Creating Bashstrap: bootstrap for your terminal
Bashstrap is a quick way to spruce up OSX terminal. It cuts out the fluff, adds in timesaving features, and provides a solid foundation for customizing your terminal style.
Feature list
Faster directory navigation
- Open your current directory in Sublime Text (with just 2 characters)
- Jump directories rapidly, without having to set aliases—using Z (my favorite feature!)
- Tab bar displays your current directory
- Lots of quick shortcut aliases that I use for git and moving around directories
Customized bash prompt line
- Git branch status inline
- ☠ ahoy! An easily customizable symbol
- Stripped out extraneous text
Updated color scheme
- Colored ‘ls’
- Syntax highlighted ‘cat’
Install via Github (takes 10 mins)
In the rest of this post I’ll go into detail on how I configured the features. I’m not an expert at customizing terminal—if you notice anything that could be improved, please leave a comment or open a pull request.
Supports
Bash, not zsh
I don’t have a need for any of z shell’s features so I decided not to go that route. Bash is capable of a lot of those features now, like command-line completion. I looked at oh-my-zsh briefly, but there weren’t any themes to my liking.
iTerm, not Terminal
This was primarily because I had a lot of difficulty customizing the stock terminal that comes with OSX. It was way easier to edit colors and preferences in iTerm 2. There are some iTerm features that I’d expect to use in the future too.
Sublime Text, not Vim
I use Sublime Text for virtually all text editing so decided to leave out the .vimrc that customizes Vim.
File Organization
File organization based on Mathias Bynens epic dotfiles.
The installation notes on the repo cover installing to your home directory, which is where OSX looks for your dotfiles. This works perfectly, but I found that housing my dotfiles in their own folder and symlinking to them from my home directory gave a lot of advantages.
It makes it easier to backup, version and share my dotfiles by creating a Github repo for them. There’s even a landing page dedicated to dotfiles on Github.
To install to a folder:
-
Fork and clone the Bashstrap repo to a subfolder of your home directory. I keep my dotfiles in ~/Code/dotfiles.
-
Backup your current dotfiles (optional)
cp ~/.bash_profile ~/.bash_profile_old cp ~/.bashrc ~/.bashrc_old cp ~/.gitconfig ~/.gitconfig_old
-
Create symlinks to the new dotfiles
ln -s ~/.bash_profile ~/your/path/to/.bash_profile ln -s ~/.bashrc ~/your/path/to/.bashrc ln -s ~/.gitconfig ~/your/path/to/.gitconfig ln -s ~/.gitignore ~/your/path/to/.gitignore ln -s ~/.hushlogin ~/your/path/to/.hushlogin
Side note: I wish I’d realized there’s a Sublime Text syntax highlighting package for dotfiles before I started work on customizing them. It’s really helpful!
Productivity Features
Open files and directories in Sublime Text
There are multiple ways to set this up, some more complicated than others. The best I found is a this one-liner that’s included in the .bash_profile.
- alias s=’open -a “Sublime Text 2″‘
This enables you to just type “s .” to open the current directory in Sublime Text. Or “s file-name.ext” to open a file.
Z directory jumping
Possibly my favorite feature is Z (not to be confused with zsh, which is a totally different thing).
Z removes a lot of the need for cd’ing around directories. Instead you type “z” then any substring of the name of the directory you want to jump to. For example I can be in any dir and type “z dotf” to jump straight into my dotfiles dir. This means I don’t need to bother setting up aliases for frequently visited directories! It works really really well.
You need to cd around a bit after installing it so that it builds up a memory of the directories you visit. Here’s the Z repo.
Changing the bash prompt
My bash prompt is simply “[user] in [current-directory] on [current-git-branch]“, where current-git-branch will only display if I’m within a dir that has a git repo. This came straight from @gf3′s bash prompt. I really dig it, and made a few customizations.
For more bash prompt hacking, this Reddit topic contains a lot of good inspiration, and this Stack Overflow too.
Silence the “welcome, last login was at X” message
.hushlogin is awesome. Credit to Mathias.
Display the current dir name as the tab title
With multiple tabs open it’s nice to be able to see what’s going on in them. I found a nice little one-liner for this on Stack Exchange, it now lives in my .bash_profile. It displays just the name of the current directory as the tab title.
Aliases
Z is amazing and eliminates a lot of the need for aliases but there are still some spots where they’re useful. I added in “..”, “…” and “….” to skip back 1, 2 or 3 directories. I stuck in a couple of aliases to directories that I use frequently too, these can be easily customized and added to.
I use “ls” and “ls -la” a lot, so there are a number of ls aliases. Typing “l” gives you the colorized list in long format, and “la” includes dotfiles in the list. These show the directories in blue, which is nice for scannability.
If you’d like “cat” with syntax highlighting you can use the “c” alias. You’ll just need to install Pygments first.
Shortcut key binding
Binding shortcut keys to things I want (delete previous word, skip to EOL, etc) seems like a pain in the ass. Instead I opted to get used to the bash shortcuts. Here’s a list of the shortcuts I use the most.
Style Updates
I installed iTerm 2 because color tweaking in OSX terminal was a painful process and taking me hours. iTerm 2 lets you preview as you select from the color pallete, which rocks.
Font
I played around with a lot of fixed width fonts, including Adobe’s Source Code Pro, and in the end settled on Menlo that comes with OSX. I like 16pt Menlo regular. This can be changed in iTerm Preferences > Profiles > Default > Text > Regular Font (make sure you change the Non-ASCII version to be the same too).
It looks a lot better without bold too. I switched to the non-bold font by unchecking “Draw bold text in bold font” in iTerm Preferences > Profiles > Default > Text > Text Rendering.
Color scheme
The bash prompt edits in .bash_profile took care of a lot of the coloring. But there were still a few things that needed tweaking.
I wanted a lighter blue for the directory highlighting. The quickest way I found to change this was by changing the iTerm blue color. iTerm Preferences > Profiles > Default > Colors > click Blue and make it lighter.
Cursor
While you’re in the iTerm color settings you might notice cursor colors too. These are really fun to change! Bright green or pink make really nice cursor colors. Click the “Smart cursor color” checkbox, then you can edit Cursor color.
I also like having selection text as the same color as the cursor. I went for bright green, with black text.
Also, my preference is for the thin vertical bar cursor. This can be change in iTerm Preferences > Profiles > Default > Text > Cursor.
Unicode symbol
The avatar of the bash prompt! I made this really easy to change by creating a variable for it in .bash_profile. Just command+f for “symbol”. A few favorites: ⚡ ☠ ☢ ♥. Tables worth of symbols here to copy paste in.
That’s all for now!
All of these tweaks and features are included, it only takes 10 minutes to install.