Skip to content

Instantly share code, notes, and snippets.

@beccasaurus
Last active April 29, 2021 00:09
Show Gist options
  • Save beccasaurus/f0c78384d7680b68b27512866a281959 to your computer and use it in GitHub Desktop.
Save beccasaurus/f0c78384d7680b68b27512866a281959 to your computer and use it in GitHub Desktop.
My PS1
MY_PROMPT_HOSTNAMES=(
"beccabox:🐧"
"winvm:🕹️"
)
MY_PROMPT_HOME="$HOME"
[ -d /cygdrive/b ] && MY_PROMPT_HOME=/cygdrive/b
MY_PROMPT_FOLDERS=(
"$MY_PROMPT_HOME/Code/beccasaurus/minispec-main:💻 🦖 🧫 ⇪"
"$MY_PROMPT_HOME/Code/beccasaurus/minispec:💻 🦖 🧫"
"$MY_PROMPT_HOME/Code/specs-sh:💻 🔬"
"$MY_PROMPT_HOME/Code/shellbox-sh:💻 🐚"
"$MY_PROMPT_HOME/Code/beccasaurus:💻 🦖"
"$MY_PROMPT_HOME/Code:💻"
"$MY_PROMPT_HOME:🏡"
)
myPromptHostname() {
local hostname="$HOSTNAME"
local item
for item in "${MY_PROMPT_HOSTNAMES[@]}"
do
if [ "$hostname" = "${item%:*}" ]
then
printf '%s' "${item##*:}"
return 0
fi
done
printf '%s' "$hostname"
}
myPromptFolder() {
local folder="$PWD"
local item
for item in "${MY_PROMPT_FOLDERS[@]}"
do
if [[ "$folder" = "${item%:*}"* ]]
then
folder="${folder#"${item%:*}"}"
folder="${folder#/}"
if [ -z "$folder" ]
then
printf '%s' "${item##*:}"
else
printf '%s' "${item##*:} \e[94m(\e[36m$folder\e[94m)\e[0m"
fi
return 0
fi
done
printf '%s' "\e[94m(\e[36m$folder\e[94m)\e[0m"
}
myPromptGitBranch() {
local branch="$( git branch --show-current 2>/dev/null )"
if (( $? == 0 )) && [ -n "$branch" ] && [ "$branch" != main ]
then
printf '%s' " \e[94m(\e[35m$branch\e[94m)\e[0m"
fi
}
myPromptGitStatus() {
local status="$( git status 2>/dev/null )"
if (( $? == 0 )) && [ -n "$status" ]
then
case "$status" in
*Untracked*) printf '%s' " \e[31m*\e[0m" ;;
*Changes*) printf '%s' " \e[33m*\e[0m" ;;
*) printf '%s' " \e[32m*\e[0m" ;;
esac
fi
}
myPrompt() {
local lastCommandExitCode=$?
if (( $lastCommandExitCode == 0 ))
then
export PS1="\n$(myPromptHostname) $(myPromptFolder)$(myPromptGitBranch)$(myPromptGitStatus) \e[0m\n» "
else
export PS1="\n(\e[31m$lastCommandExitCode\e[0m)\n$(myPromptHostname) $(myPromptFolder)$(myPromptGitBranch)$(myPromptGitStatus) \e[0m\n» "
fi
__vte_prompt_command
}
PROMPT_COMMAND=myPrompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment