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?

Oldest 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
 
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
 
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
 
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
 
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
 
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
 
lysofdev profile image
Esteban Hernández

alias dc="docker-compose"

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