Skip to content

Instantly share code, notes, and snippets.

@rsp
Last active July 26, 2018 16:41
Show Gist options
  • Save rsp/fd71cad1ba91fc1777ef0b12bb36c9dc to your computer and use it in GitHub Desktop.
Save rsp/fd71cad1ba91fc1777ef0b12bb36c9dc to your computer and use it in GitHub Desktop.
A nice shell prompt by @rsp
# A nice shell prompt by Rafał Pocztarski
# With error code display and commands to switch between styles
# From https://gist.github.com/rsp/fd71cad1ba91fc1777ef0b12bb36c9dc
TR="\[$(tput sgr0)\]"
Tr="\[$(tput setaf 1)\]"
Tb="\[$(tput bold)\]"
__err() {
e=$?
[ "$e" -ne 0 ] && echo -n "$e!"
}
p1() { # long version (user, host, full path) without git completion:
export PS1="\n$TR$Tr\$(__err)$TR$Tb\\u@\\h:\\w\$$TR "
}
p1g() { # long version to use for git completion:
export PS1="\n$TR$Tr\$(__err)$TR$Tb\\u@\\h:\\w\$(__git_ps1)\$$TR "
}
p2() { # short version (user, host, short path) without git completion:
export PS1="\n$TR$Tr\$(__err)$TR$Tb\\u@\\h:\\W\$$TR "
}
p2g() { # short version (user, host, short path) to use for git completion:
export PS1="\n$TR$Tr\$(__err)$TR$Tb\\u@\\h:\\W\$(__git_ps1)\$$TR "
}
p3() { # shorter version (host, short path) without git completion:
export PS1="\n$TR$Tr\$(__err)$TR$Tb\\h:\\W\$$TR "
}
p3g() { # shorter version (host, short path) to use for git completion:
export PS1="\n$TR$Tr\$(__err)$TR$Tb\\h:\\W\$(__git_ps1)\$$TR "
}
p4() { # even shorter version (host, no path) without git completion:
export PS1="\n$TR$Tr\$(__err)$TR$Tb\\h\$$TR "
}
p4g() { # even shorter version (host, no path) to use for git completion:
export PS1="\n$TR$Tr\$(__err)$TR$Tb\\h\$(__git_ps1)\$$TR "
}
p5() { # shortest version (no host, no path) without git completion:
export PS1="\n$TR$Tr\$(__err)$TR$Tb\$$TR "
}
p5g() { # shortest version (no host, no path) to use for git completion:
export PS1="\n$TR$Tr\$(__err)$TR$Tb\$(__git_ps1)\$$TR "
}
p1 # default prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment