Skip to content

Instantly share code, notes, and snippets.

@zanbaldwin
Last active October 28, 2015 09:29
Show Gist options
  • Save zanbaldwin/e3a0c1411e36bfd5a410 to your computer and use it in GitHub Desktop.
Save zanbaldwin/e3a0c1411e36bfd5a410 to your computer and use it in GitHub Desktop.
Useful variables and functions to use in your PS1 terminal prompt string.
# Common Aliases
alias c='clear'
alias ..='cd ..'
alias cd..='cd ..'
# Self-referencing
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -lAh --color=auto'
alias ls='ls --color=auto'
alias mkdir='mkdir -pv'
alias nano="nano -AESm --tabsize=4"
alias rm='rm -I --preserve-root'
alias vssh='vagrant ssh'
alias vsync='vagrant rsync'
alias wget='wget -c'
# Shortcuts
alias fuck='sudo "$BASH" -c "$(history -p !!)"'
alias fucking='sudo'
alias update='sudo apt-get update'
alias upgrade='sudo apt-get upgrade'
alias dist-upgrade='sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y'
alias install='sudo apt-get install'
# Inputs.
SHELL_NAME="\\v"
TERMINAL="\\l"
EXIT_CODE="\$?"
USERNAME="\\u"
WORKING_DIRECTORY="\\w"
DIRECTORY_BASENAME="\\W"
NEWLINE="\\n"
HOSTNAME_FULL="\\H"
HOSTNAME_SHORT="\\h"
PERMISSION_INDICATOR="\\$"
# Formatting.
TEXT_BOLD="\[$(tput bold)\]"
TEXT_NORMAL="\[$(tput sgr0)\]"
# Colours.
EARTH="\[\033[38;5;58m\]"
RED="\[\033[38;5;160m\]"
DARK_GREY="\[\033[38;5;237m\]"
GREEN="\[\033[38;5;34m\]"
LIGHT_GREY="\[\033[38;5;249m\]"
CYAN="\[\033[38;5;39m\]"
WHITE="\[\033[38;5;15m\]"
# Git Branch Detector
function parse_git_branch () {
# Make sure that "color.ui" in "~/.gitconfig" is NEVER set to "always". Bad things (colour overflow) happen.
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="$RED{$TEXT_BOLD$EXIT_CODE$TEXT_NORMAL$RED}$DARK_GREY: $GREEN$USERNAME$WHITE@$TEXT_BOLD$GREEN$HOSTNAME_FULL$WHITE$TEXT_NORMAL: $LIGHT_GREY$WORKING_DIRECTORY$EARTH\$(parse_git_branch)$WHITE$PERMISSION_INDICATOR\n$CYAN$TEXT_BOLD>$WHITE $TEXT_NORMAL\[$(tput sgr0)\]"
@zanbaldwin
Copy link
Author

Place this inside your ~/.bashrc file, then either reopen the terminal or reload with . ~/.bashrc to see the updated terminal prompt.
Always make sure the PS1 string ends with $WHITE$TEXT_NORMAL so the text you type into terminal is normal white text (colours and formatting will overflow from the prompt string).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment