aboutsummaryrefslogtreecommitdiff
path: root/snowfall/modules/nixos/apps/bash/prompt.sh
diff options
context:
space:
mode:
authorCaroline Larimore <caroline@larimo.re>2025-02-04 17:28:45 -0800
committerCaroline Larimore <caroline@larimo.re>2025-04-14 18:58:44 -0700
commite45aca9d0cbda0559fb3c6a8075e029faa9c58ac (patch)
tree17d9e668d56344206247e74ff8ed12e004729193 /snowfall/modules/nixos/apps/bash/prompt.sh
parentef4b43dfad047cbd3219deaab8f50b8cd4bc1891 (diff)
migration: bash config
Diffstat (limited to 'snowfall/modules/nixos/apps/bash/prompt.sh')
-rw-r--r--snowfall/modules/nixos/apps/bash/prompt.sh86
1 files changed, 86 insertions, 0 deletions
diff --git a/snowfall/modules/nixos/apps/bash/prompt.sh b/snowfall/modules/nixos/apps/bash/prompt.sh
new file mode 100644
index 0000000..ff3ebe0
--- /dev/null
+++ b/snowfall/modules/nixos/apps/bash/prompt.sh
@@ -0,0 +1,86 @@
+source "$(dirname "${BASH_SOURCE[0]}")/git-prompt.sh"
+
+PROMPT_CHAR='❯'
+
+if [[ "$TERM" == "xterm-kitty" ]]; then
+ function prompt.bubble {
+ printf '\[\e[49m\e[38;5;237m\]◖\[\e[48;5;237m\e[39m\]%s\[\e[0m\e[49m\e[38;5;237m\]◗\[\e[0m\]' "$@";
+ }
+elif [[ "$TERM" == "xterm-256color" ]]; then
+ function prompt.bubble {
+ printf '\[\e[38;5;237m\](\[\e[0m\]%s\[\e[0m\e[38;5;237m\])\[\e[0m\]' "$@";
+ }
+else
+ PROMPT_CHAR='>'
+ function prompt.bubble {
+ printf '\[\e[2;39m\](\[\e[0m\]%s\[\e[0m\e[2;39m\])\[\e[0m\]' "$@";
+ }
+fi
+
+function prompt.git {
+ GIT_PS1_STATESEPARATOR=';'
+ GIT_PS1_SHOWDIRTYSTATE=1
+ GIT_PS1_SHOWUNTRACKEDFILES=
+ GIT_PS1_SHOWUPSTREAM=
+
+ GIT_PS1_HIDE_IF_PWD_IGNORED=1
+
+ local git_ps1="$(__git_ps1)"
+ git_ps1="${git_ps1##' ('}"
+ git_ps1="${git_ps1%')'}"
+
+ IFS=';' read -r branch state _ <<< "$git_ps1"
+
+ if [[ -n "$branch" ]]; then
+ printf ' '
+
+ if [[ "$state" == '*' ]]; then
+ prompt.bubble "$(printf '\[\e[4;32m\]%s' "$branch")"
+ else
+ prompt.bubble "$(printf '\[\e[32m\]%s' "$branch")"
+ fi
+ fi
+}
+
+function prompt.prepare {
+ local err=$?
+ PS1="\\[\e[0m\\]\n"
+
+ local subshell=''
+ local base_shlvl=1
+ local shlvl=$((SHLVL-base_shlvl))
+
+ if [[ -n "$IN_NIX_SHELL" ]]; then
+ subshell="\\[\e[33m\\]nix"
+ fi
+ if [[ $shlvl != 0 && ! ($shlvl == 1 && -n "$IN_NIX_SHELL") ]]; then
+ if [[ -n "$subshell" ]]; then subshell+="\\[\e[39m\\] "; fi
+ subshell+="\\[\e[2;37m\\]$shlvl"
+ fi
+ if [[ -n "$subshell" ]]; then
+ PS1+="$(prompt.bubble "$subshell") "
+ fi
+
+ if [[ $EUID == 0 ]]; then
+ PS1+="$(prompt.bubble "\\[\e[4m\\]\u@\H")"
+ else
+ PS1+="$(prompt.bubble "\u@\H")"
+ fi
+
+ PS1+=" $(prompt.bubble "\\[\e[34m\\]\w")"
+ PS1+="$(prompt.git)"
+ if [[ $err != 0 ]]; then
+ PS1+=" $(prompt.bubble "\\[\e[31m\\]$err")"
+ fi
+ PS1+=" $(prompt.bubble "$PROMPT_CHAR") "
+
+ if [[ $err != 0 ]]; then
+ (exit "$err")
+ fi
+}
+
+PROMPT_COMMAND='prompt.prepare'
+
+function baller {
+ printf '🮲🮳⚽︎ \n'
+}