Skip to content

Instantly share code, notes, and snippets.

@crowjdh
Last active January 9, 2024 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crowjdh/8874d9c132b61819e0558fd285a60661 to your computer and use it in GitHub Desktop.
Save crowjdh/8874d9c132b61819e0558fd285a60661 to your computer and use it in GitHub Desktop.

Terminal Tips & Tricks

  • Pretty prompt
    # Start colored text with:
    #   %F{red}
    # End colored text with:
    #   %F{red}
    # %n    : user name
    # %m    : computer name
    # %/    : current dir
    export PS1='%n@%m:%F{red}%/%f $ '
    
    alias ls='ls --color'
  • Aliases
    • Docker aliases
      # Docker
      export DOCKER_CONTEXT="lima"
      alias dmg="docker images"
      alias dps="docker ps --format 'table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Names}}\t{{.Ports}}' $@"
      alias dst='docker stack "$@"'
      alias dsv='docker service "$@"'
      alias dsl='docker-stack-logs "$@"'
      alias dex='docker-exec $@'
      dsh() { docker-exec -ti $@ sh; }
      dbash() { docker-exec -ti $@ bash; }
    • rmforsure
      alias rm='echo "Warning: Use \"rmforsure\""'
      alias rmforsure='/usr/bin/rm'
    • pbcopy
      alias cpwd='echo -n $PWD | pbcopy'
  • Navigation aids
    pushd()
    {
      if [ $# -eq 0 ]; then
        DIR="${HOME}"
      else
        DIR="$1"
      fi
    
      builtin pushd "${DIR}" > /dev/null
    }
    
    pushd_builtin()
    {
      builtin pushd > /dev/null
    }
    
    popd()
    {
      builtin popd > /dev/null
    }
    
    alias cd='pushd'
    alias pd='popd'
    alias td='pushd_builtin'
    
    # Shortcuts
    alias ll='ls -lah'
  • Faster nvm
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --no-use # This loads nvm
  • Terminal key bindings(jump by word, go to home/end, delete all)
    autoload -U up-line-or-beginning-search
    zle -N up-line-or-beginning-search
    autoload -U down-line-or-beginning-search
    zle -N down-line-or-beginning-search
    
    bindkey -- "^[[A" up-line-or-beginning-search
    bindkey -- "^[[B" down-line-or-beginning-search
    
    bindkey -- "^[[1;3D" backward-word
    bindkey -- "^[[1;3C" forward-word
    
    bindkey -- "^H" backward-kill-word
    • Stop at "/" character
      WORDCHARS=${WORDCHARS/\/}
      WORDCHARS="$WORDCHARS\""
      
...and even nyan cat
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄░░░░░░░░░
░░░░░░░░▄▀░░░░░░░░░░░░▄░░░░░░░▀▄░░░░░░░
░░░░░░░░█░░▄░░░░▄░░░░░░░░░░░░░░█░░░░░░░
░░░░░░░░█░░░░░░░░░░░░▄█▄▄░░▄░░░█░▄▄▄░░░
░▄▄▄▄▄░░█░░░░░░▀░░░░▀█░░▀▄░░░░░█▀▀░██░░
░██▄▀██▄█░░░▄░░░░░░░██░░░░▀▀▀▀▀░░░░██░░
░░▀██▄▀██░░░░░░░░▀░██▀░░░░░░░░░░░░░▀██░
░░░░▀████░▀░░░░▄░░░██░░░▄█░░░░▄░▄█░░██░
░░░░░░░▀█░░░░▄░░░░░██░░░░▄░░░▄░░▄░░░██░
░░░░░░░▄█▄░░░░░░░░░░░▀▄░░▀▀▀▀▀▀▀▀░░▄▀░░
░░░░░░█▀▀█████████▀▀▀▀████████████▀░░░░
░░░░░░████▀░░███▀░░░░░░▀███░░▀██▀░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment