Skip to content

Instantly share code, notes, and snippets.

@KyleMit
Created January 14, 2019 00:30
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 KyleMit/c491b1ad3985d654f07151ad2e23eed1 to your computer and use it in GitHub Desktop.
Save KyleMit/c491b1ad3985d654f07151ad2e23eed1 to your computer and use it in GitHub Desktop.
Custom Bash Prompt
# PS1 special characters
UserName="\u" # the username of the current user
HostShort="\h" # the hostname up to the first `.'
WorkingDirectory="\w" # the current working directory
HostFull="\H" # the hostname
JobCount="\j" # the number of jobs currently managed by the shell
DeviceName="\l" # the basename of the shell's terminal device name
NewLine="\n" # newline
Return="\r" # carriage return
ShellName="\s" # the name of the shell, the basename of $0 (the portion following the final slash)
Date="\d" # the date in "Weekday Month Date" format (e.g., "Tue May 26")
Time24Hour="\t" # the current time in 24-hour HH:MM:SS format
Time12Hour="\T" # the current time in 12-hour HH:MM:SS format
TimeAmPm="\@" # the current time in 12-hour am/pm format
WorkingDirectoryBase="\W" # the basename of the current working direc­tory
EscASCII="\e" # an ASCII escape character (033)
EscBegin="\[" # begin a sequence of non-printing characters, which could be used to embed a terminal con­trol sequence into the prompt
EscEnd="\]" # end a sequence of non-printing characters
EscNewline="\012" # new line with ASCII chars
# Colors with escapes
Reset="${EscBegin}${EscASCII}[0m${EscEnd}"
Black="${EscBegin}${EscASCII}[0;30m${EscEnd}"
Red="${EscBegin}${EscASCII}[0;31m${EscEnd}"
Green="${EscBegin}${EscASCII}[0;32m${EscEnd}"
Yellow="${EscBegin}${EscASCII}[0;33m${EscEnd}"
Blue="${EscBegin}${EscASCII}[0;34m${EscEnd}"
Purple="${EscBegin}${EscASCII}[0;35m${EscEnd}"
Cyan="${EscBegin}${EscASCII}[0;36m${EscEnd}"
White="${EscBegin}${EscASCII}[0;37m${EscEnd}"
export PS1="\
${Green}${UserName}@${HostShort} \
${Yellow}${WorkingDirectory}\
${Cyan}\$(__git_ps1) \
${Reset}${EscNewline}$ "
# set aliases
alias jq="C:/libraries/jq-win32.exe"
alias cls="clear"
# Custom Bash Command - http://tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html
# Command Line Colors - http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html
# Bash User Name - https://stackoverflow.com/questions/19306771/get-current-users-username-in-bashecho
# Bash File Extension - https://unix.stackexchange.com/questions/31760/file-extensions-for-unix-shell-scripts
# Bash Scripts - https://www.taniarascia.com/how-to-create-and-use-bash-scripts/
# Bash Prompt - https://www.gnu.org/software/bash/manual/bashref.html#Controlling-the-Prompt
# Posic - https://www.wikiwand.com/en/POSIX
# Parameter Expansion - http://wiki.bash-hackers.org/syntax/pe
# Brace Expansion - http://wiki.bash-hackers.org/syntax/expansion/brace
# Command Substitution - http://wiki.bash-hackers.org/syntax/expansion/cmdsubst
# printf vs echo - https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo
# update bash prompt - https://stackoverflow.com/questions/5379986/why-doesnt-my-bash-prompt-update
# bash prompt generator - http://bashrcgenerator.com/
# bash colors - https://www.howtogeek.com/307701/how-to-customize-and-colorize-your-bash-prompt/
# string multiple lines - https://unix.stackexchange.com/q/163898/128893
# multi-line variable - https://serverfault.com/questions/72476/clean-way-to-write-complex-multi-line-string-to-a-variable
# Print env variables - https://www.cyberciti.biz/faq/linux-list-all-environment-variables-env-command/
# print env sorted - https://www.build-business-websites.co.uk/sorted-list-of-environment-variables/ec
# newline after command substitution - https://stackoverflow.com/questions/33712750/git-config-global-returns-syntax-error-near-unexpected-token-error
# create bash file
# $ touch ~/.bashrc
# open bash file
# $ code ~/.bashrc
# force .bashrc update
# $ source ~/.bashrc
# previous PS1
# $PS1="\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$"
# Echo: \033[32m This is in green \033[0m
# PS1: \[\033[32m\]This is in green\[\033[m\]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment