Skip to content

Instantly share code, notes, and snippets.

@Ketrel
Last active February 12, 2018 22:08
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 Ketrel/f55bb765bcf57ee7cef249217d138438 to your computer and use it in GitHub Desktop.
Save Ketrel/f55bb765bcf57ee7cef249217d138438 to your computer and use it in GitHub Desktop.
Bash Prompt File
#!/bin/bash
p_checkRoot(){
if [ $(id -u) -eq 0 ]; then
return 0
fi
return 1
}
p_colorSetup(){
case "$TERM" in
*color*)
P_RES=$(printf "%b" "\e[00m")
P_BOLD=$(printf "%b" "\e[01m")
P_TIME=$(printf "%b" "\e[01;90m")
P_MPX=$(printf "%b" "\e[01;35m")
if p_checkRoot; then
P_NAME=$(printf "%b" "\e[01;91m")
P_HOST=$(printf "%b" "\e[00;31m")
else
P_NAME=$(printf "%b" "\e[01;92m")
P_HOST=$(printf "%b" "\e[00;32m")
fi
P_DIR=$(printf "%b" "\e[00;96m")
P_RED=$(printf "%b" "\e[31m")
P_GREEN=$(printf "%b" "\e[32m")
P_BLUE=$(printf "%b" "\e[34m")
;;
*)
P_RES=$(printf "%b" "\e[00m")
P_BOLD=$(printf "%b" "\e[01m")
P_TIME=$(printf "%b" "")
P_MPX=$(printf "%b" "\e[01m")
P_NAME=$(printf "%b" "\e[01m")
P_HOST=$(printf "%b" "\e[00m")
P_DIR=$(printf "%b" "\e[00m")
P_RED=$(printf "%b" "\e[01m")
P_GREEN=$(printf "%b" "\e[00m")
P_BLUE=$(printf "%b" "\e[00m")
;;
esac
}
p_returnColor(){
if [ $1 -eq 0 ]; then
local color="${P_GREEN}"
else
local color="${P_RED}"
fi
printf "%s%s%s" "[R:\001${color}\002" "${1}" "\001${P_RES}\002]"
}
p_multiPlex(){
case "$TERM" in
*screen*|*tmux*)
printf "%s" "[\001${P_MPX}\002M\001${P_RES}\002]"
;;
esac
}
PROMPT_COMMAND='ret=$?;p_colorSetup;PS1="[\[${P_TIME}\]\A\[${P_RES}\]]$(p_multiPlex)[\[${P_NAME}\]\u\[${P_RES}\]@\[${P_HOST}\]\h\[${P_RES}\]]: \[${P_DIR}\]\w\[${P_RES}\]\n$(p_returnColor ${ret}) \\$ "'
#!/bin/bash
checkRoot(){
if [ $(id -u) -eq 0 ]; then
return 0
fi
return 1
}
colorSetup(){
case "$TERM" in
*color*)
P_RES=$(printf "%b" "\e[00m")
P_BOLD=$(printf "%b" "\e[01m")
P_TIME=$(printf "%b" "\e[01;90m")
P_MPX=$(printf "%b" "\e[01;35m")
if checkRoot; then
P_NAME=$(printf "%b" "\e[01;91m")
P_HOST=$(printf "%b" "\e[00;31m")
else
P_NAME=$(printf "%b" "\e[01;92m")
P_HOST=$(printf "%b" "\e[00;32m")
fi
P_DIR=$(printf "%b" "\e[00;96m")
P_RED=$(printf "%b" "\e[31m")
P_GREEN=$(printf "%b" "\e[32m")
P_BLUE=$(printf "%b" "\e[34m")
;;
*)
P_RES=$(printf "%b" "\e[00m")
P_BOLD=$(printf "%b" "\e[01m")
P_TIME=$(printf "%b" "")
P_MPX=$(printf "%b" "\e[01m")
P_NAME=$(printf "%b" "\e[01m")
P_HOST=$(printf "%b" "\e[00m")
P_DIR=$(printf "%b" "\e[00m")
P_RED=$(printf "%b" "\e[01m")
P_GREEN=$(printf "%b" "\e[00m")
P_BLUE=$(printf "%b" "\e[00m")
;;
esac
}
returnColor(){
if [ $1 -eq 0 ]; then
local color="${P_GREEN}"
else
local color="${P_RED}"
fi
printf "%s%s%s" "[R:\001${color}\002" "${1}" "\001${P_RES}\002]"
}
multiPlex(){
case "$TERM" in
*screen*|*tmux*)
printf "%s" "[\001${P_MPX}\002M\001${P_RES}\002]"
;;
esac
}
PROMPT_COMMAND='ret=$?;colorSetup;PS1="[\[${P_TIME}\]\A\[${P_RES}\]]$(multiPlex)[\[${P_NAME}\]\u\[${P_RES}\]@\[${P_HOST}\]\h\[${P_RES}\]]: \[${P_DIR}\]\w\[${P_RES}\]\n$(returnColor ${ret}) \$ "'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment