From 035e07d395b2b2fc5d6b1fe9b7e2942dace0a4af Mon Sep 17 00:00:00 2001 From: Salt Date: Wed, 18 Sep 2019 03:29:48 -0500 Subject: [PATCH] .profile: Overcomplicate the prompt --- .profile | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/.profile b/.profile index b6dce9c4..91549aef 100755 --- a/.profile +++ b/.profile @@ -261,10 +261,15 @@ alias todo='$EDITOR "$HOME/Documents/todo"' _ps1() { exitcode="$?" r="\e[0m" - fg_blue="\e[34m" + bg_red="\e[41m" + bg_yellow="\e[43m" + bg_blue="\e[44m" + fg_black="\e[30m" fg_red="\e[31m" fg_green="\e[32m" fg_yellow="\e[33m" + fg_blue="\e[34m" + fg_magenta="\e[35m" fg_grey="\e[37m" fg_bold="\e[1m" @@ -298,13 +303,39 @@ _ps1() { else cpwd="$PWD" fi + # Show read-only status in certain directories + if [ "$UID" = 0 ]; then + # Fuck you I'm root + prompt="${fg_red}#${r}" + elif ! [ -d "$PWD" ]; then + # What the fuck happened to my directory + prompt="${bg_red}${fg_black}!${r}" + elif ! [ -r "$PWD" ]; then + # Can't read is worst case + prompt="${fg_red}"'$'"${r}" + elif ! [ -x "$PWD" ]; then + # Can read it but can't search it is weird but also bad + if [ -w "$PWD" ]; then + # Fixable + prompt="${bg_blue}${fg_black}"'$'"${r}" + else + # Unfixable + prompt="${bg_yellow}${fg_black}"'$'"${r}" + fi + elif ! [ -w "$PWD" ]; then + # Can't write is really common but also good to know + prompt="${fg_magenta}"'~'"${r}" + else + # Otherwise we should be fine + prompt="${fg_green}"'$'"${r}" + fi # Alert us if the last command failed unset fail if ! [ "$exitcode" = "0" ]; then fail="${fg_bold}${fg_red}?" fi # shellcheck disable=2059 - printf "[${prefix}${cpwd}${r}]${fail}${r}${fg_green}\$${r} " + printf "[${prefix}${cpwd}${r}]${fail}${r}${prompt}${r} " } # And export our PS1