From 6ff0d0bf10418516cf26e57b1749391855748f63 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Thu, 1 May 2014 23:28:17 -0700 Subject: [PATCH] Fix things for bash. --- dotfiles/lib/bash/prompt.sh | 54 +++++++++++++++++++++++-------- dotfiles/lib/shellrc.sh | 6 ++++ dotfiles/lib/shellrc/functions.sh | 6 ++-- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/dotfiles/lib/bash/prompt.sh b/dotfiles/lib/bash/prompt.sh index d9680b83..d3fa5a36 100644 --- a/dotfiles/lib/bash/prompt.sh +++ b/dotfiles/lib/bash/prompt.sh @@ -7,41 +7,69 @@ Blue='\e[0;34m' # Blue Purple='\e[0;35m' # Purple Cyan='\e[0;36m' # Cyan White='\e[0;37m' # White +BoldYellow='\e[1;33m' # Yellow + function current_directory() { - local PWD=$(pwd) - echo "${PWD/#$HOME/~}" + pwd | sed "s:$HOME:~:" } -function current_directory() { - local PWD=$(pwd) - echo "${PWD/#$HOME/~}" -} function git_prompt_info() { if test -z $(git branch-or-sha); then echo "" else - echo " on $(git branch-or-sha)$(git_status_character)" + echo " $(separator "on") $(git branch-or-sha)$(git_status_character)" fi } function git_status_character() { if git dirty; then - echo "✘" + print_with_color "✘" "$Red" else - echo "✔" + print_with_color "✔" "$Green" fi } function sandbox_prompt() { - if [ ! -z $(sandbox_prompt_info) ]; + if [ ! -z "$(sandbox_prompt_info)" ]; then - echo " with $(colored_sandbox_string)" + echo " $(separator "with") $(colored_sandbox_string)%{$reset_color%}" fi } -PS1="╭─% ${Green}\u ${White}at ${Blue}\h ${White}in \$(current_directory)\$(git_prompt_info)\$(sandbox_prompt) -╰─± " +function command_line_character() { + if ! test -z $(git branch-or-sha); + then + echo "±" + else + echo "○" + fi +} + +function prompt_basic_colors() { + export USERNAME_COLOR="$Green" + export SEPARATOR_COLOR="$Black" + export HOSTNAME_COLOR="$Blue" + export CURRENT_DIRECTORY_COLOR="$BoldYellow" +} + +function print_with_color() { + echo "$2$1\e[0m" +} + +function separator() { + print_with_color "$1" "$SEPARATOR_COLOR" +} + +prompt_basic_colors +function set_bash_prompt() { + PS1="╭─$(print_with_color "$(whoami)" "$USERNAME_COLOR") $(separator "at") $(print_with_color "`hostname -s`" "$HOSTNAME_COLOR") $(separator "in") $(print_with_color "`current_directory`" "$CURRENT_DIRECTORY_COLOR")$(git_prompt_info)$(sandbox_prompt) +╰─$(command_line_character) " +} + +export PROMPT_COMMAND=set_bash_prompt + +PS2='(%_) ' diff --git a/dotfiles/lib/shellrc.sh b/dotfiles/lib/shellrc.sh index d60bc57c..fcdb1b4d 100644 --- a/dotfiles/lib/shellrc.sh +++ b/dotfiles/lib/shellrc.sh @@ -1,3 +1,9 @@ for filename in ~/.lib/shellrc/*; do source $filename done +# Source everything twice just in case there were things that depended +# on each other. +for filename in ~/.lib/shellrc/*; do + source $filename +done + diff --git a/dotfiles/lib/shellrc/functions.sh b/dotfiles/lib/shellrc/functions.sh index f5e0d884..7a80722d 100644 --- a/dotfiles/lib/shellrc/functions.sh +++ b/dotfiles/lib/shellrc/functions.sh @@ -105,7 +105,8 @@ function git_root() { function git_diff_replacing() { local original_sha='HEAD~1' local new_sha='HEAD' - while getopts "do:n:" OPTCHAR; do; + while getopts "do:n:" OPTCHAR; + do case $OPTCHAR in o) original_sha="$OPTARG" @@ -129,7 +130,8 @@ function git_diff_replacing() { function git_reset_author() { local should_update_command='' local update_command='' - while getopts "a:e:A:E:h" OPTCHAR; do; + while getopts "a:e:A:E:h" OPTCHAR; + do case $OPTCHAR in a) new_author="$OPTARG";