ソースを参照

Call profile-local last
No error if lacking p4/git
Username in blue (bold) for default PS1.

Samuel Jaffe 8 年 前
コミット
4b4676ef25
2 ファイル変更15 行追加7 行削除
  1. 2 2
      bashrc
  2. 13 5
      profile-util

+ 2 - 2
bashrc

@@ -1,5 +1,5 @@
 
-if [[ -f ${HOME}/.profile-local ]]; then . ${HOME}/.profile-local; fi
-
 . ${HOME}/.profile-util
 
+if [[ -f ${HOME}/.profile-local ]]; then . ${HOME}/.profile-local; fi
+

+ 13 - 5
profile-util

@@ -1,16 +1,24 @@
 CYAN="\e[96m"
 GREEN="\e[92m"
 RED="\e[91m"
+BBLUE="\e[34;1m"
 RESET="\e[0m"
+IS_PASS() {
+  [[ $1 -eq 0 ]] || [[ $1 -gt 128 ]]
+}
 SUCCESS() {
-  if [[ $1 -eq 0 ]] || [[ $1 -gt 128 ]]; then
+  if IS_PASS $1; then
     echo -en $GREEN 
   else
     echo -en $RED
   fi
 }
-CODE() { [[ $1 -eq 0  ]] || [[ $1 -gt 128  ]] || echo "(rc=$1) "; }
-export PS1='$(rc=$?; echo -e "\[$CYAN\]\D{%F %T} \[$(SUCCESS $rc)\]\u@\h:[\w] $(CODE $rc)\[$RESET\]$ ")'
+CODE() { IS_PASS $1 || echo "(rc=$1) "; }
+GITBRANCH() {
+  local branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
+  [[ -z ${branch} ]] || echo -n ":${branch}"
+}
+export PS1='$(rc=$?; echo -e "\[$CYAN\]\D{%F %T} \[$BBLUE\]\u\[$RESET\]@\[$(SUCCESS $rc)\]\h:[\w$(GITBRANCH)] $(CODE $rc)\[$RESET\]$ ")'
 
 PATH="$HOME/usr/local/bin:$HOME/bin:$HOME/usr/bin:$PATH"
 export PATH
@@ -143,6 +151,6 @@ else
   . ${HOME}/.profile-linux
 fi
 
-has git && . ${HOME}/.profile-git
-has p4 && . ${HOME}/.profile-p4
+has git && . ${HOME}/.profile-git || true
+has p4 && . ${HOME}/.profile-p4 || true