My favorite bash shortcuts in 2023
I use fishshell, and its Oh my fish framework as my command line shell. Over the years, I have gathered many useful functions and shortcuts. Here are my favorites.
General shortcuts
Let’s start with some general shortcuts. The first one is the brc
shortcut which reloads the .bashrc
file and refreshes its content. That way, I can use new shortcuts if added.
alias brc="source ~/.config/fish/.bashrc"
Since I am using VS Code Insiders, whose command in the terminal is code-insiders
, which I am too lazy to write every time, I have added a ci
shortcut.
alias ci="code-insiders"
Sometimes I use The Fuck app for my terminal, but it might be inconvenient when sharing screen. So, I use a shortcut pls
to run fuck
command.
alias pls=fuck
SSH shortcuts
Recently Josie posted on Twitter how she cannot remember how to add the SSH key.
“I have been a software engineer for 7 years and I will never remember the steps to adding a SSH key to my Github profile I'm so sorry.”
It reminded me of the SSH shortcuts that I configured many years ago. So here are my SSH shortcuts.
To generate a new SSH key, I use the sshkey
shortcut with an additional argument, the SSH user filename, like so sshkey pgh_rsa
.
function sshAddKey
ssh-keygen -t rsa -C $argv
end
alias sshkey=sshAddKey
To start the SSH agent and add the SSH key, I use the sshuser
shortcut with an additional argument, the SSH user filename, like so sshuser pgh_rsa
.
function sshStart
eval ssh-agent -s
ssh-add ~/.ssh/$argv[1]
end
alias sshuser=sshStart
To delete all identities from the agent, I use the sshdel
shortcut.
alias sshdel="ssh-add -D"
To test the SSH connection to GitHub, I use the sshpingg
shortcut.
alias sshpingg="ssh -T git@github.com"
Handling terminal processes shortcuts
Since I use Gulp, 11ty, and custom Node.js scripts in my workflow, I have situations where I need to kill a process or two that are stuck or hanging.
To check if a process already occupies a port, I use the checkPort
shortcut with am additional argument, the port, like so checkPort 8080
.
function checkPort
lsof -t -i:$argv[1]
end
alias cport=checkPort
To terminate all processes that occupy a port, I use the kport
shortcut with an additional argument, the port, like so kport 8080
.
function killPort
kill -9 (lsof -t -i:$argv[1])
end
alias kport=killPort
To terminate all running Node.js processes, I use the killnode
shortcut.
alias killnode="killall -9 node"
To terminate all running Node.js processes, I use the kf
shortcut.
alias kf="killify"
kf
is just an alias for my killify NPM package.
Filesystem shortcuts
For general filesystem navigation in my terminal, I’m using z command. But for finer control, I am using the following commands.
To go up one level, I use cd..
and ..
commands.
alias cd..="cd .."
alias ..="cd .."
To see the long listing format of the current folder, I use the ll
and lll
shortcuts. To see every single file and folder within current folder, I use the llll
shortcut.
alias ll="ls -la"
alias lll="exa -abghHliS"
function exaTree
exa --long --tree $argv
end
alias llll=exaTree
To remove folders and files, I use the rr
and rrr
shortcuts. The difference is that the rr
shortcut shows prompt before removal.
alias rr="rm -rf -i"
alias rrr="rm -rf"
Use rm -rf
with extreme caution. The action cannot be reverted, and all deleted files and folders are permanently gone.
Git shortcuts
I am using a lot of Git shortcuts, but here are my favorites.
To check the git status, I use the gs
shortcut.
alias gs="git status -s"
To view the git log, I use the gl
shortcut.
alias gl="git log --oneline --graph"
To stash every new, removed, or changed file in the current repository, I use the ga.
shortcut.
alias ga.="git add ."
To commit the changes, I use the gc
shortcut with an additional argument, the message, like so gc "My message"
.
# git: commit with message
function commitWithMessage
git commit -m $argv
end
alias gc=commitWithMessage
To edit the last commit message, I use the gcam
shortcut with an additional argument, the new message, like so gcam "My new message."
.
# git: commit amend message
function commitAmend
git commit --amend -m $argv
end
alias gcam=commitAmend
Remember to add quotation marks when using the gc
and gcam
shortcuts.
To view all local and remote branches, I use the gba
shortcut.
alias gba="git branch -a"
To prune or to delete the refs to the branches that don't exist on the remote, I use the grpo
shortcut.
function pruneOrigin
git remote prune origin
gba
end
alias grpo=pruneOrigin
To fetch all remote branches, I use the gfa
shortcut.
alias gfa="git fetch --all"
To push all local branches to remote, I use the gpa
shortcut.
alias gpa="git push --all"
To undo all changes, I use the gr
shortcut.
alias gr="git reset --hard"
To checkout to my master
branch, I use the gcm
shortcut.
alias gcm="git checkout master"
To pull the master branch from the remote, I use the gpom
shortcut.
alias gpom="git pull origin master"
To create a new branch, I use the gcn
shortcut with an additional argument, the branch name, like so gcn new-branch-name
.
function checkoutNew
git checkout -b $argv
end
alias gcn=checkoutNew
git-flow shortcuts
I am using git-flow, a set of Git extensions that makes it easier to implement Vincent Driessen's branching model I have used for ages.
To initialize git-flow, I use the gfi
shortcut.
alias gfi="git flow init"
To start a feature branch, I use the gfs
shortcut with an additional argument, the branch name, like so gfs feature-name
.
function flowFeatureStart
git flow feature start $argv
end
alias gfs=flowFeatureStart
To close and merge a feature branch, I use the gff
shortcut with an additional argument, the branch name, like so gff feature-name
.
function flowFeatureFinish
git flow feature finish $argv
end
alias gff=flowFeatureFinish
I use similar shortcuts to start and finish the hotfix
and release
branches.
Conclusion
If you want to see my complete fish configuration, I have it versioned on GitHub.
You could check my setup page to learn what other software and hardware I use.