There is a common misconception that development happens best in an GUI IDE such as Intellij. Having a well setup terminal development environment can make a developers life significantly easier. In this post, I am going to be describing the steps that I take to create my terminal development environment. I do all of my development on a Mac, these directions can easily be converted to work in linux with minor adjustments.
Pre-Requisites
Homebrew
Homebrew is a free and open source package manager for Mac OSX that makes installing software simple. Installing Homebrew is always my first step when I am provisioning my Mac for development. Installing Homebrew is a single command.
/usr/bin/ruby -e "$(curl -fsSL /raw.githubusercontent.com/Homebrew/install/master/install)"
Now that Homebrew is installed, it’s important to run the following two commands to ensure that all the latest packages are installed. This may take awhile the first time.
brew update; brew upgrade
iTerm2
Unfortunately, Mac OSX default terminal leaves much to be desired. After looking at all of the alternatives, I use iTerm2. iTerm2 comes with tabbing support, sane default key mappings, as well as support for ZSH, Prezto, Vim, etc. Installing iTerm2 is a single brew command.
brew cask install iterm2
Xcode
While not required for most non-apple device development, I always install Xcode, and the Xcode command line tools. Xcode can be installed via the App Store. Once installed run the following command to enable the command line tools.
xcode-select --install
Installing Zsh
Z Shell (Zsh) is a Unix shell that is built on top of bash, with a ton of extended functionality. What I enjoy most about Zsh is that I can make my terminal significantly more useable through the use of frameworks. Installing Zsh is a single brew install command.
brew install zsh
Now that Zsh is installed, before it is useable, it has to be configured as the default shell. In iTerm2, run:
chsh -s $(which zsh)
Installing Prezto
Prezto is a configuration framework for Zsh that includes sane aliases, auto completion, template support, etc. Installing Prezto requires checking out a github repository, and copying files into the proper directory structure.
git clone --recursive /github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
Now that Prezto has been installed, a .zshrc file needs to be created. Run the following code in iTerm2.
setopt EXTENDED_GLOB;
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
While Prezto comes with a good number of sane modules, I add the following modules to my environment for extended functionality. Open ~/.zpreztorc add search for pmodule, replacing the module list with the one below.
zstyle ':prezto:load' pmodule \
'environment' \
'terminal' \
'editor' \
'history' \
'history-substring-search' \
'directory' \
'spectrum' \
'utility' \
'completion' \
'homebrew' \
'osx' \
'ruby' \
'rails' \
'git' \
'node' \
'python' \
'haskell' \
'syntax-highlighting' \
'autosuggestions' \
'tmux' \
'utility' \
'prompt'
Prezto comes with a default theme that I don’t find appealing, so I switch to the powerlevel9k theme. In the ~/.zpreztorrc file, search for theme, and replace the line with the following:
zstyle ':prezto:module:prompt' theme 'powerlevel9k'
Finally, I add some of my aliases and preferred configurations to ~/.zshrc
# Customize to your needs...
#My git aliases
alias gco='git checkout'
alias ga='git add .'
alias gcm='git commit -m'
alias gp='git push'
alias gpu='git pull'
alias gcl='git clone'
alias gstat='git status'
alias dm='docker-machine'
#My only adjustment to the powerlevel9k theme
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs)
Installing and Configuring an awesome VIM deployment
While there are many awesome text editors, I have yet to find one that is as capable as a fully configured VIM. Unfortunately, VIM by default is less then impressive. I have spent many hours optimizing my VIM deployment to be as lightweight as possible, while significantly enhancing the development process. The first step is to install VIM.
brew install macvim
The first step in configuring VIM is to install a plugin manager. I prefer Pathogen.
mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim /tpo.pe/pathogen.vim
Now we need to configure our .vimrc file to use Pathogen. I have included my .vimrc below, which includes my preferred configurations.
if &compatible
set nocompatible
endif
set guifont=Monospace\ 10
set wrap
set scrolloff=5
set number
set showmatch
set showmode
set showcmd
set ruler
set title
set wildmenu
set wildmode=longest,full
set wildignore=*.o,*.obj,*.bak,*.exe,*.py[co],*.swp,*~,*.pyc,.svn
set laststatus=2
set matchtime=5
set matchpairs+=<:>
set nolist
set listchars=tab:>-,trail:.,eol:$,extends:>,precedes:<
set tabpagemax=15
syntax enable
set encoding=utf-8
set autoread
set esckeys
set ignorecase
set smartcase
set smartindent
set smarttab
set magic
set backspace=indent,eol,start
set tabstop=2
set shiftwidth=2
set autoindent
set softtabstop=2
set expandtab
set fileformats=unix,dos
set diffopt+=iwhite
set foldmarker=#ifdef,endif
set foldmethod=marker
set autochdir
set lazyredraw
set confirm
set nobackup
set viminfo='20,\"500
set hidden
set history=1024
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
set incsearch
endif
map ,mm :set mouse=a<CR>
map ,m :set mouse=<CR>
map,, :tabp<CR>
map,. :tabn<CR>
nnoremap <silent> <C-S> <Esc>:w<CR>
inoremap <c-s> <Esc>:w<CR>i
vnoremap <c-s> <Esc>:w<CR>
execute pathogen#infect()
syntax on
filetype plugin indent on
set background=dark
colorscheme molokai
set t_Co=256
set statusline=[%n]
set statusline+=\ %<%F
set statusline+=\ \ \ [%M
set statusline+=%R
set statusline+=%H
set statusline+=%W
set statusline+=%Y]
set statusline+=[%{&ff}]
set statusline+=%{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\&bomb)?\",B\":\"\").\"]\ \"}
set statusline+=\ \ %=
set statusline+=\ line:%l/%L
set statusline+=\ col:%c
set statusline+=\ \ \ %p%%
" Setup Nerdtree
autocmd vimenter * NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
let g:nerdtree_tabs_open_on_console_startup=1
autocmd VimEnter * wincmd p
" Setup JS Support
let g:javascript_plugin_jsdoc = 1
augroup javascript_folding
au!
au FileType javascript setlocal foldmethod=syntax
augroup END
" Indent guides enabled
let g:indent_guides_enable_on_vim_startup = 1
Finally, it’s time to install plugins that greatly enhance the usability of VIM. Plugins can be found at VimAwesome. My list of plugins are as follows.
- dart-vim-plugin
- molokai
- supertab
- vim-endwise
- vim-javascript
- vim-nerdtree-tabs
- vim-rails
- youcompleteme
- delimitmate
- nerdtree
- syntastic
- vim-fugitive
- vim-json
- vim-node
- vim-ruby
- dockerfile.vim
- nerdtree-git-plugin
- vim-airline
- vim-go
- vim-jsx
- vim-polyglot
- vim-sensible