I spend a lot of time in Terminal.app mostly running Rails or Git commands. I am also lazy, so I like to use short macros instead of typing in the same thing over and over again. I used to use bash aliases or functions, but I mostly use TextExpander snippets now because I like to be sure they don’t conflict with internal UNIX commands.
In this post I will show you
- How to setup a TextExpander Group that only runs in the Terminal
- Some of the more common snippets I have added to this group
Lets get started.
Setup TextExpander Group for Terminal
If TextExpander is only on your menu bar, click the icon, then choose Open TextExpander. In TextExpander, create a new Group. I called mine HL Terminal Commands. In the Group Settings (see below), choose Only These Applications… and TextExpander will bring up a list of installed applications (see right). Check Terminal only. TextExpander will now only expand these snippets in Terminal.app.
Some core Snippets
Change to Project Folder
One of the first commands I always enter in Terminal is to change to a project folder’s code subfolder. It’s a lot to type
cd ~/Projects/Kifu/code/kifu every time, so I created a snippet abbreviated to
;cdki to do it.
As we all do, I spend a lot of time typing in Git commands to manage Source Control. Of course, I use git-completion.bash to speed up typing in branch names. Here are some of my snippets for git:
git merge --no-edit --no-ff(note the space at the end)
git checkout develop
git add .
git checkout -b(note the space at the end)
git push origin
One thing I like to do is log all commits to Day One – see Bread Crumbs in Day One. In this case I use a TextExpander cursor position marker to set where I type the commit message, then use it to run a bash macro.
The bash macro in
.bash_profile (OS X) is
1 2 3 4 5 6
So to commit my current branch and merge it into development I could do the following:
1 2 3 4 5 6 7
or, with TextExpander (showing typing only)
1 2 3 4 5 6
to do the same thing, 62 keystrokes instead of 191! Add that up over a day!
SSH to Server
SSH to a server takes too much typing, so I use this:
Aside: I like my remote terminals to look different, so I have set the following functions up in my bash profile:
1 2 3 4 5 6 7 8 9 10 11
Whenever I execute a ssh command, my current terminal gets a new color scheme, which gets restored on exit from the remote session (local to the left, remote to the right).
Open with Editor
Launching an editor, then opening a recent folder or file takes too much effort too. Here are my editor launcher snippets:
mate .(Opens the current folder in TextMate 2)
subl -n .(Opens the current folder in Sublime Text)
bbedit .(Opens the current folder in BBEdit)
Looking for more ideas
If you use TextExpander to speed up your use of Terminal, I’d love to hear about it. Link in the comments or DM me on Twitter @hiltmon.