do it… Take the Easy Way Out! With BASH Shortcuts
While studying for my master’s in music and recording vocals for my first E.P., I asked a classmate to be my “engineer” in the studio one day. Well, I noticed that every time he toggled between ProTools mix and edit windows, he grasped the mouse, moved it to the other window, and clicked. I said “Hey dude, you can just use ⌘/+ for that!” He snapped back: “It doesn’t matter. Doing it this way is easier for me.” I said “But...” and he said “IT’S FINE.”
I thought about how this was my scheduled studio time, and how every time he switched windows with the mouse, he willingly wasted several of my scheduled studio seconds. But I was too polite to call BS.
We certainly weren’t professional engineers — but that doesn’t mean we couldn’t value our time the same way engineers do!
Ohhhh, doing it the long way is easier, is it? Well, next time you catch yourself thinking that— stop lying to yourself! EMBRACE SHORTCUTS.
If you’re scared you’ll forget your shortcuts, make a shortcut for remembering your shortcuts!
tami@Xena:$ eek
------------------
special shortcuts:
------------------
|| cp -a . ../foo || copy everything in a dir to another dirrrr!
|| in sublime ctrl + shift + up or down || move lines!!!!!!
|| gcl blah.git && cd $ instead of git clone...
|| md NEW-DIR automatically creates and cds into new directory
|| and doesn't get upset if the dir exists already!
|| CTRL-U || clears a line
|| ls -a | grep '^\.b' || helps me find dotfiles via grep
|| man [program] | grep '^E'|| search for man entries via grep, remove ^ if necessary, etc
------------------
tami's aliases & functions:
------------------
|| pretty-eyes || makes xflux run
|| night-night || makes computer go to bed in one hour
|| gitrdun || submit quick flatiron labs
|| tamtam-prompt ||
|| flatiron-prompt ||
|| boring-tamtam-prompt ||
I love shortcuts. I’ve seen how they make music production faster — especially when I get to watch wizards do it — and at Flatiron School I love looking up the shortcuts my instructors use.
Indoctrinated yet? Read on to learn some of my favorite BASH cheats…
Making BASH Aliases
The first time I heard the word “alias” I thought it sounded like a scary alien disease. Luckily, BASH aliases are much more fun than that! A BASH alias is a shortcut for doing stuff you’re sick of typing. You saw a few of them referenced in my cheat sheet — so let me show you how/where I defined them…
My .bashrc* actually came with lots of predefined aliases, though it politely suggests I define my own aliases on my own turf:
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
WELL FINE! Looks like this .bashrc script ain’t big enough for the two of us! So here’s the part of my .bashrc file that sources my separate dotfile, .tamtam_aliases:
# GET TAMTAM'S ALIASES
# ===========================
if [ -f ~/.tamtam_aliases ]; then
. ~/.tamtam_aliases
fi
# ===========================
(Note: I could have just as easily sourced my separate config file with . ~/.tamtam_aliases instead of that if-statement — but what if I deleted it in the future? Then BASH would get mad at me once per session! You’ll see that if-statement a lot in .bashrc files.)
*If you’re a Mac user, like all my Flatiron School classmates, you might be like “I don’t have a .bashrc!!” to which I say “It’s okay, just use your .bash_profile!
Now here is .tamtam_aliases in the flesh:
#TAMTAM's Aliases
alias pretty-eyes='xflux -z 10304'
alias night-night='sudo shutdown -P 60'
alias gitrdun="git add . && git commit -am 'done' && git push"
alias roar='echo "ROOOOAARRRR!!!"'
alias Puff='echo "the Magic Dragon lived by the sea 🐉"'
# Aliases Courtesy of Flatiron School
# =====================
# LS
alias l='ls -lah'
# Git
alias gcl="git clone"
alias gst="git status"
alias gl="git pull"
alias gp="git push"
Nice! So pretty-eyes just runs xflux whenever I want a vaguely red-tinged screen, and night-night means i like to fall asleep while watching TV and need to tell my computer to put itself to bed. I use gitrdun to submit short assignments at Flatiron School, when I don’t need a detailed commit message.
All those Flatiron School aliases are scraped from a .bash_profile they made for students. Thanks for the shortcuts, guys!
Step-by-Step BASH Aliases
If you came here looking for a step-by-step guide for making an alias, here’s one:
- Back up your .bashrc or .bash_profile:
$ cp .bashrc .bashrc.backup
- Open it up:
$ sometexteditor .bashrc
- Add this to your .bashrc and save it:
alias my_alias="stuff i want to do fast!"
- For example:
alias bongos= "echo 'i like to play the bongos'"
- Restart your BASH session and try out your new alias!
Here’s an even shorter way to tack on aliases at the end of your .bashrc, .bash_profile, or .personal_aliases file***:
echo -e "alias bongos=\"echo 'i like to play the bogoesss'\"" >> .my_cool_aliases
***Just make sure you DEFINITELY use >> and not > or you’ll overwrite your file — so on that note, make sure you always back up your dotfiles, or track your changes with git. I recommend this page for learning to use ‘echo’ for useful things like the above. I don’t recommend this method unless you’re super annoying and stubborn and need to know everything about everything! But even in that case, practice on unimportant files first.
PLEASE just one more!
Let me tell you about one more awesome shortcut I can’t bear to live without, which is actually a function and not an alias (though you use them the same way). It’s called md, and I’ve defined it in my .bashrc like so:
# Tamtam’s other functions
function md () { mkdir -p "$@" && cd "$@"; }
Can you guess what md does? Here’s a hint — I found it on this cool website.
Whew, that’s a lot of shortcuts! Are you sure you’ll remember them all? If not, you can make your own little tool for memorizing them…
Make a Cheat Sheet
Remember my cheat sheet from above? It’s the easiest BASH script you can make. Here’s what it looks like conCATenated:
tami@Xena:$ cat ~/bin/eek
#!/bin/bash
echo "
------------------
special shortcuts:
------------------
|| cp -a . ../foo || copy everything in a dir to another dirrrr!
|| in sublime ctrl + shift + up or down || move lines!!!!!!
|| gcl blah.git && cd $ instead of git clone...
|| md NEW-DIR automatically creates and cds into new directory
|| and doesn't get upset if the dir exists already!
|| CTRL-U || clears a line
|| ls -a | grep '^\.b' || helps me find dotfiles via grep
|| man [program] | grep '^E'|| search for man entries via grep, remove ^ if necessary, etc
------------------
tami's aliases & functions:
------------------
|| pretty-eyes || makes xflux run
|| night-night || makes computer go to bed in one hour
|| gitrdun || submit quick flatiron labs
|| tamtam-prompt ||
|| flatiron-prompt ||
|| boring-tamtam-prompt ||
"
It’s just a long ECHO command, preceded by the shebang. Mine runs when I type one naughty word because I’ve changed its permissions* to be executable by the owner (me!), and because it’s saved in a directory in my $PATH (Click here if you’re a Mac user or here if you’re a Linux user to learn about personal bins and putting ‘em in your $PATH)**.
*Get comfortable with the CHMOD function! If you don’t want to mark a script as executable, however, you can still run it like this: $ bash cheat_sheet (or whatever naughty word you picked for yours)
**DO use a personal bin directory for these kinds of scripts, and not one higher up in the filesystem hierarchy — this will help you avoid name conflicts with important system functions.
End Note
To circle back to the beginning, I want to give my friend the benefit of the doubt. He was probably wary of that shortcut because memorization is hard. I re-understand that every time I have to work at a restaurant! But don’t we memorize new things all the time?
Even while watching TV, we memorize new characters, situations, jargon, governmental structures on planets that don’t exist — and we enjoy it! It’s fun to know those things! If we had that same attitude with programming, music production, and other stuff, we’d spend less time clicking around, and more time seeing the big picture.