Created
December 1, 2016 05:27
-
-
Save mpan-pl/ec4ee80336524bb241775cf3c0473ca2 to your computer and use it in GitHub Desktop.
mpan’s bash prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/env bash | |
# Copyright © 2016 mpan; <https://mpan.pl/>; CC0 1.0 | |
remote=1 | |
if [[ -z "$SSH_CONNECTION" && -z "$SSH_TTY" ]]; then | |
remote=0 | |
fi | |
root=0 | |
if [[ -n "$EUID" ]]; then | |
if [[ "$EUID" == 0 ]]; then | |
root=1 | |
fi | |
elif [[ -n "$UID" ]]; then | |
if [[ "$UID" == 0 ]]; then | |
root=1 | |
fi | |
else | |
if [[ $(whoami) == 'root' ]]; then | |
root=1 | |
fi | |
fi | |
if [[ -n "$TERM" && !$(which tput &>/dev/null) ]]; then | |
if (( remote )); then | |
tJs8DzemWhJQoAxzABKH8mKqco_preHost="$(tput sgr0)$(tput bold)$(tput setaf 2)" | |
else | |
tJs8DzemWhJQoAxzABKH8mKqco_preHost="$(tput sgr0)$(tput setaf 6)" | |
fi | |
if (( root )); then | |
tJs8DzemWhJQoAxzABKH8mKqco_preUser="$(tput sgr0)$(tput bold)$(tput setaf 1)" | |
else | |
tJs8DzemWhJQoAxzABKH8mKqco_preUser="$(tput sgr0)$(tput setaf 3)" | |
fi | |
tJs8DzemWhJQoAxzABKH8mKqco_postUser="$(tput sgr0)$(tput setaf 0)$(tput bold)@" | |
tJs8DzemWhJQoAxzABKH8mKqco_reset="$(tput sgr0)" | |
tJs8DzemWhJQoAxzABKH8mKqco_preColorResultP="$(tput setaf 2)" | |
tJs8DzemWhJQoAxzABKH8mKqco_preColorResultN="$(tput bold)$(tput setaf 1)" | |
fi | |
unset remote | |
unset root | |
function tJs8DzemWhJQoAxzABKH8mKqco_buildPrompt { | |
lastResult=$? | |
if (( lastResult )); then | |
resultStyle="$tJs8DzemWhJQoAxzABKH8mKqco_preColorResultN" | |
else | |
resultStyle="$tJs8DzemWhJQoAxzABKH8mKqco_preColorResultP" | |
fi | |
pwd="$(basename "$(pwd)")" | |
if [[ "$(readlink -f "$(pwd)/..")" != '/' ]]; then | |
pwd="$(basename "$(readlink -f "$(pwd)/..")")/$pwd" | |
fi | |
if [[ "$(readlink -f "$(pwd)/../..")" != '/' ]]; then | |
pwd="…/$pwd" | |
elif [[ "$pwd" != '/' ]]; then | |
pwd="/$pwd" | |
fi | |
PS1=$( \ | |
echo -n "$tJs8DzemWhJQoAxzABKH8mKqco_reset\n"; \ | |
echo -n "$resultStyle| $(printf '% 3d' $lastResult) "; \ | |
echo -n '| | | | \T | | | | '"$tJs8DzemWhJQoAxzABKH8mKqco_reset "; \ | |
echo -n "$tJs8DzemWhJQoAxzABKH8mKqco_preUser\u"; \ | |
echo -n "$tJs8DzemWhJQoAxzABKH8mKqco_postUser"; \ | |
echo -n "$tJs8DzemWhJQoAxzABKH8mKqco_preHost\H"; \ | |
echo -n "$tJs8DzemWhJQoAxzABKH8mKqco_reset"; \ | |
echo -n ":$pwd\n \$ ") | |
} | |
PROMPT_COMMAND='tJs8DzemWhJQoAxzABKH8mKqco_buildPrompt' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment