summaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorBlaise Thompson <blaise@untzag.com>2018-07-03 18:00:32 -0500
committerBlaise Thompson <blaise@untzag.com>2018-07-03 18:00:32 -0500
commitf94b9b632630175c589fdd73b8648bd00af64a1e (patch)
tree3f6efa14b765489c4d938377ed94a706c958bdde /bash
parentf972585b1ce8c6f29320f157cdd711277b3f5c33 (diff)
2018-07-03 18:00
Diffstat (limited to 'bash')
-rw-r--r--bash/bashrc.sync94
1 files changed, 93 insertions, 1 deletions
diff --git a/bash/bashrc.sync b/bash/bashrc.sync
index 842211a..199e206 100644
--- a/bash/bashrc.sync
+++ b/bash/bashrc.sync
@@ -1,4 +1,4 @@
-export PS1="\[\033[01;32m\]\u@\h \W \\$ \[$(tput sgr0)\]\[\033[0m\]"
+# --- environment variables -----------------------------------------------------------------------
export VISUAL=vim
export EDITOR="$VISUAL"
@@ -14,6 +14,98 @@ alias ledger-checking='ledger register checking --tail 15'
alias ledger-worth='ledger bal ^assets ^liabilities'
+
+# --- prompt command ------------------------------------------------------------------------------
+
+
+_bash_prompt_config() {
+
+ local USER_SYMBOL="\u"
+ local HOST_SYMBOL="\h"
+ local ESC_OPEN="\["
+ local ESC_CLOSE="\]"
+
+ if tput setaf >/dev/null 2>&1 ; then
+ _setaf () { tput setaf "$1" ; }
+ local RESET="${ESC_OPEN}$( { tput sgr0 || tput me ; } 2>/dev/null )${ESC_CLOSE}"
+ local BOLD="$( { tput bold || tput md ; } 2>/dev/null )"
+ else
+ # Fallback
+ _setaf () { echo "\033[0;$(($1+30))m" ; }
+ local RESET="\033[m"
+ local BOLD=""
+ ESC_OPEN=""
+ ESC_CLOSE=""
+ fi
+
+ # Normal colors
+ local BLACK="${ESC_OPEN}$(_setaf 0)${ESC_CLOSE}"
+ local RED="${ESC_OPEN}$(_setaf 1)${ESC_CLOSE}"
+ local GREEN="${ESC_OPEN}$(_setaf 2)${ESC_CLOSE}"
+ local YELLOW="${ESC_OPEN}$(_setaf 3)${ESC_CLOSE}"
+ local BLUE="${ESC_OPEN}$(_setaf 4)${ESC_CLOSE}"
+ local VIOLET="${ESC_OPEN}$(_setaf 5)${ESC_CLOSE}"
+ local CYAN="${ESC_OPEN}$(_setaf 6)${ESC_CLOSE}"
+ local WHITE="${ESC_OPEN}$(_setaf 7)${ESC_CLOSE}"
+
+ # Bright colors
+ local BRIGHT_GREEN="${ESC_OPEN}$(_setaf 10)${ESC_CLOSE}"
+ local BRIGHT_YELLOW="${ESC_OPEN}$(_setaf 11)${ESC_CLOSE}"
+ local BRIGHT_BLUE="${ESC_OPEN}$(_setaf 12)${ESC_CLOSE}"
+ local BRIGHT_VIOLET="${ESC_OPEN}$(_setaf 13)${ESC_CLOSE}"
+ local BRIGHT_CYAN="${ESC_OPEN}$(_setaf 14)${ESC_CLOSE}"
+ local BRIGHT_WHITE="${ESC_OPEN}$(_setaf 15)${ESC_CLOSE}"
+
+ # Bold colors
+ local BLACK_BOLD="${ESC_OPEN}${BOLD}$(_setaf 0)${ESC_CLOSE}"
+ local RED_BOLD="${ESC_OPEN}${BOLD}$(_setaf 1)${ESC_CLOSE}"
+ local GREEN_BOLD="${ESC_OPEN}${BOLD}$(_setaf 2)${ESC_CLOSE}"
+ local YELLOW_BOLD="${ESC_OPEN}${BOLD}$(_setaf 3)${ESC_CLOSE}"
+ local BLUE_BOLD="${ESC_OPEN}${BOLD}$(_setaf 4)${ESC_CLOSE}"
+ local VIOLET_BOLD="${ESC_OPEN}${BOLD}$(_setaf 5)${ESC_CLOSE}"
+ local CYAN_BOLD="${ESC_OPEN}${BOLD}$(_setaf 6)${ESC_CLOSE}"
+ local WHITE_BOLD="${ESC_OPEN}${BOLD}$(_setaf 7)${ESC_CLOSE}"
+
+ # Expose the variables we need in prompt command
+ P_USER=${BRIGHT_GREEN}${USER_SYMBOL}
+ P_HOST=${CYAN}${HOST_SYMBOL}
+ P_WHITE=${WHITE_BOLD}
+ P_BLUE=${BLUE_BOLD}
+ P_GREEN=${YELLOW_BOLD}
+ P_YELLOW=${GREEN_BOLD}
+ P_RED=${RED}
+ P_RESET=${RESET}
+
+}
+
+_bash_prompt_config
+unset _bash_prompt_config
+
+parse_git_branch() {
+ local OUT=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
+ if [ "$OUT" != "" ]; then echo "$OUT"; fi
+}
+
+bash_prompt_command() {
+ # conda
+ if [ "$CONDA_DEFAULT_ENV" != "" ];
+ then
+ P_CONDA="conda@$CONDA_DEFAULT_ENV "
+ else
+ P_CONDA=""
+ fi
+ # git
+ if [ "$(parse_git_branch)" != "" ];
+ then
+ P_GIT="git@$(parse_git_branch) "
+ else
+ P_GIT=""
+ fi
+ # construct
+ export PS1="${P_YELLOW}\u@\h ${P_GREEN}${P_CONDA}${P_RED}${P_GIT}${P_BLUE}\W ${P_YELLOW}\\$ ${P_RESET}"
+}
+PROMPT_COMMAND=bash_prompt_command
+
# --- functions -----------------------------------------------------------------------------------
function countdown(){