summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralexg0 <alexg@alexland.org>2009-11-30 04:47:39 +0800
committerLeonid Volnitsky <leonid@volnitsky.com>2009-11-30 12:59:31 +0800
commit908a3733288f2d987b4f679d0b9a4304018c395a (patch)
tree6700669f862f9078fed97c185f6c9c37b4f18a67
parentfixed: in locked state "git status" does not work (diff)
downloadgit-prompt-908a3733288f2d987b4f679d0b9a4304018c395a.tar.gz
git-prompt-908a3733288f2d987b4f679d0b9a4304018c395a.tar.bz2
git-prompt-908a3733288f2d987b4f679d0b9a4304018c395a.zip
Fixed errors related to running git-prompt.sh in Emacs shell-mode,
change prompt-char to '#' when root, allowed changing prompt-char (eg. $) when user. Added Emacs backup (*~) files as .gitignore. 1. tput colors was being concatinated to '0'. Inside emacs shell this is not valid, as `tput colors` is 0. 2. MC bug check was catching Emacs shell inferior mode. Now checking for $INSIDE_EMACS variable. 3. Defined $prompt_char variable and $root_prompt_char variable. Defaulting $root_prompt_char to '#'. Can just use \$, which automatically changes between '$' and '#', but that would change defalt behavior. 4. Fixed typo in a comment (cmd_cmd -> cwd_cmd).
-rw-r--r--.gitignore4
-rw-r--r--git-prompt.conf7
-rwxr-xr-xgit-prompt.sh26
3 files changed, 29 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index 2d19fc7..827d95c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,5 @@
*.html
+
+# emacs backup and lock files
+*~
+\#*\#
diff --git a/git-prompt.conf b/git-prompt.conf
index c4706c9..bdae7d5 100644
--- a/git-prompt.conf
+++ b/git-prompt.conf
@@ -46,7 +46,8 @@
### directory, exit code, root color
-# if [ 0`tput colors` -ge 8 ]; then # if terminal supports colors
+# cols=`tput colors`
+# if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors
# dir_color=CYAN
# rc_color=red
# user_id_color=blue
@@ -56,6 +57,10 @@
# rc_color=bw_bold
# fi
+### prompt character, default '>' for regular user, '#' for root
+# prompt_char='>'
+## prompt_char='$'
+# root_prompt_char='#'
##### Per host color
diff --git a/git-prompt.sh b/git-prompt.sh
index d6b0492..eb60bb4 100755
--- a/git-prompt.sh
+++ b/git-prompt.sh
@@ -25,15 +25,23 @@
#### dir, rc, root color
- if [ 0`tput colors` -ge 8 ]; then # if terminal supports colors
+ #### alexg: removed prefixing 0 to `tput colors`,
+ #### in emacs shell-mode tput colors returns -1
+ cols=`tput colors`
+ if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors
dir_color=${dir_color:-CYAN}
rc_color=${rc_color:-red}
user_id_color=${user_id_color:-blue}
root_id_color=${root_id_color:-magenta}
- else # only B/W
+ else # only B/W
dir_color=${dir_color:-bw_bold}
rc_color=${rc_color:-bw_bold}
fi
+ unset cols
+
+ #### prompt character, default '>' for user, '#' for root
+ prompt_char=${prompt_char:-'>'}
+ root_prompt_char=${root_prompt_char:-'#'}
#### vcs state colors
init_vcs_color=${init_vcs_color:-WHITE} # initial
@@ -129,10 +137,13 @@
unset PROMPT_COMMAND
- ####### work around for MC bug
- if [ -z "$TERM" -o "$TERM" = "dumb" -o -n "$MC_SID" ]; then
+ ####### work around for MC bug.
+ ####### specifically exclude emacs, want full when running inside emacs
+ if [[ -z "$TERM" || \
+ ("$TERM" = "dumb" && -z "$INSIDE_EMACS") || \
+ -n "$MC_SID" ]]; then
unset PROMPT_COMMAND
- PS1='\w> '
+ PS1="\w$prompt_char "
return 0
fi
@@ -314,6 +325,7 @@ set_shell_label() {
# if root then make it root_color
if [ "$id" == "root" ] ; then
user_id_color=$root_id_color
+ prompt_char="$root_prompt_char"
fi
color_who_where="$user_id_color$color_who_where$colors_reset"
else
@@ -596,10 +608,10 @@ prompt_command_function() {
parse_vcs_status
# if cwd_cmd have back-slash, then assign it value to cwd
- # else eval cmd_cmd, cwd should have path after exection
+ # else eval cwd_cmd, cwd should have path after exection
eval "${cwd_cmd/\\/cwd=\\\\}"
- PS1="$colors_reset$rc$head_local$color_who_where$dir_color$cwd$tail_local$dir_color> $colors_reset"
+ PS1="$colors_reset$rc$head_local$color_who_where$dir_color$cwd$tail_local$dir_color$prompt_char $colors_reset"
unset head_local tail_local pwd
}