From 666f002cd085d50c5b4fecec8f21940e26511d7d Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Sat, 14 Jun 2008 11:59:19 +0300 Subject: git WD status detection added (display still ugly) --- prompt | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'prompt') diff --git a/prompt b/prompt index 4a7b799..9c68d10 100755 --- a/prompt +++ b/prompt @@ -254,10 +254,33 @@ PROMPT_COMMAND=' # LOCAL # GIT - if [[ -d .git || -d ../.git || -d ../../.git ]]; then - local=`git branch -a |sed -n "s/^* //p"` - local=${local+($local)} - fi + if [[ -d .git || -d ../.git || -d ../../.git ]]; then + + ### branch + branch=`git branch -a |sed -n "s/^* //p"` + + ### state + # clean(blue) nothing to commit (working directory clean) + # modified(red) # Changed but not updated: + # added(green) # Changes to be committed: + # untracked(yellow) # Untracked files: + + status_msg=`git status` + state=` + git status | + sed -n -e " + s/nothing to commit (working directory clean)/clean/p + s/^# Untracked files:/untracked/p + s/^# Changed but not updated:/modified/p + s/^# Changes to be committed:/added/p + " + ` + + ### compose local label + local=${branch+($branch $state)} + + fi + ######################### #PS1="$label$rc'$color_who_where$dir_color'${head:10*(${#PWD}max)*(${#PWD}-max):max}> '$colors_reset'" PS1="$label$rc'$color_who_where$dir_color'\w$local> '$colors_reset'" -- cgit v1.2.3 From c2f4326071f52dc77d72b4406e25b7746ec3f47b Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Sat, 14 Jun 2008 13:24:38 +0300 Subject: eval works --- prompt | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) (limited to 'prompt') diff --git a/prompt b/prompt index 9c68d10..13431d7 100755 --- a/prompt +++ b/prompt @@ -159,22 +159,44 @@ export -f set_shell_title ### if term support colors, then use color prompt, else bold - colors_reset='\['`tput sgr0`'\]' + black='\['`tput setaf 0`'\]' + red='\['`tput setaf 1`'\]' + green='\['`tput setaf 2`'\]' + yellow='\['`tput setaf 3`'\]' + blue='\['`tput setaf 4`'\]' + magenta='\['`tput setaf 5`'\]' + cyan='\['`tput setaf 6`'\]' + white='\['`tput setaf 7`'\]' + + BLACK='\['`tput setaf 0; tput bold`'\]' + RED='\['`tput setaf 1; tput bold`'\]' + GREEN='\['`tput setaf 2; tput bold`'\]' + YELLOW='\['`tput setaf 3; tput bold`'\]' + BLUE='\['`tput setaf 4; tput bold`'\]' + MAGENTA='\['`tput setaf 5; tput bold`'\]' + CYAN='\['`tput setaf 6; tput bold`'\]' # why 14 dosn't work? + WHITE='\['`tput setaf 7; tput bold`'\]' + + bw_bold='\['`tput bold`'\]' + bell=`tput bel` + + colors_reset='\['`tput sgr0`'\]' - #"bell='\['`tput bel`'\]' - bell=`tput bel` # Workaround for UTF readline(?) bug. Dissable bell when UTF locale |grep -qi UTF && bell='' if [ "`tput colors`" -ge 8 ]; then # Colors - dir_color='\['`tput setaf 6; tput bold`'\]' - rc_color='\['`tput setaf 1;`$bell'\]' - root_id_color='\['`tput setaf 5`'\]' + dir_color='CYAN' + rc_color='red' + root_id_color='magenta' else # B/W - dir_color='\['`tput bold`'\]' - rc_color='\['`tput bold;`$bell'\]' + dir_color='bw_bold' + rc_color='bw_bold' fi + eval dir_color="\$$dir_color" + eval rc_color="\$$rc_color" + eval root_id_color="\$$root_id_color" ########################################################### HOST @@ -188,19 +210,19 @@ export -f set_shell_title #host=`hostname --short` #host=`echo ${host%$default_host} | tr a-z A-Z` host=`echo ${host} | tr a-z A-Z` - # don't use bright, margenta(5), case $host in - TOSHA) host_color='\['`tput setaf 3`'\]' ;; - TASHA) host_color='\['`tput setaf 6`'\]' ;; - AL) host_color='\['`tput setaf 2`'\]' ;; - SH) host_color='\['`tput setaf 4`'\]' ;; - LVV) host_color='\['`tput setaf 4`'\]' ;; - AHP) host_color='\['`tput setaf 7`'\]' ;; + TOSHA) host_color='yellow' ;; + TASHA) host_color='cyan' ;; + AL) host_color='geen' ;; + SH|LVV) host_color='blue' ;; + AHP) host_color='white' ;; esac else host="" fi + eval host_color="\$$host_color" + # we already should have short host name, but just in case host=${host%.localdoman} host=${host%.$default_domain} -- cgit v1.2.3 From 45e9391aa5e8090d16ae7a3906d4acd3013e2fe0 Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Sat, 14 Jun 2008 14:58:02 +0300 Subject: docs removed from head --- prompt | 52 ---------------------------------------------------- 1 file changed, 52 deletions(-) (limited to 'prompt') diff --git a/prompt b/prompt index 13431d7..5692720 100755 --- a/prompt +++ b/prompt @@ -1,47 +1,4 @@ -#-------------------------- -# /etc/prompt - sets bash prompt -# -# To use it run -# . /etc/prompt -# -# should be called after keychain (it uses keychain env vars (SSH_..) to detect if host is remote) -# -# -# Sample "line-shot" -# -# Default user on default host in home dir -# ~> -# -# As before but Last command has return code 13, system bell is sounded -# 13 ~> -# -# User "lvv" on host "big" in "/tmp" dir, color of BIG set to specific color if set in config -# Hostname is alwais shown if host is remote. -# lvv@BIG /tmp > -# -# User "root" (almost all prompt set to magenta color) -# root /tmp> -# -# -# Features/Advantages -# -# Any terminal. -# All color prompt scripts that I've seen use hard coded terminal escape -# sequences for vt102/vt220. That is, they will not work on any other -# terminal. My prompt will work on on any terminfo terminal -# -# Shell Title -# Function set_shell_title() set xterm title, gnome-terminal tabs and gnu-screen labels. -# by default it current dir. It is also possible to use it for other info. -# I use it to display remote hostname or file names I am currently editing. -# (FIXME write how to do this) -# (FIXME make screen shots) -# -# Leonid@Volnitsky.com / 2007 -# -################ -# # TOFIX: after "su -" hostname is not displayed # # TO CHECK: @@ -53,15 +10,6 @@ # export LC_ALL # fi -# TODO -# display git brach http://unboundimagination.com/Current-Git-Branch-in-Bash-Prompt -#--- -# parse_git_branch() { -# git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' -# } -# PS1="\w\$(parse_git_branch) $ " -#--- -#git symbolic-ref HEAD ##################################################################### lvv Prompt # echo "*** /etc/prompt on A, TERM=$TERM" -- cgit v1.2.3 From 36a675acf4d65cd1288c8a1d5adc820996a6735a Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Sat, 14 Jun 2008 15:19:46 +0300 Subject: config moved to the top --- prompt | 62 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) (limited to 'prompt') diff --git a/prompt b/prompt index 5692720..6f481de 100755 --- a/prompt +++ b/prompt @@ -1,16 +1,33 @@ +##################################################################### CONFIG + default_user=lvv # default user is not displayed + #default_host="tosha" # default host is not displayed + default_domain="lvvnet" # default domain is not deplayed, remote host is alwais shown + + # dir, rc, root color + if [ "`tput colors`" -ge 8 ]; then # Colors + dir_color='CYAN' + rc_color='red' + root_id_color='magenta' + else # B/W + dir_color='bw_bold' + rc_color='bw_bold' + fi -# TOFIX: after "su -" hostname is not displayed -# -# TO CHECK: -# # GNU awk and sed have regex issues in a multibyte environment. If any locale -# # variables are set, then override by setting LC_ALL -# lvars=`locale 2>/dev/null | egrep -v '="?(|POSIX|C)"?$' 2>/dev/null` -# if [ -n "$lvars$LANG$LC_ALL" ]; then -# LC_ALL=C -# export LC_ALL -# fi + # where is user color? + + # host color + TOSHA_host_color='yellow' + TASHA_host_color='cyan' + AL_host_color='geen' + SH_host_color='blue' + LVV_host_color='blue' + AHP_host_color='white' + +##################################################################### + LC_ALL=C + # if label non empty, append 1 space + label=${1:+$1 } -##################################################################### lvv Prompt # echo "*** /etc/prompt on A, TERM=$TERM" unset PROMPT_COMMAND @@ -22,13 +39,6 @@ return 0 fi - # if label non empty, append 1 space - label=${1:+$1 } - - default_user=lvv # default user is not displayed - #default_host="tosha" # default host is not displayed - default_domain="lvvnet" # default domain is not deplayed, remote host is alwais shown - export who_where @@ -133,14 +143,6 @@ export -f set_shell_title # Workaround for UTF readline(?) bug. Dissable bell when UTF locale |grep -qi UTF && bell='' - if [ "`tput colors`" -ge 8 ]; then # Colors - dir_color='CYAN' - rc_color='red' - root_id_color='magenta' - else # B/W - dir_color='bw_bold' - rc_color='bw_bold' - fi eval dir_color="\$$dir_color" eval rc_color="\$$rc_color" @@ -158,13 +160,7 @@ export -f set_shell_title #host=`hostname --short` #host=`echo ${host%$default_host} | tr a-z A-Z` host=`echo ${host} | tr a-z A-Z` - case $host in - TOSHA) host_color='yellow' ;; - TASHA) host_color='cyan' ;; - AL) host_color='geen' ;; - SH|LVV) host_color='blue' ;; - AHP) host_color='white' ;; - esac + eval host_color=\$${host}_host_color else host="" fi -- cgit v1.2.3 From 25e0b2f6d1fa1d975511461086b6ce56c2de3f71 Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Sat, 14 Jun 2008 15:45:47 +0300 Subject: branch changes color according to git status --- prompt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'prompt') diff --git a/prompt b/prompt index 6f481de..39880a5 100755 --- a/prompt +++ b/prompt @@ -23,6 +23,13 @@ LVV_host_color='blue' AHP_host_color='white' + # git color + git_clean=blue # clean(blue) nothing to commit (working directory clean) + git_modified=red # modified(red) # Changed but not updated: + git_added=green # added(green) # Changes to be committed: + git_untracked=yellow # untracked(yellow) # Untracked files: + + ##################################################################### LC_ALL=C # if label non empty, append 1 space @@ -232,7 +239,7 @@ PROMPT_COMMAND=' # untracked(yellow) # Untracked files: status_msg=`git status` - state=` + status=` git status | sed -n -e " s/nothing to commit (working directory clean)/clean/p @@ -243,13 +250,15 @@ PROMPT_COMMAND=' ` ### compose local label - local=${branch+($branch $state)} + eval git_color="\${git_$status}" + eval esc_string="\$$git_color" + local="${branch+$esc_string ($branch) }" fi ######################### #PS1="$label$rc'$color_who_where$dir_color'${head:10*(${#PWD}max)*(${#PWD}-max):max}> '$colors_reset'" - PS1="$label$rc'$color_who_where$dir_color'\w$local> '$colors_reset'" + PS1="$label$rc'$color_who_where$dir_color'\w$local$dir_color> '$colors_reset'" unset local ' #echo \"$color_who_where\" -- cgit v1.2.3 From c5b025718698d3edef8f772c25775827cd0f628a Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Sat, 14 Jun 2008 16:01:40 +0300 Subject: Bold attribute stays until reseted. Put in reset command before all colors. --- prompt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'prompt') diff --git a/prompt b/prompt index 39880a5..8fb1ef9 100755 --- a/prompt +++ b/prompt @@ -124,14 +124,14 @@ export -f set_shell_title ### if term support colors, then use color prompt, else bold - black='\['`tput setaf 0`'\]' - red='\['`tput setaf 1`'\]' - green='\['`tput setaf 2`'\]' - yellow='\['`tput setaf 3`'\]' - blue='\['`tput setaf 4`'\]' - magenta='\['`tput setaf 5`'\]' - cyan='\['`tput setaf 6`'\]' - white='\['`tput setaf 7`'\]' + black='\['`tput sgr0; tput setaf 0`'\]' + red='\['`tput sgr0; tput setaf 1`'\]' + green='\['`tput sgr0; tput setaf 2`'\]' + yellow='\['`tput sgr0; tput setaf 3`'\]' + blue='\['`tput sgr0; tput setaf 4`'\]' + magenta='\['`tput sgr0; tput setaf 5`'\]' + cyan='\['`tput sgr0; tput setaf 6`'\]' + white='\['`tput sgr0; tput setaf 7`'\]' BLACK='\['`tput setaf 0; tput bold`'\]' RED='\['`tput setaf 1; tput bold`'\]' -- cgit v1.2.3 From 79ffe8f9b15aefdd611ddf4cbd1689819ca4a335 Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Sat, 14 Jun 2008 15:45:47 +0300 Subject: branch changes color according to git status --- prompt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'prompt') diff --git a/prompt b/prompt index 8fb1ef9..4815188 100755 --- a/prompt +++ b/prompt @@ -23,11 +23,11 @@ LVV_host_color='blue' AHP_host_color='white' - # git color - git_clean=blue # clean(blue) nothing to commit (working directory clean) - git_modified=red # modified(red) # Changed but not updated: - git_added=green # added(green) # Changes to be committed: - git_untracked=yellow # untracked(yellow) # Untracked files: + # git color + git_clean=blue # nothing to commit (working directory clean) + git_modified=red # # Changed but not updated: + git_added=green # # Changes to be committed: + git_untracked=BLUE # # Untracked files: ##################################################################### -- cgit v1.2.3 From d543031671db5155f8a06a9db70284436e440f96 Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Sat, 14 Jun 2008 16:52:32 +0300 Subject: bug: temp fix for multiple git states --- prompt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'prompt') diff --git a/prompt b/prompt index 4815188..9e1472c 100755 --- a/prompt +++ b/prompt @@ -1,6 +1,6 @@ ##################################################################### CONFIG default_user=lvv # default user is not displayed - #default_host="tosha" # default host is not displayed + default_host="ahp" # default host is not displayed default_domain="lvvnet" # default domain is not deplayed, remote host is alwais shown # dir, rc, root color @@ -246,7 +246,8 @@ PROMPT_COMMAND=' s/^# Untracked files:/untracked/p s/^# Changed but not updated:/modified/p s/^# Changes to be committed:/added/p - " + " | + head -1 ` ### compose local label @@ -264,4 +265,5 @@ PROMPT_COMMAND=' #echo \"$color_who_where\" unset rc id tty bell default_user default_host unset rc_colors dir_color root_id_color + # vim: set syntax=sh: -- cgit v1.2.3