Life is short, bash commands should be too
July 2021 • 1 min read
As a person that likes to maximise my output and minimise the input required, I don’t like having to type and re-type all my bash commands repeatedly during the day. Thankfully, I can create aliases on my machine that shorten them.
These are my favourite:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Git command shortcuts | |
alias gcam="git commit -am" | |
alias dcu="docker-compose up" | |
alias dcd="docker-compose down" | |
alias dcl="docker-compose logs -f" | |
alias dc="docker container" | |
alias gpo="git push origin" | |
alias gcm="git checkout master" | |
function merge_into_dev() { | |
branch=$(git symbolic-ref --short -q HEAD) | |
git checkout dev && git pull origin dev && git merge $branch | |
git push origin dev | |
} | |
function checkout_master() { | |
git checkout master | |
git pull origin master | |
} | |
function pull_master () { | |
git pull origin master | |
} | |
function get_branch() { | |
git branch | grep "*" | cut -d" " -f2 | |
} | |
# AWS commands | |
function run_ssm() { | |
REGION=$2 | |
aws ssm start-session --target $1 --region=$REGION | |
} |
I especially like the functions because I can shorten long commands that have variable input. e.g. to start an ssm session, I just have to type:
run_ssm <instance-id> <region>
My second favourite thing is being able to combine two shortened commands. e.g.
# old - git push origin chore/do-some-amazing-thing-with-code
gpo `get_branch`
How to use (OS X)
-
Open your
.bash_profile
filenano ~/.bash_profile
- Paste any of the commands in and save it
-
Update the shell session with the new content
source ~/.bash_profile
I will add more commands to the gist as the need for them comes along. Feel free to add your favourites to the gist too!
To get notifiied about new posts, please subscribe here.