DEV Community

Silvestar Bistrović
Silvestar Bistrović

Posted on • Edited on • Originally published at silvestar.codes

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"
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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."

— Josie on Twitter

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 $argvendalias sshkey=sshAddKey
Enter fullscreen mode Exit fullscreen mode

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]endalias sshuser=sshStart
Enter fullscreen mode Exit fullscreen mode

To delete all identities from the agent, I use the sshdel shortcut.

alias sshdel="ssh-add -D"
Enter fullscreen mode Exit fullscreen mode

To test the SSH connection to GitHub, I use the sshpingg shortcut.

alias sshpingg="ssh -T git@github.com"
Enter fullscreen mode Exit fullscreen mode

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]endalias cport=checkPort
Enter fullscreen mode Exit fullscreen mode

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])endalias kport=killPort
Enter fullscreen mode Exit fullscreen mode

To terminate all running Node.js processes, I use the killnode shortcut.

alias killnode="killall -9 node"
Enter fullscreen mode Exit fullscreen mode

To terminate all running Node.js processes, I use the kf shortcut.

alias kf="killify"
Enter fullscreen mode Exit fullscreen mode

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 .."
Enter fullscreen mode Exit fullscreen mode

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 $argvendalias llll=exaTree
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

To view the git log, I use the gl shortcut.

alias gl="git log --oneline --graph"
Enter fullscreen mode Exit fullscreen mode

To stash every new, removed, or changed file in the current repository, I use the ga. shortcut.

alias ga.="git add ."
Enter fullscreen mode Exit fullscreen mode

To commit the changes, I use the gc shortcut with an additional argument, the message, like so gc "My message".

# git: commit with messagefunction commitWithMessage  git commit -m $argvendalias gc=commitWithMessage
Enter fullscreen mode Exit fullscreen mode

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 messagefunction commitAmend  git commit --amend -m $argvendalias gcam=commitAmend
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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  gbaendalias grpo=pruneOrigin
Enter fullscreen mode Exit fullscreen mode

To fetch all remote branches, I use the gfa shortcut.

alias gfa="git fetch --all"
Enter fullscreen mode Exit fullscreen mode

To push all local branches to remote, I use the gpa shortcut.

alias gpa="git push --all"
Enter fullscreen mode Exit fullscreen mode

To undo all changes, I use the gr shortcut.

alias gr="git reset --hard"
Enter fullscreen mode Exit fullscreen mode

To checkout to my master branch, I use the gcm shortcut.

alias gcm="git checkout master"
Enter fullscreen mode Exit fullscreen mode

To pull the master branch from the remote, I use the gpom shortcut.

alias gpom="git pull origin master"
Enter fullscreen mode Exit fullscreen mode

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 $argvendalias gcn=checkoutNew
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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 $argvendalias gfs=flowFeatureStart
Enter fullscreen mode Exit fullscreen mode

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 $argvendalias gff=flowFeatureFinish
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (3)

Collapse
 
joelbonetr profile image
JoelBonetR 🥇 • Edited

wondering
The Fuck seems so natural to use... 😂😂

Collapse
 
starbist profile image
Silvestar Bistrović

Say pls. 🙃

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

my brain pls fck 😵‍💫