What are your CLI go to commands and aliases?
Peter Tasker

Peter Tasker @ptasker

About: Programmer in Ottawa Canada.

Location:
Ottawa
Joined:
Apr 3, 2017

What are your CLI go to commands and aliases?

Publish Date: Dec 14 '18
38 24

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?

Comments 24 total

  • 𒎏Wii 🏳️‍⚧️
    𒎏Wii 🏳️‍⚧️Dec 14, 2018

    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 ;)

    • Thomas Landin
      Thomas LandinDec 15, 2018

      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.

  • Lucas Bersier
    Lucas BersierDec 14, 2018

    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

  • Abhinav Kumar
    Abhinav KumarDec 14, 2018

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

    • Forest Hoffman
      Forest HoffmanDec 14, 2018

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

      • Ben Russert
        Ben RussertDec 17, 2018

        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.

        • Forest Hoffman
          Forest HoffmanDec 18, 2018

          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.

  • John Alcher
    John AlcherDec 14, 2018
    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.

  • Omri Gabay
    Omri GabayDec 14, 2018

    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"
    
  • Forest Hoffman
    Forest HoffmanDec 14, 2018

    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
    
  • Heiker
    HeikerDec 15, 2018
    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.

    • Christopher Kruse
      Christopher KruseDec 17, 2018

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

  • Esteban Hernández
    Esteban HernándezDec 15, 2018

    alias dc="docker-compose"

  • Vignesh D
    Vignesh DDec 15, 2018

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

    alias ypx='yarn run'

    • Christopher Kruse
      Christopher KruseDec 17, 2018

      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!

  • Thomas Landin
    Thomas LandinDec 15, 2018

    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.

  • Jean Michel Functional Programming
    Jean Michel Functional ProgrammingDec 15, 2018
    alias d='docker'
    alias ap='ansible-playbook'
    alias g='git'
    
  • ComputerSmiths
    ComputerSmithsDec 15, 2018

    I use ‘lan’
    ifconfig | grep ‘inet ‘
    To get my ip address
    ip a | grep ‘inet ‘
    On latest debian releases

  • Ondrej
    OndrejDec 15, 2018

    function rm --description 'alias rm rm -rf'
    command rm -rf $argv;
    end

    Wouldn't recommend it to anyone though.

  • Florian Reuschel
    Florian ReuschelDec 15, 2018

    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:]]*//' }
    
    
  • Molly Struve (she/her)
    Molly Struve (she/her)Dec 16, 2018

    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"
    
  • Ken Bellows
    Ken BellowsDec 17, 2018

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

  • Ian Kirker
    Ian KirkerDec 17, 2018

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

    function vp () {
       vim "$(which "$1")"
    }
    
  • Can Nuhlar
    Can NuhlarDec 18, 2018
    #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'
    
    
Add comment