]> code.delx.au - dotfiles/blobdiff - .bashrc
bashrc: git-prompt for Fedora
[dotfiles] / .bashrc
diff --git a/.bashrc b/.bashrc
index 06b9d258bab6c90dd6108f3fe217142b3732b0cf..5d2f8b203b112da43f56619898298518ab135034 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -102,6 +102,7 @@ function find_up_exists {
 
 for p in /usr/lib/git-core/git-sh-prompt \
          /usr/share/git/completion/git-prompt.sh \
+         /usr/share/git-core/contrib/completion/git-prompt.sh \
          /usr/local/share/git-core/contrib/completion/git-prompt.sh
 do
     [ -r "$p" ] && source "$p" && break
@@ -140,9 +141,10 @@ PS1="$PS1"'\n\$ '
 #################################
 
 function print_exit_code {
-    local exit_msg="\e[01;33mexit code: $?\e[00m"
+    local exit_code="$?"
     if [ -z "${BASH_SOURCE[1]}" ]; then
-        echo -e "$exit_msg"
+        printf '\e[01;33mexit code: %s\e[00m\n' \
+            "$exit_code"
     fi
 }
 trap print_exit_code ERR
@@ -292,31 +294,28 @@ fi
 
 # When at a prompt display `workingdir (hostname)`
 function print_title_prompt {
-    echo -ne "\e]0;bash:${PWD/$HOME/\~} ($(hostname -s))\a"
+    printf '\e]0;bash:%s (%s)\a' \
+        "${PWD/$HOME/\~}" \
+        "$(hostname -s)"
 
     if [[ "$TERM" == screen* ]]; then
-        echo -ne '\ekbash\e\\'
+        printf '\ekbash\e\\'
     fi
 }
 PROMPT_COMMAND=print_title_prompt
 
-# Display the command about to be executed
-# This must go at the end of bashrc to avoid running the trap on commands in the bashrc
+# Display the command about to be executed. This must go at the end of the
+# bashrc to avoid running the trap on commands in the bashrc
 function print_title_exec {
     [ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return
 
-    echo -ne '\e]0;'
-    echo -n "$BASH_COMMAND" | tr -cd '[:graph:] '
-    echo -n " ($(hostname -s))"
-    echo -ne '\a'
+    printf '\e]0;%s (%s)\a' \
+        "$(tr -cd '[:graph:] ' <<< "$BASH_COMMAND")" \
+        "$(hostname -s)"
 
     if [[ "$TERM" == screen* ]]; then
-        echo -ne '\ek'
-        echo -n "$BASH_COMMAND" | \
-            sed 's/^sudo //' | \
-            cut -d' ' -f1 | \
-            tr -cd '[:graph:]'
-        echo -ne '\e\\'
+        printf '\ek%s\e\\' \
+            "$(sed -n -e 's/sudo //' -e 's/ .*//' -e 1p <<< "$BASH_COMMAND")"
     fi
 }
 trap print_title_exec DEBUG