Skip to content

Instantly share code, notes, and snippets.

@apokalyptik
Last active March 16, 2022 14:45
Show Gist options
  • Save apokalyptik/4ba6288f6454c0a8f548f0bed8426e2c to your computer and use it in GitHub Desktop.
Save apokalyptik/4ba6288f6454c0a8f548f0bed8426e2c to your computer and use it in GitHub Desktop.
fun, crazy, little bash prompt
#!/bin/bash
function my_custom_prompt {
ECODE=$?
local HAPPYF=( "('◡')" '(•‿•)' '(˘‿˘)' '(^‿^)' )
local SADF=( '(⊙‸⊙)' '(⊙_☉)' '(o_O)' )
local BLACK="\[\033[0;30m\]"
local LBLACK="\[\033[0;90m\]"
local GRAY="$LBLACK"
local RED="\[\033[0;31m\]"
local LRED="\[\033[0;91m\]"
local GREEN="\[\033[0;32m\]"
local LGREEN="\[\033[0;92m\]"
local BROWN="\[\033[0;33m\]"
local LBROWN="\[\033[0;93m\]"
local YELLOW="$BROWN"
local LYELLOW="$LBROWN"
local BLUE="\[\033[0;34m\]"
local LBLUE="\[\033[0;94m\]"
local PURPLE="\[\033[0;35m\]"
local LPURPLE="\[\033[0;95m\]"
local CYAN="\[\033[0;36m\]"
local LCYAN="\[\033[0;96m\]"
local GRAY="\[\033[0;37m\]"
local LGRAY="\[\033[0;97m\]"
local WHITE="$LGRAY"
local DEFAULT="\[\033[0;39m\]"
local BLACKBG="\[\033[0;40m\]"
local LBLACKBG="\[\033[0;100m\]"
local GRAYBG="$LBLACKBG"
local REDBG="\[\033[0;41m\]"
local LREDBG="\[\033[0;101m\]"
local GREENBG="\[\033[0;42m\]"
local LGREENBG="\[\033[0;102m\]"
local BROWNBG="\[\033[0;43m\]"
local LBROWNBG="\[\033[0;103m\]"
local YELLOWBG="$BROWNBG"
local LYELLOWBG="$LBROWNBG"
local BLUEBG="\[\033[0;44m\]"
local LBLUEBG="\[\033[0;104m\]"
local PURPLEBG="\[\033[0;45m\]"
local LPURPLEBG="\[\033[0;105m\]"
local CYANBG="\[\033[0;46m\]"
local LCYANBG="\[\033[0;106m\]"
local GRAYBG="\[\033[0;47m\]"
local LGRAYBG="\[\033[0;107m\]"
local WHITEBG="$LGRAYBG"
local DEFAULTBG="\[\033[0;49m\]"
local RESET="\[$(tput sgr0)\]"
local BOLD="\[$(tput bold)\]"
local FAINT="\[$(tput dim)\]"
local ITALIC="\[$(tput sitm)\]"
local UNDERLINED="\[$(tput smul)\]"
local prompt=""
type git 2>/dev/null 1>/dev/null
if [ $? -eq 0 ]; then
local branch=$(git branch --no-color --format='%(refname:short)' 2>/dev/null)
if [ ! "" = "$branch" ]; then
prompt+="\n⦑${LPURPLE}git${RESET}:"
local origin="$(git remote -v 2>/dev/null | grep -E ^origin | head -n 1 | sed -r -e 's/^.+\t(https?|ssh)([^@]+@)?//g' -e 's/\s+.+$//g')"
# git remote -v 2>/dev/null | grep -E ^origin | head -n 1)"
if [ ! "" = "$origin" ]; then
prompt+="${LPURPLE}${origin}${RESET}:"
fi
prompt+="${LPURPLE}${branch}${RESET}:"
if [ "0" = "$(git status --porcelain --untracked-files=no . | wc -l)" ]; then
prompt+="${CYAN}"
else
prompt+="${LCYAN}"
fi
prompt+="/$(git rev-parse --show-prefix)${RESET}⦒\n"
fi
fi
type svn 2>/dev/null 1>/dev/null
if [ $? -eq 0 ]; then
local svninfo="$(svn info 2>/dev/null)"
local svnwhere="$(echo "$svninfo" | grep -E '^Repository Root' | cut -d/ -f3-)"
if [ ! "" = "$svnwhere" ]; then
prompt+="\n⦑${LPURPLE}svn${RESET}:${LPURPLE}${svnwhere}${RESET}:"
local svnpath="$(echo "$svninfo" | grep -E '^Relative URL' | cut -d/ -f2-)"
if [ "0" = "$(svn st --quiet --ignore-externals --depth=immediates 2>/dev/null | wc -l)" ]; then
prompt+="${CYAN}"
else
prompt+="${LCYAN}"
fi
prompt+="/${svnpath}${RESET}⦒\n"
fi
fi
if [ $ECODE -eq 0 ]; then
prompt+=${LGREEN}${HAPPYF[ $RANDOM % ${#HAPPYF[@]} ]}
else
prompt+=${LRED}${SADF[ $RANDOM % ${#SADF[@]} ]}
fi
prompt+=$RESET
prompt+="「"
if [ $UID -eq 0 ]; then
prompt+="${RED}\u${RESET}"
else
prompt+="${LGREEN}\u${RESET}"
fi
prompt+="${LYELLOW}\H${RESET}」"
prompt+="⧼ "
case $PWD in
$HOME*|$HOME)
prompt+=${LCYAN}
;;
/tmp|/tmp/*)
prompt+=${LCYAN}
;;
*)
prompt+=${LLRED}
;;
esac
prompt+="\w${RESET} ⧽ "
if [ $UID -eq 0 ]; then
prompt+="# "
else
prompt+="$ "
fi
export PS1=${prompt}
}
export LC_ALL="C.UTF-8"
export -f my_custom_prompt
PROMPT_COMMAND="my_custom_prompt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment