Skip to content

Instantly share code, notes, and snippets.

@irgeek
Created April 2, 2019 04:35
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 irgeek/e0fd4a351f62f42ba74a0b18db56aa38 to your computer and use it in GitHub Desktop.
Save irgeek/e0fd4a351f62f42ba74a0b18db56aa38 to your computer and use it in GitHub Desktop.
#!/bin/bash
_red() { echo '\[\e[31m\]'"$1"'\[\e[m\]'; }
_grn() { echo '\[\e[32m\]'"$1"'\[\e[m\]'; }
_ylw() { echo '\[\e[33m\]'"$1"'\[\e[m\]'; }
_blu() { echo '\[\e[34m\]'"$1"'\[\e[m\]'; }
_fus() { echo '\[\e[35m\]'"$1"'\[\e[m\]'; }
_cyn() { echo '\[\e[36m\]'"$1"'\[\e[m\]'; }
_wht() { echo '\[\e[37m\]'"$1"'\[\e[m\]'; }
_ppl() { echo '\[\e[38;5;55m\]'"$1"'\[\e[m\]'; }
_lgrn() { echo '\[\e[38;5;84m\]'"$1"'\[\e[m\]'; }
_mgry() { echo '\[\e[38;5;238m\]'"$1"'\[\e[m\]'; }
__venv_name() {
if [ -n "${VIRTUAL_ENV}" ]; then
echo "($(basename "${VIRTUAL_ENV}")) "
fi
}
__mk_ps1() {
local HOST HISTORY TIME WORK_DIR GIT_BRANCH VENV PROMPT
if [ $EUID == 0 ]; then
HOST=$(_red '\h');
else
HOST=$(_grn '\h');
fi
HISTORY='[\!]';
TIME=$(_mgry '[\A]');
WORK_DIR=$(_ylw '\W');
GIT_BRANCH=$(_cyn '$(__git_ps1 " (%s)")');
VENV=$(_ppl '$(__venv_name)');
PROMPT=$(_grn '\$');
if have_command git; then
echo "${VENV}${TIME} $HISTORY $HOST $WORK_DIR$GIT_BRANCH $PROMPT ";
else
echo "${VENV}${TIME} $HISTORY $HOST $WORK_DIR $PROMPT ";
fi
}
PS1=$(__mk_ps1)
export PS1
if [[ ! ${PROMPT_COMMAND} =~ 'history -a' ]]; then
if [[ -z ${PROMPT_COMMAND} ]]; then
export PROMPT_COMMAND="history -a"
else
export PROMPT_COMMAND="${PROMPT_COMMAND}; history -a"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment