mattshomepage

MacBook Pro Setup

This article describes my setup on a MacBook Pro :)

Browser

I use Google Chrome mostly because I love all of the Chrome extensions available (and the developers tools). An extension I highly recommend is Vimium:

https://chrome.google.com/webstore/detail/vimium/dbepggeogbaibhgnhhndojpepiihcmeb?hl=en

You can navigate web pages using VIM commands. One neat feature is typing the letter "f". Every autodetected anchor on the page gets a shortcut key such as "a" or "ae". Type that letter and it selects the link. No need for a mouse!

Brew

The missing package manager for Apple! Brew is just like "yum" or "apt-get" on linux distributions. On principle, I try to install everthing via brew. It makes managing installs easy. Brew provides commands that allow you to list all installed pacakges ($ brew list). It easily allows you to install and uninstall packages. Brew keeps installed package files in one spot at:

/usr/local/Cellar/

Brew then creates symbolic links to your installed applications at /usr/local/bin. Note that if you run $echo $PATH, that /usr/local/bin is searched in your $PATH environmental variable by default.

Install Homebrew

To install homebrew, all you have to do is run:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Here, we are instructing ruby (by use of -e argument) to interpet a block of text from stdout. The $() is an example of command substitution. It runs the command and delivers output via stdout. The curl arguments used here are:

  • -f : If there’s a failure on the server, it might return a HML document. This flag prevents that as best as possible, so we don’t feed the ruby interpreter this failed response!

  • -s: (silent). Prevents curl from showing progress at terminal

  • -S: When used with -s, makes curl show an error message if it appears

  • -L: If server declares resource has moved, curl will automatically retry at this new location.

Z Shell

I prefer to use z shell over bash. Mostly because of oh-my-zsh (https://github.com/robbyrussell/oh-my-zsh). oh-my-zsh provides many, many plugins that enhance your shell experience! By default on terminal.app, if you run:

$ echo $SHELL

You'll notice the default shell is typically /bin/bash. You can view the list of available shells by

cat /etc/shells

Note that if you run $ which zsh I get a version of 5.3 (and there is a newer version available). So instead, what I do, is I leverge brew to install the latest version:

$ brew install zsh

OK. So now I want my terminal.app to use this shell by default instead of its z shell. The link (https://rick.cogley.info/post/use-homebrew-zsh-instead-of-the-osx-default/) helped me to discover the dscl utility in Mac. This is the “Directory Service command line utility”.

We can leverage this utility to see our default shell:

$ dscl . -read /Users/$USER UserShell

To change our shell to use homebrew installed version of z shell, run:

$ sudo dscl . -create/Users/$USER UserShell /usr/local/bin/zsh

Oh-my-zsh setup

OK. Now, we can install the oh-my-zsh package manager:

$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

It does a few things. (1) It changes the default shell to z-shell

  • It changes default shell to z-shell
  • It permanently changes default shell to z-shell

It also creates a directory in your home directory: .oh-my-zsh

This is where all of the plugins are installed (~/.oh-my-zsh/plugins). It also creates the following files in your home directory:

.zsh-update .zsh_history .zshrc .zcompdump*

.zshrc is an important file. In particular, there’s an entry for:

plugins=( git )

in there. You can update this with plugins you wish to use. By default, a plugin for git is already there. This instructs z shell to how which branch I’m on within a directory managed by git.

Z Shell Plugins

z plugin

One fundamental plugin, is z (https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/z) It should already be available on your computer (/Users/mjohnson/.oh-my-zsh/plugins/z). To activate it, extend the plugins list in ~/.zshrc:

plugins=( git z )

And run:

$ source ~/.zshrc

Now, try z Desk in terminal and it will magically learn to change to your Desktop directory after it learns a bit.

autosuggestion plugin

This plugin makes nice auto suggestions for you when typing at the terminal. If you like what it suggests, use right arrow key to have it complete for you. Install plugin via:

$ git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

Now, as usual, update your .zshrc file to add this plugin to your list (zsh-autosuggestions). Also,
I added the following line after the line source $ZSH/oh-my-zsh.sh in my .zshrc file.

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=237'

This allows to me to pick the font color used by the auto suggestor. I used https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg to pick the color that corresponds to 257.

VIM

I use VIM for writing code and what I love about VIM, is my daily practice in it makes it easy to edit files on a remote server with no GUI. VIM has tons of plugins as well.

Basic VIM Setup

In my ~/.vimrc file, I have the following lines set:

syntax on filetype plugin on set number relativenumber set tabstop=4 set shiftwidth=4

The syntax on let's VIM highlight keywords for me (such as "if" in python). The filetype plugin on is necessary for when some of the vim plugins act on specific file types (such as python files--an example being Flake8, which I will go over shortly). The set number relativenumber makes VIM use relative numbering for me. Thus, I can see relative to the line I'm on, that 10 lines above me, is some line of code. I can then type "5 k" and move 5 lines up to the specific line of code I want to navigate to. The set tabstop=4 makes my tabs convert to 4 spaces. And, suppose I'm doing a group indentation in VIM by 4 >>. The line set shiftwidth=4 ensures that this also uses 4 spaces for a tab.

Pathogen Setup

Tim Pope invented an easier way to manage VIM plugins via Pathogen. And that’s what we’ll use here. A plugin is contained at ~/.vim/bundle/[name-of-plug-in]. Otherwise, VIM tends to spread these files out in different directories (~/.vim/plugin, ~/.vim/syntax, ~/.vim/doc, etc.). In general, if you want to know about customizing VIM, see http://learnvimscriptthehardway.stevelosh.com/.

Let's get Pathogen installed and then I'll go over a few plugins I use.

Run the following line below:

mkdir -p ~/.vim/autoload ~/.vim/bundle && \ curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

Next, add the following to at the top of your ~/.vimrc file:

execute pathogen#infect()

That should be it. Now, let's add some plugins via pathogen:

VIM Plugins

https://vimawesome.com/ is a site that lists so many of VIMs wonderful plugins. The first one we'll add is NerdTree.

NerdTree

Nerdtree gives you a little window to navigate a directory structure. I find it helpful in getting a big picture view of how a code project is laid out. To add it, run:

git clone https://github.com/scrooloose/nerdtree.git ~/.vim/bundle/nerdtree

Next, to have it automatically start up, add the following line to your ~/.vimrc file:

autocmd vimenter * NERDTree

Now, just run vim in any directory and you should get a navigation pane in a split window view.

Solarized

The solarized plugin is nice. It creates some beautiful colors which helps when coding all day. Install via:

git clone git://github.com/altercation/vim-colors-solarized.git ~/.vim/bundle/vim-colors-solarized

Next, add these lines to ~/.vimrc file:

set background=dark colorscheme solarized

Now, under terminal.app, colors will look funky unless you adopt this terminal theme:

https://raw.githubusercontent.com/tomislav/osx-terminal.app-colors-solarized/master/Solarized%20Dark.terminal

If you don't adopt this new theme, we have to instruct Solarized to adopt a pallet within the 256 allowed colors in terminal. To do this, there should be one more line in your ~/.vimrc file:

let g:solarized_termcolors=256 set background=dark colorscheme solarized

The line let g:solarized_termcolors=256 provides the instruction to only use colors within the 256 allowed colors in terminal.

ctrlp

This is awesome on quickly finding files in vim. Just type "control + p" and you can perform fuzzy finding on files. ctrlp.vim

git clone https://github.com/kien/ctrlp.vim.git ~/.vim/bundle/ctrlp.vim

Flake 8

This combines PyFlakes (which is a Python static analysis tool) and pep8 checker (let's you know if your Python code is within PEP8 guidelines).

git clone https://github.com/nvie/vim-flake8.git ~/.vim/bundle/vim-flake8

PyFlakes is a static analysis tool that lets you catch static programming errors when you write them, not when you run into them at runtime. And pep8 is a Python style checking tool that enforces PEP8 guidelines on your code. Note, for this plugin to work, this is why we need the filetype plugin on line we set earlier.

You'll also need to execute python -m pip install flake8 to have the flake8 library on your local computer (which Flake 8 plugin needs).

Set the following line in ~/.vimrc to have it run everytime you save Python file:

autocmd BufWritePost *.py call Flake8()

Articles Mac

Comments