dotfiles/bash/bash_prompt.sh

79 lines
1.5 KiB
Bash
Raw Permalink Normal View History

angle=""
NO_FORMAT="\033[0m"
2024-08-13 11:15:32 +00:00
fg="\033[38;2;"
bg="\033[48;2;"
function col() {
red="$1"
grn="$2"
blu="$3"
if [[ "$4" == "b" ]]; then
echo "$bg$red;$grn;$blu"m
else
echo "$fg$red;$grn;$blu"m
fi
}
rad_red="$(col 255 53 94)"
vsoft_red="$(col 237 137 157)"
lime_green="$(col 54 178 91)"
gray="$(col 70 70 70)"
mod_blue="$(col 49 142 193)"
dark_cyan="$(col 0 139 139)"
strong_orng="$(col 193 79 29)"
#If user is root
if [[ "$USER" == "root" ]]; then
2024-08-13 11:15:32 +00:00
angle1_col="$rad_red";
home_col="$rad_red";
else
2024-08-13 11:15:32 +00:00
angle1_col="$lime_green";
home_col="$lime_green";
fi
2024-08-13 11:15:32 +00:00
dir=$(pwd)
git_branch=$(git status 2>/dev/null | cut -d" " -f3 | sd "\n.*" "")
if [[ -n $git_branch ]]; then
repo="$(git rev-parse --show-toplevel)"
if [[ $git_branch == "main" ]]; then
branch_col="$strong_orng"
else
branch_col="$gray"
fi
dir="$(echo $dir | sd "$repo/" "$(basename $repo) $branch_col󰊢 $gray:")"
angle3_col="$dark_cyan";
else
2024-08-13 11:15:32 +00:00
angle3_col="$gray";
fi
2024-08-13 11:15:32 +00:00
dir="$(echo $dir | sd "^$HOME" "$home_col~$gray")"
case "$SHELL" in
"/bin/bash")
shell_char=""
;;
"/usr/bin/zsh")
shell_char="󰰶"
;;
"/usr/bin/fish")
shell_char=""
;;
*)
shell_char="󱆃"
esac
2024-08-13 11:15:32 +00:00
#If previous commant was successful
if [[ $? -eq 0 ]]; then
angle2_col="$lime_green";
else
angle2_col="$rad_red";
fi
2024-08-13 11:15:32 +00:00
prompt="$gray$shell_char $gray$dir$angle1_col$angle$angle2_col$angle$angle3_col$angle $NO_FORMAT"
2024-08-13 11:15:32 +00:00
echo "$prompt"
#export PS1="$prompt"