DEV Community

Peter Tasker
Peter Tasker

Posted on

What are your CLI go to commands and aliases?

I realized that I have a bunch of CLI go to commands and aliases that speed up my productivity and was wondering what others use.

A few of my favs:

  • history | grep 'something' - for finding a command I ran in the past
  • zz - opens up ~/.zshrc for editing
  • wpd - uses my local PHP version to run WP CLI so I can use XDEBUG on the CLI

What are your aliases and CLI goto productivity commands?

Top comments (24)

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited

For a more compact git history:

git config --global alias.adog log --all --decorate --oneline --graph

git adog

To easily pipe into and out of my clipboard on the terminal:

alias setclip='xclip -selection c'
alias getclip='xclip -selection clipboard -o'

getclip | gpg --sign --armor | setclip

I actually use this a lot to pipe, for example, GPG output directly into the clipboard and then paste it into some GUI application.

pstree -s $$ to show me the path from PID 1 to my current shell. This is really useful when you often start shells from within shells to manage context.

I also have aliases like

alias server='ssh server -t ''tmux a -t home \|\| tmux new-session -s home'''

This way I only have to type server and I get a persistent serssion that lasts until server restart, that I can detatch from easily with Ctrl+D and reattach by just calling server again.

Other than that, I have more than 1k lines in my .vimrc, so I will just leave a link to that instead of telling you about everything it does ;)

Collapse
 
kungtotte profile image
Thomas Landin

I use tmux new-session -A -s session-name. It will create the session if it doesn't exist and reattach if it does exist.

Collapse
 
abhinav profile image
Abhinav Kumar

Instead of history | grep 'something', you can just use Ctrl+R to search your history. I use zsh + prezto which adds sub-string search.

Collapse
 
foresthoffman profile image
Forest Hoffman

+1. Also, when you've narrowed the search, you can continue hitting Ctrl+R to navigate backward in time, through all the commands that match.

Collapse
 
benrussert profile image
Ben Russert

I'm sold if you can tell me a way to get back to exactly where I was when I started after I find what I need.

Thread Thread
 
foresthoffman profile image
Forest Hoffman

IIRC, you can press tab and that will dump your cursor at the end of the line, once you've found the command you want.

Collapse
 
vonheikemen profile image
Heiker • Edited
alias npr='pnpm run'

alias vi-s='nvim -S Session.vim'

alias pomd='tmux new-session -A -D -s pomodoro'
alias pmd-start='pomd gone -e "$HOME/pmd-timer.sh"'

alias dcc-up='docker-compose up -d'
alias dcc-down='docker-compose down'

npr: Run Node scripts in package.json
vi-s: As in Vim session to resume my work on a project using neovim.
pomd: Starts a tmux session named pomodoro or creates one if it doesn't. I used it to track the time on my working session.
pmd-start: Is what start the working session using this handy tool.
dcc-up: Starts docker compose in detach mode.
dcc-down: Stops docker compose.

Another handy tool for searching that I recommend is fzf.

ripgrep + fzf + Ctrl-R to search is the bee's knees.

Collapse
 
ballpointcarrot profile image
Christopher Kruse • Edited

Awesome find with gone. I'm gonna have to add that to my arsenal (no more browser tab pomodoro!)

Collapse
 
kenbellows profile image
Ken Bellows • Edited

Some of my .bashrc aliases:

# easily grep through ps output
alias psgrep="ps aux | grep -v grep | grep"

# git shorthands
alias ga="git add"
alias gA="git add -A"
alias gc="git commit -m"
alias gca="git commit -am"
alias gs="git status"
alias gd="git diff"
alias glog='git log --pretty=format:"%C(yellow)%h %C(cyan)%<(24)%ad %Cgreen%an%C(auto)%d%Creset: %s" --date=local'
alias gl="glog -10"

# ls shorthands
alias ls="ls --color=auto"
alias l="ls"
alias ll="ls -l"
alias la="ls -a"
alias lA="ls -A"
alias lla="ls -la"
alias llA="ls -lA"

The git shorthands above are actually kind of a lie; I actually have a (probably unnecessarily) complicated couple of bash functions, supported by a python script that parses git status output and assigns a number to each changed file, to allow easier shorthands. gs shows git status with the numbers inline before each file, then ga and gd will accept those numbers as arguments, so I can do ga 3 to stage the 3rd modified file for commit or gd 3 to show the diff for that file. Maybe I'll write a post about those functions at some point so someone can show me how to improve them...

Collapse
 
cannuhlar profile image
Can Nuhlar
#shows line numbers in nano
alias nano='nano --const --linenumbers'

#pump up brightness for cs:go :P
gamma(){
xrandr --output HDMI-1-1 --gamma "$1":"$1":"$1"
}

#very useful for hex, binary to decimal conversions
py(){
python -c "print $1"
}

#for looping isos
mountiso(){
sudo mount -o loop "$1" /mnt/iso
}

#got this extract function somewhere but can't remember where, it comes very handy
function extract() {
     if [ -f "$1" ] ; then
         case "$1" in
             *.tar.bz2)   tar xvjf "$1"                    ;;
             *.tar.gz)    tar xvzf "$1"                    ;;
             *.bz2)       bunzip2 "$1"                     ;;
             *.rar)       unrar x "$1"                     ;;
             *.gz)        gunzip "$1"                      ;;
             *.tar)       tar xvf "$1"                     ;;
             *.tbz2)      tar xvjf "$1"                    ;;
             *.tgz)       tar xvzf "$1"                    ;;
             *.zip)       unzip "$1"                       ;;
             *.ZIP)       unzip "$1"                       ;;
             *.pax)       cat "$1" | pax -r                ;;
             *.pax.Z)     uncompress "$1" —stdout | pax -r ;;
             *.Z)         uncompress "$1"                  ;;
             *.7z)        7z x -mmt8 "$1"                        ;;
             *)           echo "don't know how to extract '$1'..." ;;
         esac
     else
         echo "extract: error: $1 is not valid"
     fi
}

#my favorite
alias upt='sudo apt update && sudo apt upgrade && sudo apt dist-upgrade && sudo apt autoremove && sudo apt clean'

Collapse
 
alchermd profile image
John Alcher
alias pt="vendor/bin/phpunit"
alias dt="php artisan dusk --env=dusk.local"
alias test="pt && dt"

Which roughly translates to pt = Integration + Unit Tests, dt = tests that uses a real browser (IDK the correct term for this) and test = run the whole suite.

Collapse
 
omrisama profile image
Omri Gabay

I use i3wm and fish-shell, so I aliased:

alias fconfig="code ~/.config/fish/"
alias i3config="code ~/.config/i3/"

So that VSCode opens up immediately to edit those files whenever I need.

I also really like the Git-bare approach to syncing Config-files, so I have

alias config="/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME"
Collapse
 
loilo profile image
Florian Reuschel

I'm using macOS, not sure if things work in other UNIX environments (esp. pbcopy/pbpaste are macOS-specific), and some commands require external tools like Node.js or PHP to be installed.

# The prime one, can't live without it:
# Create a directory and cd to it immediately
mcd () { mkdir -p "$1" && cd "$1" }

# Copy the absolute path of the current working directory to the clipboard
# without trailing newline (e.g. to paste into quotes of a string)
here () { pwd | tr -d '\n' | pbcopy }

# Show all git tags of the current repository that represent
# valid SemVer versions
semver () { npx semver $(git tag) }

# lazygit is a great tool for quick git commits, check it out:
# https://github.com/jesseduffield/lazygit
alias lg="lazygit"

# Recursively search the current directory for PHP files
# and lint them for syntax errors
php-lint () { find . -iname "*.php" -exec php -l {} \; | grep -i "Errors.parsing" }

# Get the gzipped size (in bytes) of text in the clipboard
# (useful when writing JavaScript libraries)
gzipped () { pbpaste | gzip -c | wc -c  | sed -e 's/^[[:space:]]*//' }

Collapse
 
molly profile image
Molly Struve (she/her) • Edited

At the beginning of the year I broke my arm and was forced to type one handed for 3 weeks. It was ROUGH but because of it I now have a list of super simple 2 letter aliases which I still use :D

 alias rs="git reset --soft HEAD^"
 alias pp="git pull origin master"
 alias mm="git checkout master"
 alias ss="git status"
 alias aa="git add ."
 alias gc="git checkout ."
 alias gcb="git checkout -b"
 alias gp="git push origin HEAD"
 alias gf="git fetch origin"
 alias gr="git rebase origin/master"
Collapse
 
foresthoffman profile image
Forest Hoffman

Useful git history (I absolutely ❤️ this one):

git config --global alias.lg log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'--all
git lg

Clean up stray docker containers/images (it's a personal script not an alias):

docker-purge
Collapse
 
kungtotte profile image
Thomas Landin

I don't use many aliases, but I have replaced ls with exa. It's got saner defaults and great options for neat behaviour like grouping directories first, changing sorting mode, and respecting .gitignore and showing git status in long-form mode.

Collapse
 
vignesh0025 profile image
Vignesh D

alias c=clear
alias b=cd..
alias zshrc='vim. zshrc && source ~/. zshrc'

alias ypx='yarn run'

Collapse
 
ballpointcarrot profile image
Christopher Kruse

FYI, you can use Ctrl+L in most shells to handle screen clearing, and would allow you to free up 'c' for another action. Also doesn't require an enter key press!

Collapse
 
berslucas profile image
Lucas Bersier

I'm not the biggest fan of aliases because if you move to a different workspace you're going to have to use the original command and you might forget it

Collapse
 
ikirker profile image
Ian Kirker

I write a fair amount of script-y tooling, so this one saves me a lot of keystrokes:

function vp () {
   vim "$(which "$1")"
}
Collapse
 
lysofdev profile image
Esteban Hernández

alias dc="docker-compose"