.gitconfig colors

Aw yeah, another command-line coloring post!

John Schulz pointed me to this git cheat sheat (via Rebecca Murphey). Right up front it provides the settings in ~/.gitconfig to color git command output like git diff, git status, and git branch. Here’s what I’m rocking:

[core]
  quotepath = false
  whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol
[color]
  ui = true
[color "branch"]
  current = yellow black
  local = yellow
  remote = magenta
[color "diff"]
  meta = yellow bold
  frag = magenta bold
  old = red reverse
  new = green reverse
  whitespace = white reverse
[color "status"]
  added = yellow
  changed = green
  untracked = cyan reverse
  branch = magenta

Which looks like:

color git commands

Coloring remote command line prompts

Picking up on a running theme on the dropshado.ws, I gots to have my command line prompts looking fresh. Locally, I’m now using bash-it, with its killer theming engine by John Schulz to make it happen.

Just recently I realized that I can style my prompt on my remote server when I SSH. Here’s what I added to ~/.bash_profile.

PS1="\[\e[0;32m\]\u@\h \[\e[0;34m\]\w \[\e[0;30m\]# \[\e[39m\]"

Which looks like

username@server ~/path/to/dir # writing sweet commands

Strings in terminal

I’ve finally clued in to setting and using simple strings within Terminal. Set a string:

name='David DeSandro'

No spaces around the =. Quotes are required if your string has spaces. Reference it with $

echo $name
# will output `David DeSandro`

For example, when creating a new post, I have to reference the same long filename several times.

dropfile='_posts/2011/2011-04-12-terminal-strings.mdown'
mate $dropfile
git add $dropfile
tumblr $dropfile

SFTP from Terminal

I haven’t figured out a sweet use-case for this, but hey, it’s there.

sftp user@mydomain.com
# then enter password...

# upload
put remote-path [local-path]

# download
get remote-path [local-path]

# get help
help

Open current folder in Terminal with application

TextMate Manual:

Mac OS X comes with an open shell command which can be used to simulate a double click from within Terminal. It can also perform an Open With… operation by use of the -a argument, e.g.: open -a TextMate . will open the current folder in TextMate (as a scratch project).

Found this when I was looking for way to open the current folder in Terminal with GitX.

open -a GitX .

mate ~/.profile

Speaking of Terminal, the second quickest way to add Terminal aliases to ~/.profile is

mate ~/.profile

Which will open it up in TextMate. The quickest route would be using the nano text editor

nano ~/.profile

But then you got a text editor in your Terminal, which prompts Xhibit to show up

Yo dawg, I herd you like black windows, so I put a text editor in your Terminal so you can develop while you develop.

Terminal alias for hiding/showing hidden files

I’ve previously been using Houdini for toggling hidden file visibility. But now that I have the Terminal perpetually open, might as well make an alias for it.

alias showhidden="defaults write com.apple.finder AppleShowAllFiles TRUE; killall Finder"
alias hidehidden="defaults write com.apple.finder AppleShowAllFiles FALSE; killall Finder"

Coloring the Terminal prompt

Along with being the file to store your Terminal aliases, ~/.profile also allows you to color the Terminal prompt. This article has the particulars: BASH Shell change the color of my shell prompt under Linux or UNIX

First take a look at the current prompt with echo $PS1. It should return with \h:\W \u\$. The articles above detail what those variables represent, and it translates to host:directory username$. Color syntax starts with [\e[0;31m\] and ends with \[\e[m\]. The color code itself is 0:31, where 31 is the color (in this case red) and 0 being the equivalent of font-weight (bold is 1).

I am currently rocking:

export PS1="\[\e[0;31m\]\h:\[\e[m\]\[\e[0;34m\]\W\[\e[m\] \[\e[0;30m\]\u\[\e[m\]\[\e[0;33m\]\$\[\e[m\] "

Which is the same host:directory username$ but now red:blue darkgray and a beige $.

Colored BASH Terminal

UPDATE 16 Nov 2010 Revised opening and closing tags to \[\e[0;31m\] and \[\e[m\]. Previous version didn’t close tags properly and messed up line breaks. Removed link to erroneous article.