From 3df29299d8dec6f5df8f6c62f741dc4154eb63d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 21 Sep 2013 21:34:24 +0200 Subject: [PATCH 001/118] -Fix: typo in variable name --- git-prompt.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index f99a1d0..5aed3df 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -152,9 +152,9 @@ #################################################################### MARKERS if [[ "$LC_CTYPE $LC_ALL" =~ "UTF" && $TERM != "linux" ]]; then - elipses_marker="…" + ellipse_marker="…" else - elipses_marker="..." + ellipse_marker="..." fi export who_where @@ -200,7 +200,7 @@ cwd_truncate() { # trunc middle if over limit - if [[ ${#path_middle} -gt $(( $cwd_middle_max + ${#elipses_marker} + 5 )) ]]; then + if [[ ${#path_middle} -gt $(( $cwd_middle_max + ${#ellipse_marker} + 5 )) ]]; then # truncate middle_tail=${path_middle:${#path_middle}-${cwd_middle_max}} @@ -212,7 +212,7 @@ cwd_truncate() { # use truncated only if we cut at least 4 chars if [[ $(( ${#path_middle} - ${#middle_tail})) -gt 4 ]]; then - cwd=$path_head$elipses_marker$middle_tail$path_last_dir + cwd=$path_head$ellipse_marker$middle_tail$path_last_dir fi fi fi @@ -619,7 +619,7 @@ parse_vcs_status() { if [[ ${#file_list} -gt $max_file_list_length ]] ; then file_list=${file_list:0:$max_file_list_length} if [[ $max_file_list_length -gt 0 ]] ; then - file_list="${file_list% *} $elipses_marker" + file_list="${file_list% *} $ellipse_marker" fi fi From f774e0115518df29043baf472f900e44271a83cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 21 Sep 2013 21:44:36 +0200 Subject: [PATCH 002/118] -Fix: better detection of UTF-8, add flag to track UTF-8-ness --- git-prompt.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 5aed3df..ccf1156 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -151,9 +151,11 @@ fi #################################################################### MARKERS - if [[ "$LC_CTYPE $LC_ALL" =~ "UTF" && $TERM != "linux" ]]; then + if [[ ("$LC_CTYPE $LC_ALL" =~ "UTF" || $LANG =~ "utf") && $TERM != "linux" ]]; then + utf8_prompt=1 ellipse_marker="…" else + utf8_prompt= ellipse_marker="..." fi From 6c232e8b7ebb72dbf5692e305d681bc863e41122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 21 Sep 2013 21:51:15 +0200 Subject: [PATCH 003/118] -Fix: use UTF-8 arrow chars in git report only if utf8_prompt flag set, else use plain replacements --- git-prompt.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index ccf1156..71f0daa 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -431,6 +431,17 @@ parse_git_status() { unset branch status modified added clean init added mixed untracked op detached + if [[ $utf8_prompt ]]; then + git_up_char="↑" + git_dn_char="↓" + git_updn_char="↕" + else + git_up_char="^" + git_dn_char="v" + git_updn_char="*" + fi + + # info not in porcelain status eval " $( git status 2>/dev/null | @@ -438,9 +449,9 @@ parse_git_status() { s/^# On branch /branch=/p s/^nothing to commi.*/clean=clean/p s/^# Initial commi.*/init=init/p - s/^# Your branch is ahead of \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${WHITE}↑/p - s/^# Your branch is behind \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${YELLOW}↓/p - s/^# Your branch and \(.\).\+\1 have diverged.*/freshness=${YELLOW}↕/p + s/^# Your branch is ahead of \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${WHITE}${git_up_char}/p + s/^# Your branch is behind \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${YELLOW}${git_dn_char}/p + s/^# Your branch and \(.\).\+\1 have diverged.*/freshness=${YELLOW}${git_updn_char}/p ' )" From 93bc3ac7cc2717dd0073394329405830e0b4b7be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 21 Sep 2013 22:22:11 +0200 Subject: [PATCH 004/118] -Add: battery module --- git-prompt.conf | 1 + git-prompt.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/git-prompt.conf b/git-prompt.conf index dee3c0c..ce86889 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -20,6 +20,7 @@ # hg_module=on # vim_module=on # virtualenv_module=on +# battery_module=off ########################################################### DEFAULT OBJECTS diff --git a/git-prompt.sh b/git-prompt.sh index 71f0daa..34fa841 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -23,9 +23,14 @@ hg_module=${hg_module:-on} vim_module=${vim_module:-on} virtualenv_module=${virtualenv_module:-on} + battery_module=${battery_module:-off} error_bell=${error_bell:-off} cwd_cmd=${cwd_cmd:-\\w} + #### check for acpi, disable corresponding module if not installed + if [[ -z $(which acpi) && -z $(acpi -b) ]]; then + battery_module=off + fi #### dir, rc, root color cols=`tput colors` # in emacs shell-mode tput colors returns -1 @@ -120,6 +125,8 @@ CYAN='\['`tput setaf 6; tput bold`'\]' WHITE='\['`tput setaf 7; tput bold`'\]' + whiteonred='\['`tput setaf 7; tput setab 1; tput bold`'\]' + dim='\['`tput sgr0; tput setaf p1`'\]' # half-bright bw_bold='\['`tput bold`'\]' @@ -348,6 +355,54 @@ set_shell_label() { color_who_where='' fi +create_battery_indicator () { + # if not a laptop: : + # if laptop on AC, not charging: ⚡ + # if laptop on AC, charging: ▕⚡▏ + # if laptop on battery: one of ▕▁▏▕▂▏▕▃▏▕▄▏▕▅▏▕▆▏▕▇▏▕█▏ + # color: red if power < 30 %, else normal + battery_string=$(acpi -b) + + if [[ $battery_string ]]; then + tmp=${battery_string%\%*} + battery_percent=${tmp##* } + if [[ "$battery_string" =~ "Discharging" ]]; then + if [[ $utf8_prompt ]]; then + battery_diagrams=( ▕▁▏ ▕▂▏ ▕▃▏ ▕▄▏ ▕▅▏ ▕▆▏ ▕▇▏ ▕█▏ ) + battery_pwr_index=$(($battery_percent/13)) + battery_indicator=${battery_diagrams[battery_pwr_index]} + else + battery_indicator="|$battery_percent|" + fi + elif [[ "$battery_string" =~ "Charging" ]]; then + if [[ $utf8_prompt ]]; then + battery_indicator="▕⚡▏" + else + battery_indicator="|^|" + fi + else + if [[ $utf8_prompt ]]; then + battery_indicator=" ⚡ " + else + battery_indicator=" = " + fi + fi + + if [[ $battery_percent -ge 31 ]]; then + battery_color=$colors_reset + elif [[ $battery_percent -ge 11 ]]; then + battery_color=$RED + else + battery_color=$whiteonred + fi + else + battery_indicator=":" + battery_color=$colors_reset + fi + battery_indicator="$battery_color$battery_indicator$colors_reset" + unset battery_string battery_percent tmp +} + parse_svn_status() { @@ -709,6 +764,12 @@ prompt_command_function() { parse_virtualenv_status parse_vcs_status + if [[ $battery_module = "on" ]]; then + create_battery_indicator + else + battery_indicator=":" + fi + # autojump if [[ ${aj_dir_list[aj_idx%aj_max]} != $PWD ]] ; then aj_dir_list[++aj_idx%aj_max]="$PWD" @@ -718,7 +779,7 @@ prompt_command_function() { # 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$prompt_char $colors_reset" + PS1="$colors_reset$rc$head_local$color_who_where$colors_reset$battery_indicator$dir_color$cwd$tail_local$dir_color$prompt_char $colors_reset" unset head_local tail_local pwd } From 054c5c7bb07ab041bce3571f69b3881d4c8c5e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 21 Sep 2013 22:55:46 +0200 Subject: [PATCH 005/118] -Add: make module --- git-prompt.conf | 3 +++ git-prompt.sh | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index ce86889..aec9ff7 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -21,6 +21,7 @@ # vim_module=on # virtualenv_module=on # battery_module=off +# make_module=off ########################################################### DEFAULT OBJECTS @@ -58,6 +59,8 @@ # virtualenv_color=green # user_id_color=blue # root_id_color=magenta + # make_color_ok=BLACK + # make_color_dirty=RED # else # B/W terminal # dir_color=bw_bold # rc_color=bw_bold diff --git a/git-prompt.sh b/git-prompt.sh index 34fa841..7a2ac69 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -5,6 +5,7 @@ ##### read config file if any. + unset make_color_ok make_color_dirty unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color unset modified_vcs_color added_vcs_color addmoded_vcs_color untracked_vcs_color op_vcs_color detached_vcs_color hex_vcs_color unset rawhex_len @@ -24,13 +25,18 @@ vim_module=${vim_module:-on} virtualenv_module=${virtualenv_module:-on} battery_module=${battery_module:-off} + make_module=${make_module:-off} error_bell=${error_bell:-off} cwd_cmd=${cwd_cmd:-\\w} - #### check for acpi, disable corresponding module if not installed + #### check for acpi, make disable corresponding module if not installed if [[ -z $(which acpi) && -z $(acpi -b) ]]; then battery_module=off fi + if [[ -z $(which make) ]]; then + make_module=off + fi + #### dir, rc, root color cols=`tput colors` # in emacs shell-mode tput colors returns -1 @@ -40,6 +46,8 @@ virtualenv_color=${virtualenv_color:-green} user_id_color=${user_id_color:-blue} root_id_color=${root_id_color:-magenta} + make_color_ok=${make_color_ok:-BLACK} + make_color_dirty=${make_color_dirty:-RED} else # only B/W dir_color=${dir_color:-bw_bold} rc_color=${rc_color:-bw_bold} @@ -403,6 +411,26 @@ create_battery_indicator () { unset battery_string battery_percent tmp } +check_make_status() { + + if [[ -e Makefile ]]; then + if [[ $utf8_prompt ]]; then + make_indicator="⚑" + else + make_indicator="*" + fi + make -q &> /dev/null + myrc=$? + if [[ $myrc -eq 0 ]]; then + make_indicator="${!make_color_ok}$make_indicator" + else + make_indicator="${!make_color_dirty}$make_indicator" + fi + unset myrc + else + make_indicator="" + fi +} parse_svn_status() { @@ -770,6 +798,12 @@ prompt_command_function() { battery_indicator=":" fi + if [[ $make_module = "on" ]]; then + check_make_status + else + make_indicator="" + fi + # autojump if [[ ${aj_dir_list[aj_idx%aj_max]} != $PWD ]] ; then aj_dir_list[++aj_idx%aj_max]="$PWD" @@ -779,7 +813,7 @@ prompt_command_function() { # else eval cwd_cmd, cwd should have path after exection eval "${cwd_cmd/\\/cwd=\\\\}" - PS1="$colors_reset$rc$head_local$color_who_where$colors_reset$battery_indicator$dir_color$cwd$tail_local$dir_color$prompt_char $colors_reset" + PS1="$colors_reset$rc$head_local$color_who_where$colors_reset$battery_indicator$dir_color$cwd$tail_local$make_indicator$dir_color$prompt_char $colors_reset" unset head_local tail_local pwd } From 5dadee4c8fe23ecb774bcb39a5c5674990232199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 21 Sep 2013 23:13:06 +0200 Subject: [PATCH 006/118] -Add: jobs module (background/stopped jobs) --- git-prompt.conf | 3 +++ git-prompt.sh | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index aec9ff7..05c16ce 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -22,6 +22,7 @@ # virtualenv_module=on # battery_module=off # make_module=off +# jobs_module=on ########################################################### DEFAULT OBJECTS @@ -61,6 +62,8 @@ # root_id_color=magenta # make_color_ok=BLACK # make_color_dirty=RED + # jobs_color_bkg=yellow + # jobs_color_stop=red # else # B/W terminal # dir_color=bw_bold # rc_color=bw_bold diff --git a/git-prompt.sh b/git-prompt.sh index 7a2ac69..79f9a91 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -5,7 +5,7 @@ ##### read config file if any. - unset make_color_ok make_color_dirty + unset make_color_ok make_color_dirty jobs_color_bkg jobs_color_stop unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color unset modified_vcs_color added_vcs_color addmoded_vcs_color untracked_vcs_color op_vcs_color detached_vcs_color hex_vcs_color unset rawhex_len @@ -26,10 +26,11 @@ virtualenv_module=${virtualenv_module:-on} battery_module=${battery_module:-off} make_module=${make_module:-off} + jobs_module=${jobs_module:-on} error_bell=${error_bell:-off} cwd_cmd=${cwd_cmd:-\\w} - #### check for acpi, make disable corresponding module if not installed + #### check for acpi, make, disable corresponding module if not installed if [[ -z $(which acpi) && -z $(acpi -b) ]]; then battery_module=off fi @@ -46,8 +47,11 @@ virtualenv_color=${virtualenv_color:-green} user_id_color=${user_id_color:-blue} root_id_color=${root_id_color:-magenta} + jobs_color_bkg=${jobs_color:-yellow} + jobs_color_stop=${jobs_color:-red} make_color_ok=${make_color_ok:-BLACK} make_color_dirty=${make_color_dirty:-RED} + else # only B/W dir_color=${dir_color:-bw_bold} rc_color=${rc_color:-bw_bold} @@ -411,6 +415,26 @@ create_battery_indicator () { unset battery_string battery_percent tmp } +create_jobs_indicator() { + # background jobs ⚒⚑⚐⚠ + jobs_bkg=$(jobs -r) + jobs_stop=$(jobs -s) + if [[ -n $jobs_bkg || -n $jobs_stop ]]; then + if [[ $utf8_prompt ]]; then + jobs_indicator="⚒" + else + jobs_indicator="%" + fi + if [[ -n $jobs_stop ]]; then + jobs_indicator="${!jobs_color_stop}$jobs_indicator" + else + jobs_indicator="${!jobs_color_bkg}$jobs_indicator" + fi + else + jobs_indicator="" + fi +} + check_make_status() { if [[ -e Makefile ]]; then @@ -804,6 +828,12 @@ prompt_command_function() { make_indicator="" fi + if [[ $jobs_module = "on" ]]; then + create_jobs_indicator + else + jobs_indicator="" + fi + # autojump if [[ ${aj_dir_list[aj_idx%aj_max]} != $PWD ]] ; then aj_dir_list[++aj_idx%aj_max]="$PWD" @@ -813,7 +843,7 @@ prompt_command_function() { # else eval cwd_cmd, cwd should have path after exection eval "${cwd_cmd/\\/cwd=\\\\}" - PS1="$colors_reset$rc$head_local$color_who_where$colors_reset$battery_indicator$dir_color$cwd$tail_local$make_indicator$dir_color$prompt_char $colors_reset" + PS1="$colors_reset$rc$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$tail_local$make_indicator$dir_color$prompt_char $colors_reset" unset head_local tail_local pwd } From a34699a10a03e751786b676b61328ba5990b15be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 21 Sep 2013 23:28:15 +0200 Subject: [PATCH 007/118] -Add: highlight slashes in path with different color --- git-prompt.conf | 1 + git-prompt.sh | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/git-prompt.conf b/git-prompt.conf index 05c16ce..bf3e1c1 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -56,6 +56,7 @@ # cols=`tput colors` # if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors # dir_color=CYAN + # slash_color=BLUE # rc_color=red # virtualenv_color=green # user_id_color=blue diff --git a/git-prompt.sh b/git-prompt.sh index 79f9a91..7750ed4 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -5,7 +5,7 @@ ##### read config file if any. - unset make_color_ok make_color_dirty jobs_color_bkg jobs_color_stop + unset make_color_ok make_color_dirty jobs_color_bkg jobs_color_stop slash_color unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color unset modified_vcs_color added_vcs_color addmoded_vcs_color untracked_vcs_color op_vcs_color detached_vcs_color hex_vcs_color unset rawhex_len @@ -43,6 +43,7 @@ cols=`tput colors` # in emacs shell-mode tput colors returns -1 if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors dir_color=${dir_color:-CYAN} + slash_color=${slash_color:-CYAN} rc_color=${rc_color:-red} virtualenv_color=${virtualenv_color:-green} user_id_color=${user_id_color:-blue} @@ -304,6 +305,7 @@ set_shell_label() { esac dir_color=${!dir_color} + slash_color=${!slash_color} rc_color=${!rc_color} virtualenv_color=${!virtualenv_color} user_id_color=${!user_id_color} @@ -843,6 +845,8 @@ prompt_command_function() { # else eval cwd_cmd, cwd should have path after exection eval "${cwd_cmd/\\/cwd=\\\\}" + cwd=${cwd//\//$slash_color\/$dir_color} + PS1="$colors_reset$rc$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$tail_local$make_indicator$dir_color$prompt_char $colors_reset" unset head_local tail_local pwd From dc731d6cdba6abac3463ad4a69bed4d12a460100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 21 Sep 2013 23:39:24 +0200 Subject: [PATCH 008/118] -Change: different color for '@' --- git-prompt.conf | 1 + git-prompt.sh | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index bf3e1c1..b76f8f6 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -65,6 +65,7 @@ # make_color_dirty=RED # jobs_color_bkg=yellow # jobs_color_stop=red + # at_color=green # else # B/W terminal # dir_color=bw_bold # rc_color=bw_bold diff --git a/git-prompt.sh b/git-prompt.sh index 7750ed4..413619c 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -5,7 +5,7 @@ ##### read config file if any. - unset make_color_ok make_color_dirty jobs_color_bkg jobs_color_stop slash_color + unset make_color_ok make_color_dirty jobs_color_bkg jobs_color_stop slash_color at_color unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color unset modified_vcs_color added_vcs_color addmoded_vcs_color untracked_vcs_color op_vcs_color detached_vcs_color hex_vcs_color unset rawhex_len @@ -48,6 +48,7 @@ virtualenv_color=${virtualenv_color:-green} user_id_color=${user_id_color:-blue} root_id_color=${root_id_color:-magenta} + at_color=${at_color:-green} jobs_color_bkg=${jobs_color:-yellow} jobs_color_stop=${jobs_color:-red} make_color_ok=${make_color_ok:-BLACK} @@ -342,6 +343,7 @@ set_shell_label() { host_color=${color_index[cksum_color_no]} fi + at_color=${!at_color} host_color=${!host_color} # we might already have short host name @@ -352,7 +354,7 @@ set_shell_label() { if [[ -n $id || -n $host ]] ; then [[ -n $id && -n $host ]] && at='@' || at='' - color_who_where="${id}${host:+$host_color$at$host}${tty:+ $tty}" + color_who_where="${id}${host:+$at_color$at$host_color$host}${tty:+ $tty}" plain_who_where="${id}$at$host" # add trailing " " From 5d6be0d1ebb8204cffee0d1955d86c7996b0772e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 21 Sep 2013 23:49:18 +0200 Subject: [PATCH 009/118] -Change: different color for prompt --- git-prompt.conf | 1 + git-prompt.sh | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/git-prompt.conf b/git-prompt.conf index b76f8f6..09fece8 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -57,6 +57,7 @@ # if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors # dir_color=CYAN # slash_color=BLUE + # prompt_color=white # rc_color=red # virtualenv_color=green # user_id_color=blue diff --git a/git-prompt.sh b/git-prompt.sh index 413619c..e3285c8 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -44,6 +44,7 @@ if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors dir_color=${dir_color:-CYAN} slash_color=${slash_color:-CYAN} + prompt_color=${prompt_color:-white} rc_color=${rc_color:-red} virtualenv_color=${virtualenv_color:-green} user_id_color=${user_id_color:-blue} @@ -307,6 +308,7 @@ set_shell_label() { dir_color=${!dir_color} slash_color=${!slash_color} + prompt_color=${!prompt_color} rc_color=${!rc_color} virtualenv_color=${!virtualenv_color} user_id_color=${!user_id_color} @@ -849,7 +851,7 @@ prompt_command_function() { cwd=${cwd//\//$slash_color\/$dir_color} - PS1="$colors_reset$rc$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$tail_local$make_indicator$dir_color$prompt_char $colors_reset" + PS1="$colors_reset$rc$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$tail_local$make_indicator$prompt_color$prompt_char $colors_reset" unset head_local tail_local pwd } From ac54b39e472add03cb65b82ccda82cdfc8d049a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 00:40:49 +0200 Subject: [PATCH 010/118] -Add: default user name and host suppression now configurable, can be abbreviated instead of deleted --- git-prompt.conf | 11 ++++++++++- git-prompt.sh | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index 09fece8..264481d 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -26,7 +26,16 @@ ########################################################### DEFAULT OBJECTS -### Default objects are not displayed. Example: +### Default user and hostname can be abbreviated or suppressed. +### Valid settings: +### * keep - display fully +### * abbrev - abbreviate to first character +### * delete - do not display at all + +# default_host_abbrev_mode=delete +# default_id_abbrev_mode=delete + +### Examples: ## default_user=lvv ## default_host="ahp" # remote host is always shown diff --git a/git-prompt.sh b/git-prompt.sh index e3285c8..a0ec2ce 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -30,6 +30,9 @@ error_bell=${error_bell:-off} cwd_cmd=${cwd_cmd:-\\w} + default_host_abbrev_mode=${default_host_abbrev_mode:-delete} + default_id_abbrev_mode=${default_id_abbrev_mode:-delete} + #### check for acpi, make, disable corresponding module if not installed if [[ -z $(which acpi) && -z $(acpi -b) ]]; then battery_module=off @@ -283,7 +286,21 @@ set_shell_label() { ###################################################### ID (user name) id=`id -un` - id=${id#$default_user} + + # abbreviate user name if needed + if [[ "$default_id_abbrev_mode" == "delete" ]] + then + id=${id#$default_user} + elif [[ "$default_id_abbrev_mode" == "abbrev" ]] + then + # only abbreviate if the abbreviated string is actually shorter than the full one + if [[ "$id" == "$default_user" && ${#id} -ge $((${#ellipse_marker} + 1)) ]] + then + id="${id:0:1}$ellipse" + fi + #else + # keep full user name + fi ########################################################### TTY tty=`tty` @@ -331,7 +348,7 @@ set_shell_label() { host=`hostname -s` fi fi - host=${host#$default_host} + uphost=`echo ${host} | tr a-z-. A-Z_` if [[ $upcase_hostname = "on" ]]; then host=${uphost} @@ -345,6 +362,21 @@ set_shell_label() { host_color=${color_index[cksum_color_no]} fi + # abbreviate host name if needed + if [[ "$default_host_abbrev_mode" == "delete" ]] + then + host=${host#$default_host} + elif [[ "$default_host_abbrev_mode" == "abbrev" ]] + then + # only abbreviate if the abbreviated string is actually shorter than the full one + if [[ "$host" == "$default_host" && ${#host} -ge $((${#ellipse_marker} + 1)) ]] + then + host="${host:0:1}$ellipse" + fi + #else + # keep full host name + fi + at_color=${!at_color} host_color=${!host_color} @@ -368,6 +400,7 @@ set_shell_label() { user_id_color=$root_id_color prompt_char="$root_prompt_char" fi + color_who_where="$user_id_color$color_who_where$colors_reset" else color_who_where='' From 1bcaacdefd5c91d18eefbe08d314ae1042a4366a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 00:53:45 +0200 Subject: [PATCH 011/118] -Fix: upcase host name only if it's not abbreviated --- git-prompt.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index a0ec2ce..b153c23 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -350,9 +350,6 @@ set_shell_label() { fi uphost=`echo ${host} | tr a-z-. A-Z_` - if [[ $upcase_hostname = "on" ]]; then - host=${uphost} - fi host_color=${uphost}_host_color host_color=${!host_color} @@ -373,8 +370,11 @@ set_shell_label() { then host="${host:0:1}$ellipse" fi - #else - # keep full host name + else + # set upcase hostname if needed + if [[ $upcase_hostname = "on" ]]; then + host=${uphost} + fi fi at_color=${!at_color} From d2b934aa1dbe627f5d95d77fdd706ccf44916b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 00:56:52 +0200 Subject: [PATCH 012/118] -Fix: typo in variable name --- git-prompt.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index b153c23..628496f 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -296,7 +296,7 @@ set_shell_label() { # only abbreviate if the abbreviated string is actually shorter than the full one if [[ "$id" == "$default_user" && ${#id} -ge $((${#ellipse_marker} + 1)) ]] then - id="${id:0:1}$ellipse" + id="${id:0:1}$ellipse_marker" fi #else # keep full user name @@ -368,7 +368,7 @@ set_shell_label() { # only abbreviate if the abbreviated string is actually shorter than the full one if [[ "$host" == "$default_host" && ${#host} -ge $((${#ellipse_marker} + 1)) ]] then - host="${host:0:1}$ellipse" + host="${host:0:1}$ellipse_marker" fi else # set upcase hostname if needed From f41a4ef1edc9aa8afe9727441865e939ccfe2e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 10:48:16 +0200 Subject: [PATCH 013/118] -Fix: force git status to print English messages --- git-prompt.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 628496f..11e5845 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -590,7 +590,7 @@ parse_git_status() { # info not in porcelain status eval " $( - git status 2>/dev/null | + LANG=C git status 2>/dev/null | sed -n ' s/^# On branch /branch=/p s/^nothing to commi.*/clean=clean/p @@ -613,7 +613,7 @@ parse_git_status() { # A "with space" <------------- WITH QOUTES eval " $( - git status --porcelain 2>/dev/null | + LANG=C git status --porcelain 2>/dev/null | sed -n ' s,^[MARC]. \([^\"][^/]*/\?\).*, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p s,^[MARC]. \"\([^/]\+/\?\).*\"$, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p From ee4c52d26c5b40d2c0b176c9abe8da22937d348f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 10:56:56 +0200 Subject: [PATCH 014/118] -Fix: backslash in id needs to be escaped if colorized --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 11e5845..e3dc91d 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -388,7 +388,7 @@ set_shell_label() { if [[ -n $id || -n $host ]] ; then [[ -n $id && -n $host ]] && at='@' || at='' - color_who_where="${id}${host:+$at_color$at$host_color$host}${tty:+ $tty}" + color_who_where="${id//\\/\\\\}${host:+$at_color$at$host_color$host}${tty:+ $tty}" plain_who_where="${id}$at$host" # add trailing " " From f696b8fa35eb884a454b0b470a5fcdc5574906b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 11:19:04 +0200 Subject: [PATCH 015/118] -Fix: rc module can be switched off --- git-prompt.conf | 1 + git-prompt.sh | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/git-prompt.conf b/git-prompt.conf index 264481d..deda828 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -23,6 +23,7 @@ # battery_module=off # make_module=off # jobs_module=on +# rc_module=on ########################################################### DEFAULT OBJECTS diff --git a/git-prompt.sh b/git-prompt.sh index e3dc91d..15ccb02 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -27,6 +27,7 @@ battery_module=${battery_module:-off} make_module=${make_module:-off} jobs_module=${jobs_module:-on} + rc_module=${rc_module:-on} error_bell=${error_bell:-off} cwd_cmd=${cwd_cmd:-\\w} @@ -843,7 +844,7 @@ alias jumpstart='echo ${aj_dir_list[@]}' prompt_command_function() { rc="$?" - if [[ "$rc" == "0" ]]; then + if [[ "$rc_module" != "on" || "$rc" == "0" ]]; then rc="" else rc="$rc_color$rc$colors_reset$bell " From 1e0c8ce5355c8d7a33354698e03424a12ecd531f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 11:33:56 +0200 Subject: [PATCH 016/118] -Fix: suppress printing of error code after the first time --- git-prompt.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 15ccb02..e4c5e75 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -842,13 +842,14 @@ alias jumpstart='echo ${aj_dir_list[@]}' ###################################################################### PROMPT_COMMAND prompt_command_function() { - rc="$?" + raw_rc="$?" - if [[ "$rc_module" != "on" || "$rc" == "0" ]]; then + if [[ "$rc_module" != "on" || "$raw_rc" == "0" || "$previous_rc" == "$raw_rc" ]]; then rc="" else - rc="$rc_color$rc$colors_reset$bell " + rc="$rc_color$raw_rc$colors_reset$bell " fi + previous_rc="$raw_rc" cwd=${PWD/$HOME/\~} # substitute "~" set_shell_label "${cwd##[/~]*/}/" # default label - path last dir @@ -887,7 +888,7 @@ prompt_command_function() { PS1="$colors_reset$rc$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$tail_local$make_indicator$prompt_color$prompt_char $colors_reset" - unset head_local tail_local pwd + unset head_local tail_local pwd raw_rc } PROMPT_COMMAND=prompt_command_function From 181e5d23e49b00ed2bf95e1d946adce846706d14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 11:39:34 +0200 Subject: [PATCH 017/118] -Add: option to disable make status check for a list of directories --- git-prompt.conf | 4 ++++ git-prompt.sh | 2 ++ 2 files changed, 6 insertions(+) diff --git a/git-prompt.conf b/git-prompt.conf index deda828..646acf5 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -59,6 +59,10 @@ # they are always dirty (ex: home, /etc) or directory with huge repo (ex: linux src) ## vcs_ignore_dir_list=" /etc $HOME /usr/src/linux.git " +# Do not check make status for listed directories +# useful for large projects where make -q would take several seconds +## make_ignore_dir_list=" /etc $HOME /usr/src/linux.git " + ########################################################### COLOR ### directory, exit code, root color diff --git a/git-prompt.sh b/git-prompt.sh index e4c5e75..d747611 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -477,6 +477,8 @@ create_jobs_indicator() { check_make_status() { + [[ $make_ignore_dir_list =~ $PWD ]] && return + if [[ -e Makefile ]]; then if [[ $utf8_prompt ]]; then make_indicator="⚑" From 7e4b04167afc62f04824b7f6a38fa6954e6c6098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 12:19:52 +0200 Subject: [PATCH 018/118] -Remove: tail_local (unused variable) --- git-prompt.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index d747611..0a8de58 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -790,8 +790,6 @@ parse_vcs_status() { ### fringes head_local="${head_local+$vcs_color$head_local }" - #above_local="${head_local+$vcs_color$head_local\n}" - #tail_local="${tail_local+$vcs_color $tail_local}${dir_color}" } parse_virtualenv_status() { @@ -888,9 +886,9 @@ prompt_command_function() { cwd=${cwd//\//$slash_color\/$dir_color} - PS1="$colors_reset$rc$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$tail_local$make_indicator$prompt_color$prompt_char $colors_reset" + PS1="$colors_reset$rc$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$make_indicator$prompt_color$prompt_char $colors_reset" - unset head_local tail_local pwd raw_rc + unset head_local pwd raw_rc } PROMPT_COMMAND=prompt_command_function From 4ed392a3acab28bfa10361d471e34662afa84899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 12:20:48 +0200 Subject: [PATCH 019/118] -Fix: use == in tests --- git-prompt.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 0a8de58..43132ff 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -857,19 +857,19 @@ prompt_command_function() { parse_virtualenv_status parse_vcs_status - if [[ $battery_module = "on" ]]; then + if [[ $battery_module == "on" ]]; then create_battery_indicator else battery_indicator=":" fi - if [[ $make_module = "on" ]]; then + if [[ $make_module == "on" ]]; then check_make_status else make_indicator="" fi - if [[ $jobs_module = "on" ]]; then + if [[ $jobs_module == "on" ]]; then create_jobs_indicator else jobs_indicator="" From 51f5b0c7b2b443fe65ff5b309d4075586ee72d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 12:28:18 +0200 Subject: [PATCH 020/118] -Fix: virtualenv uses its own string instead of abusing rc --- git-prompt.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 43132ff..4aae592 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -798,8 +798,10 @@ parse_virtualenv_status() { [[ $virtualenv_module = "on" ]] || return 1 if [[ -n "$VIRTUAL_ENV" ]] ; then - virtualenv=`basename $VIRTUAL_ENV` - rc="$rc $virtualenv_color<$virtualenv> " + virtualenv=`basename $VIRTUAL_ENV` + virtualenv_string=" $virtualenv_color<$virtualenv> " + else + virtualenv_string="" fi } @@ -886,7 +888,7 @@ prompt_command_function() { cwd=${cwd//\//$slash_color\/$dir_color} - PS1="$colors_reset$rc$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$make_indicator$prompt_color$prompt_char $colors_reset" + PS1="$colors_reset$rc$virtualenv_string$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$make_indicator$prompt_color$prompt_char $colors_reset" unset head_local pwd raw_rc } From 957ece27237e004d37e62cc83fb9f0c6cae13edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 15:47:05 +0200 Subject: [PATCH 021/118] -Change: remove explicit spaces from module outputs; order of modules can be configured --- git-prompt.conf | 2 ++ git-prompt.sh | 48 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index 646acf5..0927dbe 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -25,6 +25,8 @@ # jobs_module=on # rc_module=on +### Order of modules +# prompt_modules_order="RC VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE PROMPT" ########################################################### DEFAULT OBJECTS ### Default user and hostname can be abbreviated or suppressed. diff --git a/git-prompt.sh b/git-prompt.sh index 4aae592..5ffd7ee 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -34,6 +34,8 @@ default_host_abbrev_mode=${default_host_abbrev_mode:-delete} default_id_abbrev_mode=${default_id_abbrev_mode:-delete} + prompt_modules_order=${prompt_modules_order:-RC VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE PROMPT} + #### check for acpi, make, disable corresponding module if not installed if [[ -z $(which acpi) && -z $(acpi -b) ]]; then battery_module=off @@ -168,6 +170,31 @@ unset PROMPT_COMMAND + # assemble prompt command string based on the module order specified above + + # RC, VIRTUALENV and VCS has to be flanked by spaces on either side + # except if they are at the start or end of the sequence. + # excess spaces (which may occur if some of the modules produce empty output) + # will be trimmed at runtime, in the prompt_command_function. + + prompt_command_string=$(echo $prompt_modules_order | + sed ' + s/RC/\$space\$rc\$space/; + s/VIRTUALENV/\$space\$virtualenv_string\$space/; + s/VCS/\$space\$head_local\$space/; + s/WHO_WHERE/\$color_who_where\$colors_reset/; + s/JOBS/\$jobs_indicator/; + s/BATTERY/\$battery_indicator/; + s/CWD/\$dir_color\$cwd/; + s/MAKE/\$make_indicator/; + s/PROMPT/\$prompt_color\$prompt_char/; + s/ //g; + s/\$space\$space/\$space/g; + s/^\$space//; + s/\$space$//; + s/\$space/ /g; + ') + ####### 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 @@ -392,10 +419,6 @@ set_shell_label() { color_who_where="${id//\\/\\\\}${host:+$at_color$at$host_color$host}${tty:+ $tty}" plain_who_where="${id}$at$host" - # add trailing " " - color_who_where="$color_who_where " - plain_who_where="$plain_who_where " - # if root then make it root_color if [ "$id" == "root" ] ; then user_id_color=$root_id_color @@ -789,7 +812,7 @@ parse_vcs_status() { head_local="$vcs_color(${vcs_info}$vcs_color${file_list}$vcs_color)" ### fringes - head_local="${head_local+$vcs_color$head_local }" + #head_local="${head_local+$vcs_color$head_local }" } parse_virtualenv_status() { @@ -799,7 +822,7 @@ parse_virtualenv_status() { if [[ -n "$VIRTUAL_ENV" ]] ; then virtualenv=`basename $VIRTUAL_ENV` - virtualenv_string=" $virtualenv_color<$virtualenv> " + virtualenv_string="$virtualenv_color<$virtualenv>" else virtualenv_string="" fi @@ -849,7 +872,7 @@ prompt_command_function() { if [[ "$rc_module" != "on" || "$raw_rc" == "0" || "$previous_rc" == "$raw_rc" ]]; then rc="" else - rc="$rc_color$raw_rc$colors_reset$bell " + rc="$rc_color$raw_rc$colors_reset$bell" fi previous_rc="$raw_rc" @@ -888,9 +911,16 @@ prompt_command_function() { cwd=${cwd//\//$slash_color\/$dir_color} - PS1="$colors_reset$rc$virtualenv_string$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$make_indicator$prompt_color$prompt_char $colors_reset" + # in effect, echo collapses spaces inside the string and removes them from the start/end + local prompt_command_string_l + prompt_command_string_l=$(eval echo $prompt_command_string) + prompt_command_string_l="PS1=\"\$colors_reset$prompt_command_string_l \$colors_reset\"" + eval $prompt_command_string_l + + # old static string with default order left here for reference + ###PS1="$colors_reset$rc$virtualenv_string$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$make_indicator$prompt_color$prompt_char $colors_reset" - unset head_local pwd raw_rc + unset head_local pwd raw_rc space } PROMPT_COMMAND=prompt_command_function From f8fbed414acc37b5f944a1acbf2bc429f7b2881c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 16:46:06 +0200 Subject: [PATCH 022/118] -Add: display revision for hg --- git-prompt.conf | 7 +++++++ git-prompt.sh | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/git-prompt.conf b/git-prompt.conf index 0927dbe..3a947b6 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -65,6 +65,13 @@ # useful for large projects where make -q would take several seconds ## make_ignore_dir_list=" /etc $HOME /usr/src/linux.git " +### Display revision number for Mercurial repositories +### valid options: +### * num - display local revision number +### * id - display global revision id (hex string, truncated to rawhex_len characters +### * none - do not display at all +# hg_revision_display=none + ########################################################### COLOR ### directory, exit code, root color diff --git a/git-prompt.sh b/git-prompt.sh index 5ffd7ee..240cf7a 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -89,6 +89,8 @@ upcase_hostname=${upcase_hostname:-on} count_only=${count_only:-off} rawhex_len=${rawhex_len:-5} + hg_revision_display=${hg_revision_display:-none} + aj_max=20 @@ -575,10 +577,31 @@ parse_hg_status() { [[ -f $hg_root/.hg/bookmarks.current ]] && bookmark=`cat "$hg_root/.hg/bookmarks.current"` [[ -z $modified ]] && [[ -z $untracked ]] && [[ -z $added ]] && clean=clean + vcs_info=${branch/default/D} if [[ "$bookmark" ]] ; then vcs_info+=/$bookmark fi + + local hg_vcs_char + if [[ $utf8_prompt ]]; then + hg_vcs_char="☿" + else + hg_vcs_char=":" + fi + + local hg_revision + case $hg_revision_display in + id) hg_revision=$(hg id -i) + hg_revision="$hex_vcs_color$hg_vcs_char${hg_revision:0:$rawhex_len}" + ;; + num) hg_revision=$(hg id -n) + hg_revision="$hex_vcs_color$hg_vcs_char$hg_revision" + ;; + *) hg_revision="" ;; + esac + + vcs_info+=$hg_revision } From 8c203b9d77609cfdf85b3ac6f2346888e6056b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 16:50:32 +0200 Subject: [PATCH 023/118] -Add: note about svn module being broken --- git-prompt.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/git-prompt.sh b/git-prompt.sh index 240cf7a..0ca09ab 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -524,6 +524,11 @@ check_make_status() { } parse_svn_status() { + # FIXME: SVN >= 1.7 uses a single .svn dir in the repository toplevel dir (like hg or git) + # instead of a .svn in each tracked dir, so the method below will not work! + # Unfortunately there is no easy fix, because svn doesn't have the equivalent of "hg root" + # or "git rev-parse", not to mention that it's possible to just check out a subdirectory of a repo, + # and different levels of a directory tree can belong to different checkouts. [[ -d .svn ]] || return 1 From 888c6b0777aa336cd93088613224a3d962656b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 16:52:35 +0200 Subject: [PATCH 024/118] -Add: config file with personal favorite options --- git-prompt.conf.mine | 131 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 git-prompt.conf.mine diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine new file mode 100644 index 0000000..12bb2d0 --- /dev/null +++ b/git-prompt.conf.mine @@ -0,0 +1,131 @@ + +### GIT-PROMPT.SH CONFIG +### +### lines commented-out with single '#' are default values +### lines commented-out with double '##' are examples +### +### NOTE: this is bash syntax - no spaces around "=" + +########################################################### + +# error_bell=off # sound terminal bell when command return code is not zero. (use setterm to set pitch and duration) +max_file_list_length=30 # in characters +count_only=on # off - display file list; on - display file count +# rawhex_len=5 # length of git rawhex revision id display (use 0 to hide it) + +############################################################ MODULES + +# git_module=on +# svn_module=off +# hg_module=on +vim_module=off +virtualenv_module=off +battery_module=on +make_module=on +# jobs_module=on +rc_module=on + +### order of modules +prompt_modules_order="RC VIRTUALENV WHO_WHERE JOBS BATTERY CWD VCS MAKE PROMPT" + +########################################################### DEFAULT OBJECTS +### Default user and hostname can be abbreviated or suppressed. +### Valid settings: +### * keep - display fully +### * abbrev - abbreviate to first character +### * delete - do not display at all + +default_host_abbrev_mode=abbrev +default_id_abbrev_mode=abbrev + +### Examples: + +default_user=kikuchiyo +default_host=aryabhata # remote host is always shown +## default_domain="lvvnet" + +########################################################### Current Working Dir display +# cwd_cmd='\w' # display full path +## cwd_cmd='\W' # display only last dir of path +cwd_cmd='cwd_truncate $(($COLUMNS/4))' # display only last N chars of path + +########################################################### ETC + +# Some don't like hostname in uppercase +# upcase_hostname=on # =off +# Some don't like long hostname +# short_hostname=off # =on + +# Do not do VCS parsing for listed directories +# useful for directories for which it is difficult to maintain .gitignore so +# they are always dirty (ex: home, /etc) or directory with huge repo (ex: linux src) +## vcs_ignore_dir_list=" /etc $HOME /usr/src/linux.git " + +# Do not check make status for listed directories +# useful for large projects where make -q would take several seconds +make_ignore_dir_list=" /etc $HOME /usr/src/linux.git " + +### Display revision number for Mercurial repositories +### valid options: +### * num - display local revision number +### * id - display global revision id (hex string, truncated to rawhex_len characters +### * none - do not display at all +hg_revision_display=num + +########################################################### COLOR + +### directory, exit code, root color + +# cols=`tput colors` +# if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors + dir_color=BLUE + slash_color=CYAN + prompt_color=colors_reset + rc_color=red + virtualenv_color=green + user_id_color=GREEN + root_id_color=magenta + make_color_ok=BLACK + make_color_dirty=RED + jobs_color_bkg=yellow + jobs_color_stop=red + at_color=green + +# else # B/W terminal + # dir_color=bw_bold + # rc_color=bw_bold +# fi + +### prompt character for root/non-root, default '>' for both +# prompt_char='>' +# root_prompt_char='>' + prompt_char='$' +## prompt_char='➔' + root_prompt_char='#' + +##### Per host color + +### Per host color. If not set, color will be derived from hostname checksum). +### Variable name is uppercase-short-hostname with appended "_host_color" +### Example per-host-color config: + +## TASHA_host_color=cyan +## AL_host_color=green +## AHP_host_color=white + ARYABHATA_host_color=green + PALATABLA_host_color=cyan + +##### VCS (version control system) state colors + +# init_vcs_color=WHITE # initial +# clean_vcs_color=blue # nothing to commit (working directory clean) +# modified_vcs_color=red # Changed but not updated: +# added_vcs_color=green # Changes to be committed: +# mixed_vcs_color=yellow # +# untracked_vcs_color=BLUE # Untracked files: +# op_vcs_color=MAGENTA +# detached_vcs_color=RED +# hex_vcs_color=white # git revision id: bright black (makes gray) + + +# :vim:ft=sh ts=8 sw=8 et: From 8ce4a25d799d527813772d03b3e3b85b6fef0d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 17:04:14 +0200 Subject: [PATCH 025/118] -Fix: some cleanup, use local variables in functions --- git-prompt.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 0ca09ab..60a1ab8 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -438,6 +438,11 @@ create_battery_indicator () { # if laptop on AC, charging: ▕⚡▏ # if laptop on battery: one of ▕▁▏▕▂▏▕▃▏▕▄▏▕▅▏▕▆▏▕▇▏▕█▏ # color: red if power < 30 %, else normal + + local battery_string + local battery_percent + local battery_color + local tmp battery_string=$(acpi -b) if [[ $battery_string ]]; then @@ -477,13 +482,12 @@ create_battery_indicator () { battery_color=$colors_reset fi battery_indicator="$battery_color$battery_indicator$colors_reset" - unset battery_string battery_percent tmp } create_jobs_indicator() { # background jobs ⚒⚑⚐⚠ - jobs_bkg=$(jobs -r) - jobs_stop=$(jobs -s) + local jobs_bkg=$(jobs -r) + local jobs_stop=$(jobs -s) if [[ -n $jobs_bkg || -n $jobs_stop ]]; then if [[ $utf8_prompt ]]; then jobs_indicator="⚒" @@ -504,6 +508,7 @@ check_make_status() { [[ $make_ignore_dir_list =~ $PWD ]] && return + local myrc if [[ -e Makefile ]]; then if [[ $utf8_prompt ]]; then make_indicator="⚑" @@ -517,7 +522,6 @@ check_make_status() { else make_indicator="${!make_color_dirty}$make_indicator" fi - unset myrc else make_indicator="" fi @@ -948,7 +952,7 @@ prompt_command_function() { # old static string with default order left here for reference ###PS1="$colors_reset$rc$virtualenv_string$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$make_indicator$prompt_color$prompt_char $colors_reset" - unset head_local pwd raw_rc space + unset head_local raw_rc } PROMPT_COMMAND=prompt_command_function From 19f98bef26e3efbd78746f3f6f9a7829a59897c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 17:11:29 +0200 Subject: [PATCH 026/118] -Fix: return empty make indicator if directory was in ignore list --- git-prompt.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/git-prompt.sh b/git-prompt.sh index 60a1ab8..ea9fdd0 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -506,6 +506,7 @@ create_jobs_indicator() { check_make_status() { + make_indicator="" [[ $make_ignore_dir_list =~ $PWD ]] && return local myrc From ad7b930d57e010530ec4c050333ec8ba3d619f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 22 Sep 2013 18:25:15 +0200 Subject: [PATCH 027/118] -Fix: better UTF-8 detection --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index ea9fdd0..f9b95e0 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -206,7 +206,7 @@ fi #################################################################### MARKERS - if [[ ("$LC_CTYPE $LC_ALL" =~ "UTF" || $LANG =~ "utf") && $TERM != "linux" ]]; then + if [[ ("$LC_CTYPE $LC_ALL $LANG" =~ "UTF" || $LANG =~ "utf") && $TERM != "linux" ]]; then utf8_prompt=1 ellipse_marker="…" else From 653e4fb80205bd99dd015cdfee29a5c52057d55d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Mon, 23 Sep 2013 14:41:58 +0200 Subject: [PATCH 028/118] -Fix: remove PROMPT from reorderable config, this eliminates an unwanted space --- git-prompt.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index f9b95e0..ad8390d 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -34,7 +34,7 @@ default_host_abbrev_mode=${default_host_abbrev_mode:-delete} default_id_abbrev_mode=${default_id_abbrev_mode:-delete} - prompt_modules_order=${prompt_modules_order:-RC VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE PROMPT} + prompt_modules_order=${prompt_modules_order:-RC VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE} #### check for acpi, make, disable corresponding module if not installed if [[ -z $(which acpi) && -z $(acpi -b) ]]; then @@ -189,7 +189,6 @@ s/BATTERY/\$battery_indicator/; s/CWD/\$dir_color\$cwd/; s/MAKE/\$make_indicator/; - s/PROMPT/\$prompt_color\$prompt_char/; s/ //g; s/\$space\$space/\$space/g; s/^\$space//; @@ -947,7 +946,7 @@ prompt_command_function() { # in effect, echo collapses spaces inside the string and removes them from the start/end local prompt_command_string_l prompt_command_string_l=$(eval echo $prompt_command_string) - prompt_command_string_l="PS1=\"\$colors_reset$prompt_command_string_l \$colors_reset\"" + prompt_command_string_l="PS1=\"\$colors_reset$prompt_command_string_l$prompt_color$prompt_char \$colors_reset\"" eval $prompt_command_string_l # old static string with default order left here for reference From 1d011f16b42d13715a47ab28ab5523170a8ba75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Mon, 23 Sep 2013 14:58:50 +0200 Subject: [PATCH 029/118] -Update: docs with new features --- index.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.txt b/index.txt index a48ab80..868aedd 100644 --- a/index.txt +++ b/index.txt @@ -47,6 +47,12 @@ GIT. Enable if needed in <> == Mercurial/HG HG module was developed by Lee Nussbaum ``. +== Additional features + +* Battery status (for laptops) +* Background jobs indicator +* Makefile status check +* Order of prompt elements can be changed == Labels From 02e4aa6af19d8b0113c8fd260aa6a590b81e5c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Mon, 23 Sep 2013 15:11:56 +0200 Subject: [PATCH 030/118] -Update: docs language cleanup, added new dependencies and author note --- index.txt | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/index.txt b/index.txt index 868aedd..918d3a7 100644 --- a/index.txt +++ b/index.txt @@ -13,8 +13,8 @@ image:screenshot-prompt-basic.png[basic usage] -Digit [red]*1* on 3rd line is `false(1)` exit code. Also on non-zero exit code -terminal bell is sounded. Bell is turned off by default (to set softer +Digit [red]*1* on the 3rd line is a `false(1)` exit code. Also on a non-zero exit code +the terminal bell is sounded. The bell is turned off by default (to set softer terminal bell use `setterm`). @@ -40,8 +40,8 @@ image:screenshot-prompt-git.png[git module screenshot] == Subversion/SVN image:screenshot-svn.png[svn module screenshot] -SVN module disabled by default because even on moderate sized working -directories there is noticeable delay for prompt display. SVN is slower than +SVN module is disabled by default because even on moderate sized working +directories there is a noticeable delay for prompt display. SVN is slower than GIT. Enable if needed in <> == Mercurial/HG @@ -57,16 +57,16 @@ HG module was developed by Lee Nussbaum ``. == Labels Labels are visual cues to help figure out what terminal is running what command. -It is generalization of xterm-title but differ from xterm-title that it +It is a generalization of xterm-title but it differ from xterm-title in that it can be displayed in other places (on Screen(1) windows titles for example). -Also label can display currently executed command (when bash prompt obviously -is not displayed). Because labels have less space then prompt, instead of full path -only last dir is shown. -On screenshot below labels are in red ovals. +Additionally, the label can display currently executed command (when bash prompt obviously +is not displayed). Because such labels have less space than the prompt, instead of the full path +only the bottommost directory is shown. +On screenshot below the labels are highlighted with red ovals. image:screenshot-labels.png["labels screenshot", width="300", link="screenshot-labels.png"] -The `screen(1)` status line at bottom of smaller gnome-terminal is displayed with +The `screen(1)` status line at the bottom of the smaller gnome-terminal is displayed with following line in `~/.screenrc`: --------- @@ -76,11 +76,11 @@ caption always "%{= kw}%-w%{= bw}%n %t%{-}%+w %-= @%H - %LD %d %LM - %c" == Simple AutoJump -AutoJump is python script from Joel Schaerer providing shortcuts for jumping -to directories you once visited. Git-prompt have built-in, simplified +AutoJump is a python script from Joel Schaerer providing shortcuts for jumping +to directories you once visited. Git-prompt has a built-in, simplified version of autojump. It is only about 10 lines of bash code (vs original 100+ python -LOC), there is no database. It remembers only directories from current -session. It selects not most frequent dir, but last visited. Matches are done +LOC), there is no database. It remembers only directories from the current +session. It selects not the most frequent dir, but the last visited. Matches are done from beginning of of dir name (not path name). ----------------- @@ -103,7 +103,7 @@ Download link:git-prompt.sh[] or get it with GIT: git clone git://github.com/lvv/git-prompt.git --------------- -Put following command at the end of your profile (`~/.bash_profile` or `~/.profile`) +Put the following command at the end of your profile (`~/.bash_profile` or `~/.profile`) -------------------- [[ $- == *i* ]] && . /path/to/git-prompt.sh @@ -129,15 +129,15 @@ git config [--global] --unset i18n.logoutputencoding == GIT-PROMPT config [[config]] -Is optional. If config file is not found then git-prompt uses defaults. +Optional. If no config file is found then git-prompt uses defaults. Defaults are listed in example `git-prompt.conf`. Git-prompt looks (in listed order) -for config file in following locations: +for the config file in the following locations: * `/etc/git-prompt.conf` * `~/.git-prompt.conf` Copy example config `git-prompt.conf` -to any of above locations and customize as needed. +to any of the above locations and customize as needed. == Limitations @@ -145,6 +145,9 @@ to any of above locations and customize as needed. * cd-ing into something like linux kernel git working directory for the 1st time (with cold cache) might take up to 10 seconds (that is how long `git status` executes). Use `vcs_ignore_dir_list` in config if you want to ingnore such dirs. +* Similarly, the make module may induce a noticeable delay in directories with a large and + complex Makefile (because it has to run `make -q' to figure out its build status). + Use `make_ignore_dir_list` in config to ingnore such dirs. * Because you will be always reminded about dirty repo (not checked-in files), you will maintain `.gitignore` and commit more often. * This prompt is most useful if your screen have enough width. @@ -171,11 +174,14 @@ dependencies are standard unix utils. * locale (glibc) * id (core utils) * cksum (core utils) +* awk * git (optional) * svn (optional) * hg (optional) +* make (optional) +* acpi (optional, for battery module) == Todo @@ -206,7 +212,7 @@ time consuming ops in postconfig which is executed only once. - Dan Bravender - Thomas Geffert - Tibor Simko - +- Peter Juhasz httpx://github.com/pjuhasz[] [bibliography] .References From f5caae82baf58f4bca2ec4d78fe465b623bf474a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 28 Sep 2013 14:14:15 +0200 Subject: [PATCH 031/118] -Fix: TERM in case of screen may be screen-256colors, take that into account --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index ad8390d..34891f3 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -336,7 +336,7 @@ set_shell_label() { tty=`echo $tty | sed "s:/dev/pts/:p:; s:/dev/tty::" ` # RH tty devs tty=`echo $tty | sed "s:/dev/vc/:vc:" ` # gentoo tty devs - if [[ "$TERM" = "screen" ]] ; then + if [[ "$TERM" =~ "screen" ]] ; then # [ "$WINDOW" = "" ] && WINDOW="?" # From fd5a61f04883fdca9fd4c2e723f741b98a7bf912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 28 Sep 2013 17:20:19 +0200 Subject: [PATCH 032/118] -Fix: remove PROMPT from order string in personal conf --- git-prompt.conf.mine | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine index 12bb2d0..f2d6e67 100644 --- a/git-prompt.conf.mine +++ b/git-prompt.conf.mine @@ -26,7 +26,7 @@ make_module=on rc_module=on ### order of modules -prompt_modules_order="RC VIRTUALENV WHO_WHERE JOBS BATTERY CWD VCS MAKE PROMPT" +prompt_modules_order="RC VIRTUALENV WHO_WHERE JOBS BATTERY CWD VCS MAKE" ########################################################### DEFAULT OBJECTS ### Default user and hostname can be abbreviated or suppressed. From 587b9b904f35cd712af00c0553d8dd35dd7a0c4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 28 Sep 2013 17:38:55 +0200 Subject: [PATCH 033/118] -Fix: correct logical operator in test for acpi presence and output --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 34891f3..1ffacac 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -37,7 +37,7 @@ prompt_modules_order=${prompt_modules_order:-RC VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE} #### check for acpi, make, disable corresponding module if not installed - if [[ -z $(which acpi) && -z $(acpi -b) ]]; then + if [[ -z $(which acpi) || -z $(acpi -b) ]]; then battery_module=off fi if [[ -z $(which make) ]]; then From d23b4f0dc908c60bc766fd2a66cbb008b59c4940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 28 Sep 2013 18:09:18 +0200 Subject: [PATCH 034/118] -Add: detection of remote session via SSH[2]_CLIENT --- git-prompt.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 1ffacac..8da99ae 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -368,6 +368,12 @@ set_shell_label() { ## is sshd our parent? # if { for ((pid=$$; $pid != 1 ; pid=`ps h -o pid --ppid $pid`)); do ps h -o command -p $pid; done | grep -q sshd && echo == REMOTE ==; } #then + + if [[ -n ${SSH_CLIENT} || -n ${SSH2_CLIENT} ]]; then + probably_ssh_session=1 + else + probably_ssh_session= + fi host=${HOSTNAME} if [[ $short_hostname = "on" ]]; then @@ -389,10 +395,11 @@ set_shell_label() { fi # abbreviate host name if needed - if [[ "$default_host_abbrev_mode" == "delete" ]] + # disregard setting and display full host if session is remote + if [[ "$default_host_abbrev_mode" == "delete" && !$probably_ssh_session ]] then host=${host#$default_host} - elif [[ "$default_host_abbrev_mode" == "abbrev" ]] + elif [[ "$default_host_abbrev_mode" == "abbrev" && !$probably_ssh_session ]] then # only abbreviate if the abbreviated string is actually shorter than the full one if [[ "$host" == "$default_host" && ${#host} -ge $((${#ellipse_marker} + 1)) ]] @@ -412,6 +419,8 @@ set_shell_label() { # we might already have short host name host=${host%.$default_domain} + unset probably_ssh_session + #################################################################### WHO_WHERE # [[user@]host[-tty]] From bc64e9c1614abb6343290f5e25fa68300f5fc626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 28 Sep 2013 19:02:41 +0200 Subject: [PATCH 035/118] -Fix: remote session abbrev condition --- git-prompt.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 8da99ae..7ee1f29 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -370,7 +370,7 @@ set_shell_label() { #then if [[ -n ${SSH_CLIENT} || -n ${SSH2_CLIENT} ]]; then - probably_ssh_session=1 + probably_ssh_session=1 else probably_ssh_session= fi @@ -396,10 +396,10 @@ set_shell_label() { # abbreviate host name if needed # disregard setting and display full host if session is remote - if [[ "$default_host_abbrev_mode" == "delete" && !$probably_ssh_session ]] + if [[ "$default_host_abbrev_mode" == "delete" && -z $probably_ssh_session ]] then host=${host#$default_host} - elif [[ "$default_host_abbrev_mode" == "abbrev" && !$probably_ssh_session ]] + elif [[ "$default_host_abbrev_mode" == "abbrev" && -z $probably_ssh_session ]] then # only abbreviate if the abbreviated string is actually shorter than the full one if [[ "$host" == "$default_host" && ${#host} -ge $((${#ellipse_marker} + 1)) ]] From ad52c3b632fb90817c3c7df53a2f16bd26ee72b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 28 Sep 2013 19:03:04 +0200 Subject: [PATCH 036/118] -Fix: no upcase host in personal conf --- git-prompt.conf.mine | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine index f2d6e67..774aafc 100644 --- a/git-prompt.conf.mine +++ b/git-prompt.conf.mine @@ -52,7 +52,7 @@ cwd_cmd='cwd_truncate $(($COLUMNS/4))' # display only last N chars of path ########################################################### ETC # Some don't like hostname in uppercase -# upcase_hostname=on # =off +upcase_hostname=off # =off # Some don't like long hostname # short_hostname=off # =on From 0e23f941ff6b653a63bc83407a48caed0402d945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 28 Sep 2013 19:17:23 +0200 Subject: [PATCH 037/118] -Add: display @ before host in different color if remote session --- git-prompt.conf | 1 + git-prompt.conf.mine | 1 + git-prompt.sh | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/git-prompt.conf b/git-prompt.conf index 3a947b6..d7c6f53 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -90,6 +90,7 @@ # jobs_color_bkg=yellow # jobs_color_stop=red # at_color=green + # at_color_remote=RED # else # B/W terminal # dir_color=bw_bold # rc_color=bw_bold diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine index 774aafc..20d1f20 100644 --- a/git-prompt.conf.mine +++ b/git-prompt.conf.mine @@ -90,6 +90,7 @@ hg_revision_display=num jobs_color_bkg=yellow jobs_color_stop=red at_color=green + at_color_remote=RED # else # B/W terminal # dir_color=bw_bold diff --git a/git-prompt.sh b/git-prompt.sh index 7ee1f29..0c8ea06 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -5,7 +5,7 @@ ##### read config file if any. - unset make_color_ok make_color_dirty jobs_color_bkg jobs_color_stop slash_color at_color + unset make_color_ok make_color_dirty jobs_color_bkg jobs_color_stop slash_color at_color at_color_remote unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color unset modified_vcs_color added_vcs_color addmoded_vcs_color untracked_vcs_color op_vcs_color detached_vcs_color hex_vcs_color unset rawhex_len @@ -56,6 +56,7 @@ user_id_color=${user_id_color:-blue} root_id_color=${root_id_color:-magenta} at_color=${at_color:-green} + at_color_remote=${at_color_remote:-RED} jobs_color_bkg=${jobs_color:-yellow} jobs_color_stop=${jobs_color:-red} make_color_ok=${make_color_ok:-BLACK} @@ -371,6 +372,7 @@ set_shell_label() { if [[ -n ${SSH_CLIENT} || -n ${SSH2_CLIENT} ]]; then probably_ssh_session=1 + at_color=$at_color_remote else probably_ssh_session= fi From 2685f91980b5d2eb75468b7674ba3fd59f73702f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 28 Sep 2013 22:40:35 +0200 Subject: [PATCH 038/118] -Fix: replace hardcoded unprintable characters in xterm label escape sequence --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 0c8ea06..7b4d681 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -281,7 +281,7 @@ set_shell_label() { xterm_label() { local args="$*" - echo -n "]2;${args:0:200}" ; # FIXME: replace hardcodes with terminfo codes + printf "\033]0;%s\033\\" "${args:0:200}" } screen_label() { From 39e884ed9752eeb7228a7feabdcc32b9d6b2a723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 28 Sep 2013 23:36:22 +0200 Subject: [PATCH 039/118] -Fix: workaround screen UTF-8 bug with abbreviated host and id --- git-prompt.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 7b4d681..59b57ba 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -206,12 +206,14 @@ fi #################################################################### MARKERS + ellipse_marker_utf8="…" + ellipse_marker_plain="..." if [[ ("$LC_CTYPE $LC_ALL $LANG" =~ "UTF" || $LANG =~ "utf") && $TERM != "linux" ]]; then utf8_prompt=1 - ellipse_marker="…" + ellipse_marker=$ellipse_marker_utf8 else utf8_prompt= - ellipse_marker="..." + ellipse_marker=$ellipse_marker_plain fi export who_where @@ -285,8 +287,13 @@ set_shell_label() { } screen_label() { + local param + param="$plain_who_where $@" + # workaround screen UTF-8 bug + param=${param//$ellipse_marker/$ellipse_marker_plain} + # FIXME: run this only if screen is in xterm (how to test for this?) - xterm_label "$plain_who_where $@" + xterm_label "$param" # FIXME $STY not inherited though "su -" [ "$STY" ] && screen -S $STY -X title "$*" From 7e91c7a2ab8784384216c02625d4358307f4a832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 29 Sep 2013 16:35:27 +0200 Subject: [PATCH 040/118] -Add: track deleted files in svn/hg (TODO for git); -Fix: remove mixed/addmoded color (was unused anyway), cleanup of svn/hg modules --- git-prompt.conf | 2 +- git-prompt.conf.mine | 4 ++-- git-prompt.sh | 48 ++++++++++++++++++++++++-------------------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index d7c6f53..6538516 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -120,8 +120,8 @@ # clean_vcs_color=blue # nothing to commit (working directory clean) # modified_vcs_color=red # Changed but not updated: # added_vcs_color=green # Changes to be committed: -# mixed_vcs_color=yellow # # untracked_vcs_color=BLUE # Untracked files: +# deleted_vcs_color=yellow # Deleted files: # op_vcs_color=MAGENTA # detached_vcs_color=RED # hex_vcs_color=BLACK # git revision id: bright black (makes gray) diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine index 20d1f20..f1b9240 100644 --- a/git-prompt.conf.mine +++ b/git-prompt.conf.mine @@ -16,7 +16,7 @@ count_only=on # off - display file list; on - display file cou ############################################################ MODULES # git_module=on -# svn_module=off +svn_module=on # hg_module=on vim_module=off virtualenv_module=off @@ -122,8 +122,8 @@ hg_revision_display=num # clean_vcs_color=blue # nothing to commit (working directory clean) # modified_vcs_color=red # Changed but not updated: # added_vcs_color=green # Changes to be committed: -# mixed_vcs_color=yellow # # untracked_vcs_color=BLUE # Untracked files: +# deleted_vcs_color=yellow # Deleted files: # op_vcs_color=MAGENTA # detached_vcs_color=RED # hex_vcs_color=white # git revision id: bright black (makes gray) diff --git a/git-prompt.sh b/git-prompt.sh index 59b57ba..b5fce2f 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -7,7 +7,7 @@ unset make_color_ok make_color_dirty jobs_color_bkg jobs_color_stop slash_color at_color at_color_remote unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color - unset modified_vcs_color added_vcs_color addmoded_vcs_color untracked_vcs_color op_vcs_color detached_vcs_color hex_vcs_color + unset modified_vcs_color added_vcs_color untracked_vcs_color deleted_vcs_color op_vcs_color detached_vcs_color hex_vcs_color unset rawhex_len conf=git-prompt.conf; [[ -r $conf ]] && . $conf @@ -77,8 +77,8 @@ clean_vcs_color=${clean_vcs_color:-blue} # nothing to commit (working directory clean) modified_vcs_color=${modified_vcs_color:-red} # Changed but not updated: added_vcs_color=${added_vcs_color:-green} # Changes to be committed: - addmoded_vcs_color=${addmoded_vcs_color:-yellow} untracked_vcs_color=${untracked_vcs_color:-BLUE} # Untracked files: + deleted_vcs_color=${deleted_vcs_color:-yellow} # Deleted files: op_vcs_color=${op_vcs_color:-MAGENTA} detached_vcs_color=${detached_vcs_color:-RED} @@ -160,15 +160,15 @@ bell="\[`eval ${!error_bell} tput bel`\]" colors_reset='\['`tput sgr0`'\]' - # replace symbolic colors names to raw treminfo strings + # replace symbolic colors names to raw terminfo strings init_vcs_color=${!init_vcs_color} modified_vcs_color=${!modified_vcs_color} untracked_vcs_color=${!untracked_vcs_color} clean_vcs_color=${!clean_vcs_color} added_vcs_color=${!added_vcs_color} op_vcs_color=${!op_vcs_color} - addmoded_vcs_color=${!addmoded_vcs_color} detached_vcs_color=${!detached_vcs_color} + deleted_vcs_color=${!deleted_vcs_color} hex_vcs_color=${!hex_vcs_color} unset PROMPT_COMMAND @@ -566,17 +566,20 @@ parse_svn_status() { ` ### get status - unset status modified added clean init added mixed untracked op detached + unset status modified added clean init deleted untracked op detached eval `svn status 2>/dev/null | sed -n ' - s/^A... \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p - s/^M... \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p - s/^\?... \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\"\1\";/p + s/^A... \([^.].*\)/added=added; added_files[${#added_files[@]}]=\"\1\";/p + s/^M... \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p + s/^R... \([^.].*\)/added=added;/p + s/^D... \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p + s/^\!... \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p + s/^\?... \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\"\1\";/p ' ` # TODO branch detection if standard repo layout - [[ -z $modified ]] && [[ -z $untracked ]] && clean=clean + [[ -z $modified ]] && [[ -z $untracked ]] && [[ -z $added ]] && [[ -z $deleted ]] && clean=clean vcs_info=svn:r$rev } @@ -588,22 +591,22 @@ parse_hg_status() { vcs=hg ### get status - unset status modified added clean init added mixed untracked op detached + unset status modified added clean init deleted untracked op detached eval `hg status 2>/dev/null | sed -n ' - s/^M \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p - s/^A \([^.].*\)/added=added; added_files[${#added_files[@]}]=\"\1\";/p - s/^R \([^.].*\)/added=added;/p - s/^! \([^.].*\)/modified=modified;/p - s/^? \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\\"\1\\";/p + s/^M \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p + s/^A \([^.].*\)/added=added; added_files[${#added_files[@]}]=\"\1\";/p + s/^R \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p + s/^\! \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p + s/^\? \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\\"\1\\";/p '` branch=`hg branch 2> /dev/null` [[ -f $hg_root/.hg/bookmarks.current ]] && bookmark=`cat "$hg_root/.hg/bookmarks.current"` - [[ -z $modified ]] && [[ -z $untracked ]] && [[ -z $added ]] && clean=clean + [[ -z $modified ]] && [[ -z $untracked ]] && [[ -z $added ]] && [[ -z $deleted ]] && clean=clean vcs_info=${branch/default/D} if [[ "$bookmark" ]] ; then @@ -651,7 +654,7 @@ parse_git_status() { untracked_files=() [[ $rawhex_len -gt 0 ]] && freshness="$dim=" - unset branch status modified added clean init added mixed untracked op detached + unset branch status modified added clean init deleted untracked op detached if [[ $utf8_prompt ]]; then git_up_char="↑" @@ -787,16 +790,14 @@ parse_git_status() { parse_vcs_status() { - unset file_list modified_files untracked_files added_files + unset file_list modified_files untracked_files added_files deleted_files unset vcs vcs_info - unset status modified untracked added init detached - unset file_list modified_files untracked_files added_files + unset status modified untracked added init detached deleted [[ $vcs_ignore_dir_list =~ $PWD ]] && return eval $PARSE_VCS_STATUS - ### status: choose primary (for branch color) unset status status=${op:+op} @@ -804,6 +805,7 @@ parse_vcs_status() { status=${status:-$clean} status=${status:-$modified} status=${status:-$added} + status=${status:-$deleted} status=${status:-$untracked} status=${status:-$init} # at least one should be set @@ -842,16 +844,18 @@ parse_vcs_status() { unset file_list if [[ $count_only = "on" ]] ; then [[ ${added_files[0]} ]] && file_list+=" "${added_vcs_color}+${#added_files[@]} + [[ ${deleted_files[0]} ]] && file_list+=" "${deleted_vcs_color}-${#deleted_files[@]} [[ ${modified_files[0]} ]] && file_list+=" "${modified_vcs_color}*${#modified_files[@]} [[ ${untracked_files[0]} ]] && file_list+=" "${untracked_vcs_color}?${#untracked_files[@]} else [[ ${added_files[0]} ]] && file_list+=" "$added_vcs_color${added_files[@]} + [[ ${deleted_files[0]} ]] && file_list+=" "$deleted_vcs_color${deleted_files[@]} [[ ${modified_files[0]} ]] && file_list+=" "$modified_vcs_color${modified_files[@]} [[ ${untracked_files[0]} ]] && file_list+=" "$untracked_vcs_color${untracked_files[@]} fi [[ ${vim_files} ]] && file_list+=" "${MAGENTA}vim:${vim_files} - if [[ ${#file_list} -gt $max_file_list_length ]] ; then + if [[ $count_only != "on" && ${#file_list} -gt $max_file_list_length ]] ; then file_list=${file_list:0:$max_file_list_length} if [[ $max_file_list_length -gt 0 ]] ; then file_list="${file_list% *} $ellipse_marker" From 83529e680b4561afb3a3e22c717d42fbb1b5fa5e Mon Sep 17 00:00:00 2001 From: Juhasz Peter Date: Mon, 30 Sep 2013 11:45:43 +0200 Subject: [PATCH 041/118] -Fix: suppress warning from which when detecting make and acpi --- git-prompt.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index b5fce2f..edfedd6 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -37,14 +37,13 @@ prompt_modules_order=${prompt_modules_order:-RC VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE} #### check for acpi, make, disable corresponding module if not installed - if [[ -z $(which acpi) || -z $(acpi -b) ]]; then + if [[ -z $(which acpi 2> /dev/null) || -z $(acpi -b) ]]; then battery_module=off fi - if [[ -z $(which make) ]]; then + if [[ -z $(which make 2> /dev/null) ]]; then make_module=off fi - #### dir, rc, root color cols=`tput colors` # in emacs shell-mode tput colors returns -1 if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors From 8188403431683d40ec766693a4a98b4b84a93cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Tue, 1 Oct 2013 19:23:43 +0200 Subject: [PATCH 042/118] -Fix: issue colors_reset after jobs indicator --- git-prompt.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index edfedd6..35723a2 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -511,9 +511,9 @@ create_jobs_indicator() { jobs_indicator="%" fi if [[ -n $jobs_stop ]]; then - jobs_indicator="${!jobs_color_stop}$jobs_indicator" + jobs_indicator="${!jobs_color_stop}$jobs_indicator$colors_reset" else - jobs_indicator="${!jobs_color_bkg}$jobs_indicator" + jobs_indicator="${!jobs_color_bkg}$jobs_indicator$colors_reset" fi else jobs_indicator="" From e92be99810db729f9266e4928ba263178f82208e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Tue, 1 Oct 2013 20:02:56 +0200 Subject: [PATCH 043/118] -Fix: try to salvage some functionality in mc (abbreviated id and hostname) --- git-prompt.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 35723a2..1cac14f 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -196,14 +196,6 @@ s/\$space/ /g; ') - ####### 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$prompt_char " - return 0 - fi - #################################################################### MARKERS ellipse_marker_utf8="…" ellipse_marker_plain="..." @@ -448,6 +440,24 @@ set_shell_label() { color_who_where='' fi + # There are at least two separate problems with mc: + # it clobbers $PROMPT_COLOR, so none of the dynamically generated + # components can work, + # and it swallows escape sequences, so colors don't work either. + # Here we try to salvage some of the functionality for shells within mc. + # + # specifically exclude emacs, want full when running inside emacs + if [[ -z "$TERM" || ("$TERM" = "dumb" && -z "$INSIDE_EMACS") || -n "$MC_SID" ]]; then + unset PROMPT_COMMAND + if [[ -n $id || -n $host ]] ; then + PS1="$color_who_where:\w$prompt_char " + else + PS1="\w$prompt_char " + fi + return 0 + fi + + create_battery_indicator () { # if not a laptop: : # if laptop on AC, not charging: ⚡ From 64a6c2416280ff0e31596c8d415c63ab076d082c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Wed, 2 Oct 2013 22:42:37 +0200 Subject: [PATCH 044/118] -Fix: use different character if revision number shown for hg --- git-prompt.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/git-prompt.sh b/git-prompt.sh index 1cac14f..e9e84e5 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -635,6 +635,7 @@ parse_hg_status() { hg_revision="$hex_vcs_color$hg_vcs_char${hg_revision:0:$rawhex_len}" ;; num) hg_revision=$(hg id -n) + hg_vcs_char="#" hg_revision="$hex_vcs_color$hg_vcs_char$hg_revision" ;; *) hg_revision="" ;; From 345251444582b2aefef3cc84e7a470cd6e217a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Wed, 2 Oct 2013 22:45:46 +0200 Subject: [PATCH 045/118] -Fix: use local variables in hg section --- git-prompt.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/git-prompt.sh b/git-prompt.sh index e9e84e5..c0441d6 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -611,6 +611,9 @@ parse_hg_status() { s/^\? \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\\"\1\\";/p '` + local branch + local bookmark + branch=`hg branch 2> /dev/null` [[ -f $hg_root/.hg/bookmarks.current ]] && bookmark=`cat "$hg_root/.hg/bookmarks.current"` From 0ea7d684a0277b8f082c6775874f94f49819b417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Wed, 2 Oct 2013 23:18:18 +0200 Subject: [PATCH 046/118] -Add: show multiple heads for hg --- git-prompt.conf | 3 +++ git-prompt.conf.mine | 3 +++ git-prompt.sh | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/git-prompt.conf b/git-prompt.conf index 6538516..e9c9b09 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -72,6 +72,9 @@ ### * none - do not display at all # hg_revision_display=none +### Check for and display multiple hg heads +# hg_multiple_heads_display=on + ########################################################### COLOR ### directory, exit code, root color diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine index f1b9240..f0e4678 100644 --- a/git-prompt.conf.mine +++ b/git-prompt.conf.mine @@ -72,6 +72,9 @@ make_ignore_dir_list=" /etc $HOME /usr/src/linux.git " ### * none - do not display at all hg_revision_display=num +### Check for and display multiple hg heads +# hg_multiple_heads_display=on + ########################################################### COLOR ### directory, exit code, root color diff --git a/git-prompt.sh b/git-prompt.sh index c0441d6..c5b3be9 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -90,6 +90,7 @@ count_only=${count_only:-off} rawhex_len=${rawhex_len:-5} hg_revision_display=${hg_revision_display:-none} + hg_multiple_heads_display=${hg_multiple_heads_display:-on} aj_max=20 @@ -625,6 +626,17 @@ parse_hg_status() { vcs_info+=/$bookmark fi + if [[ $hg_multiple_heads_display == "on" ]]; then + local hg_heads + hg_heads=$(hg heads --template '{rev}\n' $branch | wc -l) + + if [[ hg_heads -gt 1 ]]; then + detached=detached + local excl_mark='!' + vcs_info="$detached_vcs_color$hg_heads$excl_mark$vcs_info" + fi + fi + local hg_vcs_char if [[ $utf8_prompt ]]; then hg_vcs_char="☿" From 3980ffbe8cb6984e6ba1857be1d0d9ef2526efae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Fri, 4 Oct 2013 17:51:47 +0200 Subject: [PATCH 047/118] -Fix: svn detection based on svn info for >1.7 svn --- git-prompt.sh | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index c5b3be9..4a09ca3 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -104,6 +104,22 @@ [[ $svn_module = "on" ]] && type svn >&/dev/null && PARSE_VCS_STATUS+="${PARSE_VCS_STATUS+||}parse_svn_status" [[ $hg_module = "on" ]] && type hg >&/dev/null && PARSE_VCS_STATUS+="${PARSE_VCS_STATUS+||}parse_hg_status" PARSE_VCS_STATUS+="${PARSE_VCS_STATUS+||}return" + + ### determining svn version information + ### In svn versions 1.7 and above there is only a single .svn directory + ### in the repository root, while before there was a .svn in every subdirectory. + ### Here we determine and save svn version information + ### and use the appropriate method in the runtime module + if [[ $PARSE_VCS_STATUS =~ "svn" ]]; then + svn_version_str=$(svn --version 2> /dev/null | head -1 | sed -ne 's/.* \([0-9]\)\.\([0-9]\{1,2\}\).*/\1\2/p') + if [[ svn_version_str > 16 ]]; then + svn_use_info=1 + else + svn_use_info= + fi + unset svn_version_str + fi + ################# terminfo colors-16 # # black? 0 8 @@ -556,19 +572,24 @@ check_make_status() { } parse_svn_status() { - # FIXME: SVN >= 1.7 uses a single .svn dir in the repository toplevel dir (like hg or git) - # instead of a .svn in each tracked dir, so the method below will not work! - # Unfortunately there is no easy fix, because svn doesn't have the equivalent of "hg root" - # or "git rev-parse", not to mention that it's possible to just check out a subdirectory of a repo, - # and different levels of a directory tree can belong to different checkouts. + local svn_info_str + local myrc - [[ -d .svn ]] || return 1 + if [[ -n $use_svn_info ]]; then + svn_info_str=$(svn info 2> /dev/null) + myrc=$? + [[ $myrc -ne 0 ]] || return 1 + else + [[ -d .svn ]] || return 1 + + svn_info_str=$(svn info 2> /dev/null) + fi vcs=svn ### get rev eval ` - svn info | + printf "%s" "$svn_info_str" | sed -n " s@^URL[^/]*//@repo_dir=@p s/^Revision: /rev=/p @@ -583,14 +604,14 @@ parse_svn_status() { s/^M... \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p s/^R... \([^.].*\)/added=added;/p s/^D... \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p - s/^\!... \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p - s/^\?... \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\"\1\";/p + s/^\!... \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p + s/^\?... \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\"\1\";/p ' ` # TODO branch detection if standard repo layout [[ -z $modified ]] && [[ -z $untracked ]] && [[ -z $added ]] && [[ -z $deleted ]] && clean=clean - vcs_info=svn:r$rev + vcs_info=r$rev } parse_hg_status() { From 5f2a4bcb664bd0f8feefc5fb9374d5906a09ec45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Fri, 4 Oct 2013 18:21:26 +0200 Subject: [PATCH 048/118] -Fix: stupid mistakes --- git-prompt.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 4a09ca3..3191e45 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -112,7 +112,7 @@ ### and use the appropriate method in the runtime module if [[ $PARSE_VCS_STATUS =~ "svn" ]]; then svn_version_str=$(svn --version 2> /dev/null | head -1 | sed -ne 's/.* \([0-9]\)\.\([0-9]\{1,2\}\).*/\1\2/p') - if [[ svn_version_str > 16 ]]; then + if [[ $svn_version_str > 16 ]]; then svn_use_info=1 else svn_use_info= @@ -575,10 +575,10 @@ parse_svn_status() { local svn_info_str local myrc - if [[ -n $use_svn_info ]]; then + if [[ -n $svn_use_info ]]; then svn_info_str=$(svn info 2> /dev/null) myrc=$? - [[ $myrc -ne 0 ]] || return 1 + [[ $myrc -eq 0 ]] || return 1 else [[ -d .svn ]] || return 1 From 916316711b2c736eed9c51db8bfcd38a1a607650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Fri, 11 Oct 2013 21:08:35 +0200 Subject: [PATCH 049/118] -Add: display if hg working dir is not at tip --- git-prompt.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 3191e45..09954f6 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -651,7 +651,7 @@ parse_hg_status() { local hg_heads hg_heads=$(hg heads --template '{rev}\n' $branch | wc -l) - if [[ hg_heads -gt 1 ]]; then + if [[ $hg_heads -gt 1 ]]; then detached=detached local excl_mark='!' vcs_info="$detached_vcs_color$hg_heads$excl_mark$vcs_info" @@ -659,10 +659,21 @@ parse_hg_status() { fi local hg_vcs_char + local hg_up_char if [[ $utf8_prompt ]]; then hg_vcs_char="☿" + hg_up_char="↑" else hg_vcs_char=":" + hg_up_char="^" + fi + + local hg_tags + local tip_regex + hg_tags=$(hg id -t) + tip_regex=\\btip\\b + if [[ ! $hg_tags =~ $tip_regex ]]; then + vcs_info+="$WHITE$hg_up_char" fi local hg_revision From 7251a790bc09f1c4d7bf43561b58dfc710abe86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 12 Oct 2013 12:01:04 +0200 Subject: [PATCH 050/118] -Fix: changed hg wd up-to-date flag location and color to make it distinct from git's 'ahead remote' flag, cleaned up logic so that hg id is called only once --- git-prompt.sh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 09954f6..ef20f0e 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -633,8 +633,7 @@ parse_hg_status() { s/^\? \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\\"\1\\";/p '` - local branch - local bookmark + local branch bookmark branch=`hg branch 2> /dev/null` @@ -658,37 +657,40 @@ parse_hg_status() { fi fi - local hg_vcs_char - local hg_up_char + local hg_vcs_char hg_up_char if [[ $utf8_prompt ]]; then hg_vcs_char="☿" - hg_up_char="↑" + hg_up_char="▲" else hg_vcs_char=":" hg_up_char="^" fi - local hg_tags - local tip_regex - hg_tags=$(hg id -t) + # get the local rev number, global rev hash and tag in one go from hg id's output + # if tag does not contain "tip", the working dir is not up to date + local id_str re num rev tags tip_regex not_uptodate + id_str=$(hg id -nit) + re="^([^ ]+) ([^ ]+) ?(.*)$" + [[ $id_str =~ $re ]] && rev="${BASH_REMATCH[1]}" && num="${BASH_REMATCH[2]}" && tags="${BASH_REMATCH[3]}" + tip_regex=\\btip\\b - if [[ ! $hg_tags =~ $tip_regex ]]; then - vcs_info+="$WHITE$hg_up_char" + if [[ ! $tags =~ $tip_regex ]]; then + not_uptodate="$YELLOW$hg_up_char" fi local hg_revision case $hg_revision_display in - id) hg_revision=$(hg id -i) + id) hg_revision=$rev hg_revision="$hex_vcs_color$hg_vcs_char${hg_revision:0:$rawhex_len}" ;; - num) hg_revision=$(hg id -n) + num) hg_revision=$num hg_vcs_char="#" hg_revision="$hex_vcs_color$hg_vcs_char$hg_revision" ;; *) hg_revision="" ;; esac - vcs_info+=$hg_revision + vcs_info+=$hg_revision$not_uptodate } From 4739c3ccf52adf1da7a5c64789c233418aa9cbee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 12 Oct 2013 21:25:40 +0200 Subject: [PATCH 051/118] -Add: color slashes differently if pwd is not writable --- git-prompt.conf | 1 + git-prompt.conf.mine | 1 + git-prompt.sh | 13 ++++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index e9c9b09..665bd97 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -83,6 +83,7 @@ # if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors # dir_color=CYAN # slash_color=BLUE + # slash_color_readonly=MAGENTA # prompt_color=white # rc_color=red # virtualenv_color=green diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine index f0e4678..2c6d4a0 100644 --- a/git-prompt.conf.mine +++ b/git-prompt.conf.mine @@ -83,6 +83,7 @@ hg_revision_display=num # if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors dir_color=BLUE slash_color=CYAN + slash_color_readonly=MAGENTA prompt_color=colors_reset rc_color=red virtualenv_color=green diff --git a/git-prompt.sh b/git-prompt.sh index ef20f0e..5b229d5 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -5,7 +5,7 @@ ##### read config file if any. - unset make_color_ok make_color_dirty jobs_color_bkg jobs_color_stop slash_color at_color at_color_remote + unset make_color_ok make_color_dirty jobs_color_bkg jobs_color_stop slash_color slash_color_readonly at_color at_color_remote unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color unset modified_vcs_color added_vcs_color untracked_vcs_color deleted_vcs_color op_vcs_color detached_vcs_color hex_vcs_color unset rawhex_len @@ -49,6 +49,7 @@ if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors dir_color=${dir_color:-CYAN} slash_color=${slash_color:-CYAN} + slash_color_readonly=${slash_color_readonly:-MAGENTA} prompt_color=${prompt_color:-white} rc_color=${rc_color:-red} virtualenv_color=${virtualenv_color:-green} @@ -370,6 +371,7 @@ set_shell_label() { dir_color=${!dir_color} slash_color=${!slash_color} + slash_color_readonly=${!slash_color_readonly} prompt_color=${!prompt_color} rc_color=${!rc_color} virtualenv_color=${!virtualenv_color} @@ -992,7 +994,7 @@ prompt_command_function() { cwd=${PWD/$HOME/\~} # substitute "~" set_shell_label "${cwd##[/~]*/}/" # default label - path last dir - parse_virtualenv_status + parse_virtualenv_status parse_vcs_status if [[ $battery_module == "on" ]]; then @@ -1022,7 +1024,12 @@ prompt_command_function() { # else eval cwd_cmd, cwd should have path after exection eval "${cwd_cmd/\\/cwd=\\\\}" - cwd=${cwd//\//$slash_color\/$dir_color} + + if [[ -w "$PWD" ]]; then + cwd=${cwd//\//$slash_color\/$dir_color} + else + cwd=${cwd//\//$slash_color_readonly\/$dir_color} + fi # in effect, echo collapses spaces inside the string and removes them from the start/end local prompt_command_string_l From 149a551e8d7833dea2f87c95572fd52bd6a47542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 12 Oct 2013 21:40:20 +0200 Subject: [PATCH 052/118] -Add: functions to turn fancy prompt on and off --- git-prompt.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/git-prompt.sh b/git-prompt.sh index 5b229d5..6de7b66 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -1043,10 +1043,39 @@ prompt_command_function() { unset head_local raw_rc } +# provide functions to turn the fancy prompt functions on and off +# off: return to old (distro default) prompt +# OFF: plain $ +# idea taken from liquidprompt: https://github.com/nojhan/liquidprompt +prompt_on() { + if [[ -z $GIT_PROMPT_ON ]]; then + OLD_PS1="$PS1" + OLD_PROMPT_COMMAND="$PROMPT_COMMAND" + fi + PROMPT_COMMAND=prompt_command_function enable_set_shell_label + GIT_PROMPT_ON=1 +} + +prompt_off() { + PROMPT_COMMAND="$OLD_PROMPT_COMMAND" + PS1="$OLD_PS1" + + disable_set_shell_label +} + +prompt_OFF() { + PROMPT_COMMAND="$OLD_PROMPT_COMMAND" + PS1="\$ " + + disable_set_shell_label +} + + prompt_on + unset rc id tty modified_files file_list # vim: set ft=sh ts=8 sw=8 et: From 5f2ff180b3e34ec42ae522d012d0919edf289218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 12 Oct 2013 22:03:11 +0200 Subject: [PATCH 053/118] -Change: better mark for hg wd not up to date (fat up arrow) --- git-prompt.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 6de7b66..5bccaaa 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -662,7 +662,8 @@ parse_hg_status() { local hg_vcs_char hg_up_char if [[ $utf8_prompt ]]; then hg_vcs_char="☿" - hg_up_char="▲" + hg_up_char="⬆" + else hg_vcs_char=":" hg_up_char="^" From 7299ab242eb016cd0e17a479f77599ee10c6acc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 13 Oct 2013 13:22:43 +0200 Subject: [PATCH 054/118] -Change: revise svn revision info logic, use svnversion if installed --- git-prompt.sh | 63 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 5bccaaa..2e86fa8 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -111,12 +111,18 @@ ### in the repository root, while before there was a .svn in every subdirectory. ### Here we determine and save svn version information ### and use the appropriate method in the runtime module + ### However, if the "svnversion" utility is installed, + ### we use its output instead. if [[ $PARSE_VCS_STATUS =~ "svn" ]]; then + unset svn_method + type svnversion >&/dev/null && svn_method="svnversion" svn_version_str=$(svn --version 2> /dev/null | head -1 | sed -ne 's/.* \([0-9]\)\.\([0-9]\{1,2\}\).*/\1\2/p') - if [[ $svn_version_str > 16 ]]; then - svn_use_info=1 - else - svn_use_info= + if [[ "$svn_method" != "svnversion" ]]; then + if [[ $svn_version_str > 16 ]]; then + svn_method="info" + else + svn_method="dotsvn" + fi fi unset svn_version_str fi @@ -574,29 +580,40 @@ check_make_status() { } parse_svn_status() { - local svn_info_str - local myrc + local svn_info_str myrc rev + + extract_rev() { + local lrev + eval ` + printf "%s" "$1" | + sed -n " + s/^Revision: /lrev=/p + " + ` + echo -n $lrev + } - if [[ -n $svn_use_info ]]; then - svn_info_str=$(svn info 2> /dev/null) - myrc=$? - [[ $myrc -eq 0 ]] || return 1 - else - [[ -d .svn ]] || return 1 + case $svn_method in + svnversion) rev=$(svnversion) + [[ "$rev" == "exported" ]] && return 1 + ;; - svn_info_str=$(svn info 2> /dev/null) - fi + info) svn_info_str=$(svn info 2> /dev/null) + myrc=$? + [[ $myrc -eq 0 ]] || return 1 + rev=$(extract_rev "$svn_info_str") + ;; + + dotsvn) [[ -d .svn ]] || return 1 + svn_info_str=$(svn info 2> /dev/null) + rev=$(extract_rev "$svn_info_str") + ;; + + *) return 1 + esac vcs=svn - ### get rev - eval ` - printf "%s" "$svn_info_str" | - sed -n " - s@^URL[^/]*//@repo_dir=@p - s/^Revision: /rev=/p - " - ` ### get status unset status modified added clean init deleted untracked op detached @@ -613,7 +630,7 @@ parse_svn_status() { # TODO branch detection if standard repo layout [[ -z $modified ]] && [[ -z $untracked ]] && [[ -z $added ]] && [[ -z $deleted ]] && clean=clean - vcs_info=r$rev + vcs_info=r$hex_vcs_color$rev } parse_hg_status() { From 39cdc0486321ef7f5612de4ecb695661a9d79e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 13 Oct 2013 13:23:38 +0200 Subject: [PATCH 055/118] -Fix: typo in comment --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 2e86fa8..7ac0f7a 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -466,7 +466,7 @@ set_shell_label() { fi # There are at least two separate problems with mc: - # it clobbers $PROMPT_COLOR, so none of the dynamically generated + # it clobbers $PROMPT_COMMAND, so none of the dynamically generated # components can work, # and it swallows escape sequences, so colors don't work either. # Here we try to salvage some of the functionality for shells within mc. From 2a04c55a3cb56963c0855ba47a38bc6929280079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 13 Oct 2013 14:10:32 +0200 Subject: [PATCH 056/118] -Add: list conflicted files for svn --- git-prompt.conf | 1 + git-prompt.conf.mine | 1 + git-prompt.sh | 47 ++++++++++++++++++++++++++++---------------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index 665bd97..af8d1b0 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -126,6 +126,7 @@ # added_vcs_color=green # Changes to be committed: # untracked_vcs_color=BLUE # Untracked files: # deleted_vcs_color=yellow # Deleted files: +# conflicted_vcs_color=CYAN # Conflicted files: # op_vcs_color=MAGENTA # detached_vcs_color=RED # hex_vcs_color=BLACK # git revision id: bright black (makes gray) diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine index 2c6d4a0..fd6cf87 100644 --- a/git-prompt.conf.mine +++ b/git-prompt.conf.mine @@ -128,6 +128,7 @@ hg_revision_display=num # added_vcs_color=green # Changes to be committed: # untracked_vcs_color=BLUE # Untracked files: # deleted_vcs_color=yellow # Deleted files: +# conflicted_vcs_color=CYAN # Conflicted files: # op_vcs_color=MAGENTA # detached_vcs_color=RED # hex_vcs_color=white # git revision id: bright black (makes gray) diff --git a/git-prompt.sh b/git-prompt.sh index 7ac0f7a..c2c06eb 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -79,6 +79,7 @@ added_vcs_color=${added_vcs_color:-green} # Changes to be committed: untracked_vcs_color=${untracked_vcs_color:-BLUE} # Untracked files: deleted_vcs_color=${deleted_vcs_color:-yellow} # Deleted files: + conflicted_vcs_color=${conflicted_vcs_color:-CYAN} # Conflicted files: op_vcs_color=${op_vcs_color:-MAGENTA} detached_vcs_color=${detached_vcs_color:-RED} @@ -185,6 +186,7 @@ # replace symbolic colors names to raw terminfo strings init_vcs_color=${!init_vcs_color} + conflicted_vcs_color=${!conflicted_vcs_color} modified_vcs_color=${!modified_vcs_color} untracked_vcs_color=${!untracked_vcs_color} clean_vcs_color=${!clean_vcs_color} @@ -616,20 +618,27 @@ parse_svn_status() { ### get status - unset status modified added clean init deleted untracked op detached + unset status modified added clean init deleted untracked conflicted op detached eval `svn status 2>/dev/null | sed -n ' - s/^A... \([^.].*\)/added=added; added_files[${#added_files[@]}]=\"\1\";/p - s/^M... \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p + s/^A... \([^.].*\)/added=added; added_files[${#added_files[@]}]=\"\1\";/p + s/^M... \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p s/^R... \([^.].*\)/added=added;/p - s/^D... \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p - s/^\!... \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p - s/^\?... \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\"\1\";/p + s/^D... \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p + s/^C... \([^.].*\)/conflicted=conflicted; conflicted_files[${#conflicted_files[@]}]=\"\1\";/p + s/^\!... \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p + s/^\?... \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\"\1\";/p ' ` # TODO branch detection if standard repo layout - [[ -z $modified ]] && [[ -z $untracked ]] && [[ -z $added ]] && [[ -z $deleted ]] && clean=clean + [[ -z $modified ]] && \ + [[ -z $untracked ]] && \ + [[ -z $added ]] && \ + [[ -z $deleted ]] && \ + [[ -z $conflicted ]] && \ + clean=clean + vcs_info=r$hex_vcs_color$rev } @@ -869,9 +878,9 @@ parse_git_status() { parse_vcs_status() { - unset file_list modified_files untracked_files added_files deleted_files + unset file_list modified_files untracked_files added_files deleted_files conflicted_files unset vcs vcs_info - unset status modified untracked added init detached deleted + unset status modified untracked added init detached deleted conflicted [[ $vcs_ignore_dir_list =~ $PWD ]] && return @@ -882,6 +891,7 @@ parse_vcs_status() { status=${op:+op} status=${status:-$detached} status=${status:-$clean} + status=${status:-$conflicted} status=${status:-$modified} status=${status:-$added} status=${status:-$deleted} @@ -921,16 +931,19 @@ parse_vcs_status() { ### file list unset file_list + local excl_mark='!' if [[ $count_only = "on" ]] ; then - [[ ${added_files[0]} ]] && file_list+=" "${added_vcs_color}+${#added_files[@]} - [[ ${deleted_files[0]} ]] && file_list+=" "${deleted_vcs_color}-${#deleted_files[@]} - [[ ${modified_files[0]} ]] && file_list+=" "${modified_vcs_color}*${#modified_files[@]} - [[ ${untracked_files[0]} ]] && file_list+=" "${untracked_vcs_color}?${#untracked_files[@]} + [[ ${added_files[0]} ]] && file_list+=" "${added_vcs_color}+${#added_files[@]} + [[ ${deleted_files[0]} ]] && file_list+=" "${deleted_vcs_color}-${#deleted_files[@]} + [[ ${modified_files[0]} ]] && file_list+=" "${modified_vcs_color}*${#modified_files[@]} + [[ ${untracked_files[0]} ]] && file_list+=" "${untracked_vcs_color}?${#untracked_files[@]} + [[ ${conflicted_files[0]} ]] && file_list+=" ${conflicted_vcs_color}${excl_mark}${#conflicted_files[@]}" else - [[ ${added_files[0]} ]] && file_list+=" "$added_vcs_color${added_files[@]} - [[ ${deleted_files[0]} ]] && file_list+=" "$deleted_vcs_color${deleted_files[@]} - [[ ${modified_files[0]} ]] && file_list+=" "$modified_vcs_color${modified_files[@]} - [[ ${untracked_files[0]} ]] && file_list+=" "$untracked_vcs_color${untracked_files[@]} + [[ ${added_files[0]} ]] && file_list+=" "$added_vcs_color${added_files[@]} + [[ ${deleted_files[0]} ]] && file_list+=" "$deleted_vcs_color${deleted_files[@]} + [[ ${modified_files[0]} ]] && file_list+=" "$modified_vcs_color${modified_files[@]} + [[ ${untracked_files[0]} ]] && file_list+=" "$untracked_vcs_color${untracked_files[@]} + [[ ${conflicted_files[0]} ]] && file_list+=" "$conflicted_vcs_color${conflicted_files[@]} fi [[ ${vim_files} ]] && file_list+=" "${MAGENTA}vim:${vim_files} From dd8efaa8c7ebde91a5f6c5bbf0083beb1db6466c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 13 Oct 2013 14:17:14 +0200 Subject: [PATCH 057/118] -Change: reorder elments in vcs file list --- git-prompt.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index c2c06eb..5abb61b 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -933,17 +933,18 @@ parse_vcs_status() { unset file_list local excl_mark='!' if [[ $count_only = "on" ]] ; then - [[ ${added_files[0]} ]] && file_list+=" "${added_vcs_color}+${#added_files[@]} - [[ ${deleted_files[0]} ]] && file_list+=" "${deleted_vcs_color}-${#deleted_files[@]} + [[ ${conflicted_files[0]} ]] && file_list+=" ${conflicted_vcs_color}${excl_mark}${#conflicted_files[@]}" [[ ${modified_files[0]} ]] && file_list+=" "${modified_vcs_color}*${#modified_files[@]} + [[ ${deleted_files[0]} ]] && file_list+=" "${deleted_vcs_color}-${#deleted_files[@]} + [[ ${added_files[0]} ]] && file_list+=" "${added_vcs_color}+${#added_files[@]} [[ ${untracked_files[0]} ]] && file_list+=" "${untracked_vcs_color}?${#untracked_files[@]} - [[ ${conflicted_files[0]} ]] && file_list+=" ${conflicted_vcs_color}${excl_mark}${#conflicted_files[@]}" else - [[ ${added_files[0]} ]] && file_list+=" "$added_vcs_color${added_files[@]} - [[ ${deleted_files[0]} ]] && file_list+=" "$deleted_vcs_color${deleted_files[@]} + [[ ${conflicted_files[0]} ]] && file_list+=" "$conflicted_vcs_color${conflicted_files[@]} [[ ${modified_files[0]} ]] && file_list+=" "$modified_vcs_color${modified_files[@]} + [[ ${deleted_files[0]} ]] && file_list+=" "$deleted_vcs_color${deleted_files[@]} + [[ ${added_files[0]} ]] && file_list+=" "$added_vcs_color${added_files[@]} [[ ${untracked_files[0]} ]] && file_list+=" "$untracked_vcs_color${untracked_files[@]} - [[ ${conflicted_files[0]} ]] && file_list+=" "$conflicted_vcs_color${conflicted_files[@]} + fi [[ ${vim_files} ]] && file_list+=" "${MAGENTA}vim:${vim_files} From 6594b60786761d6806ea9f3db0e82f4f3034ec0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 13 Oct 2013 14:17:46 +0200 Subject: [PATCH 058/118] -Fix: reset colors after vcs_info in svn module --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 5abb61b..e53a06e 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -639,7 +639,7 @@ parse_svn_status() { [[ -z $conflicted ]] && \ clean=clean - vcs_info=r$hex_vcs_color$rev + vcs_info=r$hex_vcs_color$rev$colors_reset } parse_hg_status() { From 8b7c734f630546db8ed641d878b501beb669edf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 13 Oct 2013 15:07:31 +0200 Subject: [PATCH 059/118] -Add: display conflicted and deleted files for git --- git-prompt.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index e53a06e..cce6ef7 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -782,12 +782,18 @@ parse_git_status() { eval " $( LANG=C git status --porcelain 2>/dev/null | sed -n ' - s,^[MARC]. \([^\"][^/]*/\?\).*, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p - s,^[MARC]. \"\([^/]\+/\?\).*\"$, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p - s,^.[MAU] \([^\"][^/]*/\?\).*, modified=modified; [[ \" ${modified_files[@]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\",p - s,^.[MAU] \"\([^/]\+/\?\).*\"$, modified=modified; [[ \" ${modified_files[@]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\",p - s,^?? \([^\"][^/]*/\?\).*, untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\",p - s,^?? \"\([^/]\+/\?\).*\"$, untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\",p + s,^U. \([^\"][^/]*/\?\).*, conflicted=conflicted; [[ \" ${conflicted_files[@]} \" =~ \" \1 \" ]] || conflicted_files[${#conflicted_files[@]}]=\"\1\",p + s,^U. \"\([^/]\+/\?\).*\"$, conflicted=conflicted; [[ \" ${conflicted_files[@]} \" =~ \" \1 \" ]] || conflicted_files[${#conflicted_files[@]}]=\"\1\",p + s,^.U \([^\"][^/]*/\?\).*, conflicted=conflicted; [[ \" ${conflicted_files[@]} \" =~ \" \1 \" ]] || conflicted_files[${#conflicted_files[@]}]=\"\1\",p + s,^.U \"\([^/]\+/\?\).*\"$, conflicted=conflicted; [[ \" ${conflicted_files[@]} \" =~ \" \1 \" ]] || conflicted_files[${#conflicted_files[@]}]=\"\1\",p + s,^D. \([^\"][^/]*/\?\).*, deleted=deleted; [[ \" ${deleted_files[@]} \" =~ \" \1 \" ]] || deleted_files[${#conflicted_files[@]}]=\"\1\",p + s,^D. \"\([^/]\+/\?\).*\"$, deleted=deleted; [[ \" ${deleted_files[@]} \" =~ \" \1 \" ]] || deleted_files[${#conflicted_files[@]}]=\"\1\",p + s,^[MARC]. \([^\"][^/]*/\?\).*, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p + s,^[MARC]. \"\([^/]\+/\?\).*\"$, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p + s,^.[MA] \([^\"][^/]*/\?\).*, modified=modified; [[ \" ${modified_files[@]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\",p + s,^.[MA] \"\([^/]\+/\?\).*\"$, modified=modified; [[ \" ${modified_files[@]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\",p + s,^?? \([^\"][^/]*/\?\).*, untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\",p + s,^?? \"\([^/]\+/\?\).*\"$, untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\",p ' # |tee /dev/tty )" From ff1c30f6441a750be243f0527c2781e6a911c8e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 13 Oct 2013 18:50:54 +0200 Subject: [PATCH 060/118] [hg_module] -Fix: different way of pushing file onto file list array speeds up vcs module dramatically --- git-prompt.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index cce6ef7..87aab59 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -654,11 +654,11 @@ parse_hg_status() { eval `hg status 2>/dev/null | sed -n ' - s/^M \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p - s/^A \([^.].*\)/added=added; added_files[${#added_files[@]}]=\"\1\";/p - s/^R \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p - s/^\! \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p - s/^\? \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\\"\1\\";/p + s/^M \([^.].*\)/modified=modified; modified_files+=(\"\1\");/p + s/^A \([^.].*\)/added=added; added_files+=(\"\1\");/p + s/^R \([^.].*\)/deleted=deleted; deleted_files+=(\"\1\");/p + s/^\! \([^.].*\)/deleted=deleted; deleted_files+=(\"\1\");/p + s/^\? \([^.].*\)/untracked=untracked; untracked_files+=(\"\1\");/p '` local branch bookmark @@ -887,6 +887,7 @@ parse_vcs_status() { unset file_list modified_files untracked_files added_files deleted_files conflicted_files unset vcs vcs_info unset status modified untracked added init detached deleted conflicted + declare -a file_list modified_files untracked_files added_files deleted_files conflicted_files [[ $vcs_ignore_dir_list =~ $PWD ]] && return From 94e6acd1fda7b58ba6d52b10131fa7e76fedfd3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 13 Oct 2013 18:59:50 +0200 Subject: [PATCH 061/118] [svn_module] -Fix: different way of pushing file onto file list array speeds up vcs module dramatically --- git-prompt.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 87aab59..5cc8d67 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -621,13 +621,13 @@ parse_svn_status() { unset status modified added clean init deleted untracked conflicted op detached eval `svn status 2>/dev/null | sed -n ' - s/^A... \([^.].*\)/added=added; added_files[${#added_files[@]}]=\"\1\";/p - s/^M... \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p + s/^A... \([^.].*\)/added=added; added_files+=(\"\1\");/p + s/^M... \([^.].*\)/modified=modified; modified_files+=(\"\1\");/p s/^R... \([^.].*\)/added=added;/p - s/^D... \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p - s/^C... \([^.].*\)/conflicted=conflicted; conflicted_files[${#conflicted_files[@]}]=\"\1\";/p - s/^\!... \([^.].*\)/deleted=deleted; deleted_files[${#deleted_files[@]}]=\"\1\";/p - s/^\?... \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\"\1\";/p + s/^D... \([^.].*\)/deleted=deleted; deleted_files+=(\"\1\");/p + s/^C... \([^.].*\)/conflicted=conflicted; conflicted_files+=(\"\1\");/p + s/^\!... \([^.].*\)/deleted=deleted; deleted_files+=(\"\1\");/p + s/^\?... \([^.].*\)/untracked=untracked; untracked_files+=(\"\1\");/p ' ` # TODO branch detection if standard repo layout From c3d767a89940fe87cb7d56160ebe018b4af0f9f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 13 Oct 2013 19:17:29 +0200 Subject: [PATCH 062/118] [git_module] -Fix: different way of pushing file onto file list array speeds up vcs module dramatically --- git-prompt.sh | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 5cc8d67..44d1f19 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -737,9 +737,7 @@ parse_git_status() { vcs=git ########################################################## GIT STATUS - added_files=() - modified_files=() - untracked_files=() + [[ $rawhex_len -gt 0 ]] && freshness="$dim=" unset branch status modified added clean init deleted untracked op detached @@ -782,18 +780,18 @@ parse_git_status() { eval " $( LANG=C git status --porcelain 2>/dev/null | sed -n ' - s,^U. \([^\"][^/]*/\?\).*, conflicted=conflicted; [[ \" ${conflicted_files[@]} \" =~ \" \1 \" ]] || conflicted_files[${#conflicted_files[@]}]=\"\1\",p - s,^U. \"\([^/]\+/\?\).*\"$, conflicted=conflicted; [[ \" ${conflicted_files[@]} \" =~ \" \1 \" ]] || conflicted_files[${#conflicted_files[@]}]=\"\1\",p - s,^.U \([^\"][^/]*/\?\).*, conflicted=conflicted; [[ \" ${conflicted_files[@]} \" =~ \" \1 \" ]] || conflicted_files[${#conflicted_files[@]}]=\"\1\",p - s,^.U \"\([^/]\+/\?\).*\"$, conflicted=conflicted; [[ \" ${conflicted_files[@]} \" =~ \" \1 \" ]] || conflicted_files[${#conflicted_files[@]}]=\"\1\",p - s,^D. \([^\"][^/]*/\?\).*, deleted=deleted; [[ \" ${deleted_files[@]} \" =~ \" \1 \" ]] || deleted_files[${#conflicted_files[@]}]=\"\1\",p - s,^D. \"\([^/]\+/\?\).*\"$, deleted=deleted; [[ \" ${deleted_files[@]} \" =~ \" \1 \" ]] || deleted_files[${#conflicted_files[@]}]=\"\1\",p - s,^[MARC]. \([^\"][^/]*/\?\).*, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p - s,^[MARC]. \"\([^/]\+/\?\).*\"$, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p - s,^.[MA] \([^\"][^/]*/\?\).*, modified=modified; [[ \" ${modified_files[@]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\",p - s,^.[MA] \"\([^/]\+/\?\).*\"$, modified=modified; [[ \" ${modified_files[@]} \" =~ \" \1 \" ]] || modified_files[${#modified_files[@]}]=\"\1\",p - s,^?? \([^\"][^/]*/\?\).*, untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\",p - s,^?? \"\([^/]\+/\?\).*\"$, untracked=untracked; [[ \" ${untracked_files[@]} \" =~ \" \1 \" ]] || untracked_files[${#untracked_files[@]}]=\"\1\",p + s,^U. \([^\"][^/]*/\?\).*, conflicted=conflicted; conflicted_files+=(\"\1\"),p + s,^U. \"\([^/]\+/\?\).*\"$, conflicted=conflicted; conflicted_files+=(\"\1\"),p + s,^.U \([^\"][^/]*/\?\).*, conflicted=conflicted; conflicted_files+=(\"\1\"),p + s,^.U \"\([^/]\+/\?\).*\"$, conflicted=conflicted; conflicted_files+=(\"\1\"),p + s,^D. \([^\"][^/]*/\?\).*, deleted=deleted; deleted_files+=(\"\1\"),p + s,^D. \"\([^/]\+/\?\).*\"$, deleted=deleted; deleted_files+=(\"\1\"),p + s,^[MARC]. \([^\"][^/]*/\?\).*, added=added; added_files+=(\"\1\"),p + s,^[MARC]. \"\([^/]\+/\?\).*\"$, added=added; added_files+=(\"\1\"),p + s,^.[MA] \([^\"][^/]*/\?\).*, modified=modified; modified_files+=(\"\1\"),p + s,^.[MA] \"\([^/]\+/\?\).*\"$, modified=modified; modified_files+=(\"\1\"),p + s,^?? \([^\"][^/]*/\?\).*, untracked=untracked; untracked_files+=(\"\1\"),p + s,^?? \"\([^/]\+/\?\).*\"$, untracked=untracked; untracked_files+=(\"\1\"),p ' # |tee /dev/tty )" From 3d2c9d4a2d97e53ec703a02acc504c0f1f5611be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 13 Oct 2013 19:33:56 +0200 Subject: [PATCH 063/118] -Fix: slashes in cwd were not colorized when cwd was truncated (weird bash bug?) --- git-prompt.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 44d1f19..d3ad8a4 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -1061,11 +1061,11 @@ prompt_command_function() { # else eval cwd_cmd, cwd should have path after exection eval "${cwd_cmd/\\/cwd=\\\\}" - + local slash='/' if [[ -w "$PWD" ]]; then - cwd=${cwd//\//$slash_color\/$dir_color} + cwd="${cwd//$slash/$slash_color$slash$dir_color}" else - cwd=${cwd//\//$slash_color_readonly\/$dir_color} + cwd="${cwd//$slash/$slash_color_readonly$slash$dir_color}" fi # in effect, echo collapses spaces inside the string and removes them from the start/end From 721560f2adc1e215bd0dab4d42720412f9da1769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 13 Oct 2013 21:40:27 +0200 Subject: [PATCH 064/118] -Add: command_time module that displays time elapsed while last command was running --- git-prompt.conf | 6 +++++- git-prompt.conf.mine | 6 +++++- git-prompt.sh | 33 ++++++++++++++++++++++++++++----- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index af8d1b0..00a7bcf 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -24,9 +24,10 @@ # make_module=off # jobs_module=on # rc_module=on +# command_time_module=on ### Order of modules -# prompt_modules_order="RC VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE PROMPT" +# prompt_modules_order="RC CTIME VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE PROMPT" ########################################################### DEFAULT OBJECTS ### Default user and hostname can be abbreviated or suppressed. @@ -75,6 +76,9 @@ ### Check for and display multiple hg heads # hg_multiple_heads_display=on +### Display elapsed time used by long-running command if it's above this threshold: +# command_time_threshold=15 + ########################################################### COLOR ### directory, exit code, root color diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine index fd6cf87..079545a 100644 --- a/git-prompt.conf.mine +++ b/git-prompt.conf.mine @@ -24,9 +24,10 @@ battery_module=on make_module=on # jobs_module=on rc_module=on +command_time_module=on ### order of modules -prompt_modules_order="RC VIRTUALENV WHO_WHERE JOBS BATTERY CWD VCS MAKE" +prompt_modules_order="RC CTIME VIRTUALENV WHO_WHERE JOBS BATTERY CWD VCS MAKE" ########################################################### DEFAULT OBJECTS ### Default user and hostname can be abbreviated or suppressed. @@ -75,6 +76,9 @@ hg_revision_display=num ### Check for and display multiple hg heads # hg_multiple_heads_display=on +### Display elapsed time used by long-running command if it's above this threshold: +# command_time_threshold=15 + ########################################################### COLOR ### directory, exit code, root color diff --git a/git-prompt.sh b/git-prompt.sh index d3ad8a4..bba6893 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -6,6 +6,7 @@ ##### read config file if any. unset make_color_ok make_color_dirty jobs_color_bkg jobs_color_stop slash_color slash_color_readonly at_color at_color_remote + unset command_time_color unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color unset modified_vcs_color added_vcs_color untracked_vcs_color deleted_vcs_color op_vcs_color detached_vcs_color hex_vcs_color unset rawhex_len @@ -28,13 +29,14 @@ make_module=${make_module:-off} jobs_module=${jobs_module:-on} rc_module=${rc_module:-on} + command_time_module=${command_time_module:-on} error_bell=${error_bell:-off} cwd_cmd=${cwd_cmd:-\\w} default_host_abbrev_mode=${default_host_abbrev_mode:-delete} default_id_abbrev_mode=${default_id_abbrev_mode:-delete} - prompt_modules_order=${prompt_modules_order:-RC VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE} + prompt_modules_order=${prompt_modules_order:-RC CTIME VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE} #### check for acpi, make, disable corresponding module if not installed if [[ -z $(which acpi 2> /dev/null) || -z $(acpi -b) ]]; then @@ -61,6 +63,7 @@ jobs_color_stop=${jobs_color:-red} make_color_ok=${make_color_ok:-BLACK} make_color_dirty=${make_color_dirty:-RED} + command_time_color=${command_time_color:-YELLOW} else # only B/W dir_color=${dir_color:-bw_bold} @@ -93,6 +96,8 @@ rawhex_len=${rawhex_len:-5} hg_revision_display=${hg_revision_display:-none} hg_multiple_heads_display=${hg_multiple_heads_display:-on} + command_time_threshold=${command_time_threshold:-15} + aj_max=20 @@ -200,7 +205,7 @@ # assemble prompt command string based on the module order specified above - # RC, VIRTUALENV and VCS has to be flanked by spaces on either side + # RC, CTIME, VIRTUALENV and VCS has to be flanked by spaces on either side # except if they are at the start or end of the sequence. # excess spaces (which may occur if some of the modules produce empty output) # will be trimmed at runtime, in the prompt_command_function. @@ -208,6 +213,7 @@ prompt_command_string=$(echo $prompt_modules_order | sed ' s/RC/\$space\$rc\$space/; + s/CTIME/$space$command_time$space/; s/VIRTUALENV/\$space\$virtualenv_string\$space/; s/VCS/\$space\$head_local\$space/; s/WHO_WHERE/\$color_who_where\$colors_reset/; @@ -581,6 +587,16 @@ check_make_status() { fi } +meas_command_time() { + if [[ ${_gp_timestamp} ]]; then + local elapsed_time=$(($SECONDS - ${_gp_timestamp})) + if [[ $elapsed_time -gt $command_time_threshold ]]; then + command_time="${!command_time_color}${elapsed_time}s$colors_reset" + fi + fi + unset _gp_timestamp +} + parse_svn_status() { local svn_info_str myrc rev @@ -988,8 +1004,9 @@ disable_set_shell_label() { enable_set_shell_label() { disable_set_shell_label # check for BASH_SOURCE being empty, no point running set_shell_label on every line of .bashrc - trap '[[ -z "$BASH_SOURCE" && ($BASH_COMMAND != prompt_command_function) ]] && - set_shell_label $BASH_COMMAND' DEBUG >& /dev/null + # also set up timer here for command_time module + trap '[[ -z "$BASH_SOURCE" && ($BASH_COMMAND != prompt_command_function) ]] && set_shell_label $BASH_COMMAND; + _gp_timestamp=${_gp_timestamp:-$SECONDS}' DEBUG >& /dev/null } declare -ft disable_set_shell_label @@ -1052,6 +1069,12 @@ prompt_command_function() { jobs_indicator="" fi + if [[ $command_time_module == "on" ]]; then + meas_command_time + else + command_time="" + fi + # autojump if [[ ${aj_dir_list[aj_idx%aj_max]} != $PWD ]] ; then aj_dir_list[++aj_idx%aj_max]="$PWD" @@ -1077,7 +1100,7 @@ prompt_command_function() { # old static string with default order left here for reference ###PS1="$colors_reset$rc$virtualenv_string$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$make_indicator$prompt_color$prompt_char $colors_reset" - unset head_local raw_rc + unset head_local raw_rc jobs_indicator virtualenv_string make_indicator battery_indicator command_time } # provide functions to turn the fancy prompt functions on and off From 9fdca714bc8c3122b8bed6ec5dc89c2e56abe7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 13 Oct 2013 23:23:20 +0200 Subject: [PATCH 065/118] -Add: load module --- git-prompt.conf | 4 +++- git-prompt.conf.mine | 4 +++- git-prompt.sh | 47 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index 00a7bcf..b85dd53 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -25,9 +25,11 @@ # jobs_module=on # rc_module=on # command_time_module=on +# load_module=on + ### Order of modules -# prompt_modules_order="RC CTIME VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE PROMPT" +# prompt_modules_order="RC LOAD CTIME VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE PROMPT" ########################################################### DEFAULT OBJECTS ### Default user and hostname can be abbreviated or suppressed. diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine index 079545a..2993ae6 100644 --- a/git-prompt.conf.mine +++ b/git-prompt.conf.mine @@ -25,9 +25,11 @@ make_module=on # jobs_module=on rc_module=on command_time_module=on +load_module=on + ### order of modules -prompt_modules_order="RC CTIME VIRTUALENV WHO_WHERE JOBS BATTERY CWD VCS MAKE" +prompt_modules_order="RC LOAD CTIME VIRTUALENV WHO_WHERE JOBS BATTERY CWD VCS MAKE" ########################################################### DEFAULT OBJECTS ### Default user and hostname can be abbreviated or suppressed. diff --git a/git-prompt.sh b/git-prompt.sh index bba6893..27b2532 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -30,13 +30,14 @@ jobs_module=${jobs_module:-on} rc_module=${rc_module:-on} command_time_module=${command_time_module:-on} + load_module=${load_module:-on} error_bell=${error_bell:-off} cwd_cmd=${cwd_cmd:-\\w} default_host_abbrev_mode=${default_host_abbrev_mode:-delete} default_id_abbrev_mode=${default_id_abbrev_mode:-delete} - prompt_modules_order=${prompt_modules_order:-RC CTIME VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE} + prompt_modules_order=${prompt_modules_order:-RC LOAD CTIME VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE} #### check for acpi, make, disable corresponding module if not installed if [[ -z $(which acpi 2> /dev/null) || -z $(acpi -b) ]]; then @@ -205,7 +206,7 @@ # assemble prompt command string based on the module order specified above - # RC, CTIME, VIRTUALENV and VCS has to be flanked by spaces on either side + # RC, LOAD, CTIME, VIRTUALENV and VCS has to be flanked by spaces on either side # except if they are at the start or end of the sequence. # excess spaces (which may occur if some of the modules produce empty output) # will be trimmed at runtime, in the prompt_command_function. @@ -213,6 +214,7 @@ prompt_command_string=$(echo $prompt_modules_order | sed ' s/RC/\$space\$rc\$space/; + s/LOAD/$space$load_indicator$space/; s/CTIME/$space$command_time$space/; s/VIRTUALENV/\$space\$virtualenv_string\$space/; s/VCS/\$space\$head_local\$space/; @@ -597,6 +599,39 @@ meas_command_time() { unset _gp_timestamp } +# TODO make this more configurable +create_load_indicator () { + local load_color load_value load_str load_mark i j + local -a load_colors load_thresholds + load_colors=(BLACK red RED whiteonred) + load_thresholds=(100 200 300 400) + + load_str=$(uptime) + load_str=${load_str:45:4} + load_value=${load_str/\./} + load_value=${load_value#0} + + if [[ $load_value -lt ${load_thresholds[0]} ]]; then + load_indicator="" + return + fi + + for ((i = ${#load_thresholds[@]} ; i > 0 ; i--)); do + j=$((i-1)) + if [[ $load_value -gt ${load_thresholds[$j]} ]]; then + load_color=${!load_colors[$j]} + break + fi + done + + if [[ $utf8_prompt ]]; then + load_mark="☢" + else + load_mark="L" + fi + load_indicator="$load_color$load_mark$load_str$colors_reset" +} + parse_svn_status() { local svn_info_str myrc rev @@ -1075,6 +1110,12 @@ prompt_command_function() { command_time="" fi + if [[ $load_module == "on" ]]; then + create_load_indicator + else + load_indicator="" + fi + # autojump if [[ ${aj_dir_list[aj_idx%aj_max]} != $PWD ]] ; then aj_dir_list[++aj_idx%aj_max]="$PWD" @@ -1100,7 +1141,7 @@ prompt_command_function() { # old static string with default order left here for reference ###PS1="$colors_reset$rc$virtualenv_string$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$make_indicator$prompt_color$prompt_char $colors_reset" - unset head_local raw_rc jobs_indicator virtualenv_string make_indicator battery_indicator command_time + unset head_local raw_rc jobs_indicator virtualenv_string make_indicator battery_indicator command_time load_indicator } # provide functions to turn the fancy prompt functions on and off From 83b37c26e3c5ea3d72238b19d64cbfa9067bf311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 13 Oct 2013 23:39:49 +0200 Subject: [PATCH 066/118] [svn_module] -Fix: svnversion 1.7 produces different output in unversioned dirs --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 27b2532..96d7430 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -648,7 +648,7 @@ parse_svn_status() { case $svn_method in svnversion) rev=$(svnversion) - [[ "$rev" == "exported" ]] && return 1 + [[ "$rev" == "exported" || "$rev" =~ "Unversioned" ]] && return 1 ;; info) svn_info_str=$(svn info 2> /dev/null) From 1e0daa372e7b10dbbf242f4d4498eb87d024c05d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 13 Oct 2013 23:54:51 +0200 Subject: [PATCH 067/118] -Fix: broken non-portable method of extracting load from uptime output --- git-prompt.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 96d7430..abf4ad3 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -606,10 +606,9 @@ create_load_indicator () { load_colors=(BLACK red RED whiteonred) load_thresholds=(100 200 300 400) - load_str=$(uptime) - load_str=${load_str:45:4} + load_str=$(uptime | sed -ne 's/.* load average: \([0-9]\.[0-9]\{1,2\}\).*/\1/p') load_value=${load_str/\./} - load_value=${load_value#0} + load_value=${load_value##0} if [[ $load_value -lt ${load_thresholds[0]} ]]; then load_indicator="" From 4ef7cb31dc5cc316fef82c645349edd3a992b9ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Mon, 14 Oct 2013 00:36:21 +0200 Subject: [PATCH 068/118] -Change: use utf-8 block chars to display load --- git-prompt.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index abf4ad3..3d116b0 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -601,7 +601,7 @@ meas_command_time() { # TODO make this more configurable create_load_indicator () { - local load_color load_value load_str load_mark i j + local load_color load_value load_str load_bar load_mark i j local -a load_colors load_thresholds load_colors=(BLACK red RED whiteonred) load_thresholds=(100 200 300 400) @@ -625,6 +625,14 @@ create_load_indicator () { if [[ $utf8_prompt ]]; then load_mark="☢" + local load_int=$((load_value / 100 - 1)) + local load_frac=$((load_value % 100)) + load_frac=$((load_frac / 13)) + local -a load_chars=( " " "▏" "▎" "▍" "▌" "▋" "▊" "▉" "█" ) + + printf -v load_str "%${load_int}s" + load_str=${load_str// /█} + load_str+=${load_chars[$load_frac]} else load_mark="L" fi From db572025a89b4a18e38b28db704abaa4344502e9 Mon Sep 17 00:00:00 2001 From: Juhasz Peter Date: Mon, 14 Oct 2013 12:52:12 +0200 Subject: [PATCH 069/118] [load_module] -Fix: remove all leading zeros from load_value to avoid occasional error message (when value was 08 or 09) --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 3d116b0..a740b50 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -608,7 +608,7 @@ create_load_indicator () { load_str=$(uptime | sed -ne 's/.* load average: \([0-9]\.[0-9]\{1,2\}\).*/\1/p') load_value=${load_str/\./} - load_value=${load_value##0} + load_value=${load_value##0*} if [[ $load_value -lt ${load_thresholds[0]} ]]; then load_indicator="" From 463c27234ed9381406a4e4ae4a634a8e4f877dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Mon, 14 Oct 2013 22:38:48 +0200 Subject: [PATCH 070/118] [load_module] -Fix: configurable colors and style --- git-prompt.conf | 12 ++++++++++++ git-prompt.conf.mine | 12 ++++++++++++ git-prompt.sh | 30 +++++++++++++++++++----------- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index b85dd53..deab4f1 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -81,6 +81,18 @@ ### Display elapsed time used by long-running command if it's above this threshold: # command_time_threshold=15 +### Colors and color change thresholds for load display. +### If the load is under the first value in the list, the display is supressed. +# load_colors=(BLACK red RED whiteonred) +# load_thresholds=(100 200 300 400) + +### Display style for load +### valid options: +### * markonly # only display the mark, supress the value +### * numeric # display mark and numeric value +### * bar # display mark and unicode bar chart +# load_display_style=bar + ########################################################### COLOR ### directory, exit code, root color diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine index 2993ae6..555a6fc 100644 --- a/git-prompt.conf.mine +++ b/git-prompt.conf.mine @@ -81,6 +81,18 @@ hg_revision_display=num ### Display elapsed time used by long-running command if it's above this threshold: # command_time_threshold=15 +### Colors and color change thresholds for load display. +### If the load is under the first value in the list, the display is supressed. +# load_colors=(BLACK red RED whiteonred) +# load_thresholds=(100 200 300 400) + +### Display style for load +### valid options: +### * markonly # only display the mark, supress the value +### * numeric # display mark and numeric value +### * bar # display mark and unicode bar chart +# load_display_style=bar + ########################################################### COLOR ### directory, exit code, root color diff --git a/git-prompt.sh b/git-prompt.sh index a740b50..fb7fef8 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -99,6 +99,13 @@ hg_multiple_heads_display=${hg_multiple_heads_display:-on} command_time_threshold=${command_time_threshold:-15} + if [[ -z "$load_colors" ]]; then + load_colors=(BLACK red RED whiteonred) + fi + if [[ -z "$load_thresholds" ]]; then + load_thresholds=(100 200 300 400) + fi + load_display_style=${load_display_style:-bar} aj_max=20 @@ -599,12 +606,8 @@ meas_command_time() { unset _gp_timestamp } -# TODO make this more configurable create_load_indicator () { local load_color load_value load_str load_bar load_mark i j - local -a load_colors load_thresholds - load_colors=(BLACK red RED whiteonred) - load_thresholds=(100 200 300 400) load_str=$(uptime | sed -ne 's/.* load average: \([0-9]\.[0-9]\{1,2\}\).*/\1/p') load_value=${load_str/\./} @@ -625,17 +628,22 @@ create_load_indicator () { if [[ $utf8_prompt ]]; then load_mark="☢" - local load_int=$((load_value / 100 - 1)) - local load_frac=$((load_value % 100)) - load_frac=$((load_frac / 13)) - local -a load_chars=( " " "▏" "▎" "▍" "▌" "▋" "▊" "▉" "█" ) + if [[ $load_display_style == "bar" ]]; then + local load_int=$((load_value / 100 - 1)) + local load_frac=$((load_value % 100)) + load_frac=$((load_frac / 12)) + local -a load_chars=( " " "▏" "▎" "▍" "▌" "▋" "▊" "▉" "█" ) - printf -v load_str "%${load_int}s" - load_str=${load_str// /█} - load_str+=${load_chars[$load_frac]} + printf -v load_str "%${load_int}s" + load_str=${load_str// /█} + load_str+=${load_chars[$load_frac]} + fi else load_mark="L" fi + + if [[ $load_display_style == "markonly" ]]; then load_str= ; fi + load_indicator="$load_color$load_mark$load_str$colors_reset" } From 07bf1e2d0a8ea4f974bce43b07ab7e5354fdadef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Mon, 14 Oct 2013 22:40:55 +0200 Subject: [PATCH 071/118] [conf] -Fix: removed obsolete PROMPT from order string --- git-prompt.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.conf b/git-prompt.conf index deab4f1..f548e1c 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -29,7 +29,7 @@ ### Order of modules -# prompt_modules_order="RC LOAD CTIME VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE PROMPT" +# prompt_modules_order="RC LOAD CTIME VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE" ########################################################### DEFAULT OBJECTS ### Default user and hostname can be abbreviated or suppressed. From e25ecabe33ceeaa5ad7f3872038b72461c21d376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Mon, 14 Oct 2013 22:51:43 +0200 Subject: [PATCH 072/118] -Fix: minor indentation (the whole thing is in dire need of reformatting though) --- git-prompt.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index fb7fef8..db7854b 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -72,9 +72,9 @@ fi unset cols - #### prompt character, for root/non-root - prompt_char=${prompt_char:-'>'} - root_prompt_char=${root_prompt_char:-'>'} + #### prompt character, for root/non-root + prompt_char=${prompt_char:-'>'} + root_prompt_char=${root_prompt_char:-'>'} #### vcs colors init_vcs_color=${init_vcs_color:-WHITE} # initial @@ -83,7 +83,7 @@ added_vcs_color=${added_vcs_color:-green} # Changes to be committed: untracked_vcs_color=${untracked_vcs_color:-BLUE} # Untracked files: deleted_vcs_color=${deleted_vcs_color:-yellow} # Deleted files: - conflicted_vcs_color=${conflicted_vcs_color:-CYAN} # Conflicted files: + conflicted_vcs_color=${conflicted_vcs_color:-CYAN} # Conflicted files: op_vcs_color=${op_vcs_color:-MAGENTA} detached_vcs_color=${detached_vcs_color:-RED} @@ -186,7 +186,7 @@ CYAN='\['`tput setaf 6; tput bold`'\]' WHITE='\['`tput setaf 7; tput bold`'\]' - whiteonred='\['`tput setaf 7; tput setab 1; tput bold`'\]' + whiteonred='\['`tput setaf 7; tput setab 1; tput bold`'\]' dim='\['`tput sgr0; tput setaf p1`'\]' # half-bright From 0ec7e36f3c8be01c3ed0950f661b624025b10320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Wed, 16 Oct 2013 21:10:05 +0200 Subject: [PATCH 073/118] [load_module] -Fix: properly remove leading zeroes from load value (prev solution was broken) --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index db7854b..d1e7a1e 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -611,7 +611,7 @@ create_load_indicator () { load_str=$(uptime | sed -ne 's/.* load average: \([0-9]\.[0-9]\{1,2\}\).*/\1/p') load_value=${load_str/\./} - load_value=${load_value##0*} + load_value=$((10#$load_value)) if [[ $load_value -lt ${load_thresholds[0]} ]]; then load_indicator="" From 54ec53c2e7a0c82831e83df7cc61a5922493e024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Thu, 17 Oct 2013 22:57:36 +0200 Subject: [PATCH 074/118] -Fix: small optimization to vcs status parsing: don't set status variables every time, just once at the end --- git-prompt.sh | 79 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index d1e7a1e..7679d17 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -687,15 +687,22 @@ parse_svn_status() { unset status modified added clean init deleted untracked conflicted op detached eval `svn status 2>/dev/null | sed -n ' - s/^A... \([^.].*\)/added=added; added_files+=(\"\1\");/p - s/^M... \([^.].*\)/modified=modified; modified_files+=(\"\1\");/p - s/^R... \([^.].*\)/added=added;/p - s/^D... \([^.].*\)/deleted=deleted; deleted_files+=(\"\1\");/p - s/^C... \([^.].*\)/conflicted=conflicted; conflicted_files+=(\"\1\");/p - s/^\!... \([^.].*\)/deleted=deleted; deleted_files+=(\"\1\");/p - s/^\?... \([^.].*\)/untracked=untracked; untracked_files+=(\"\1\");/p + s/^A... \([^.].*\)/ added_files+=(\"\1\");/p + s/^M... \([^.].*\)/ modified_files+=(\"\1\");/p + s/^R... \([^.].*\)/ added=added;/p + s/^D... \([^.].*\)/ deleted_files+=(\"\1\");/p + s/^C... \([^.].*\)/ conflicted_files+=(\"\1\");/p + s/^\!... \([^.].*\)/ deleted_files+=(\"\1\");/p + s/^\?... \([^.].*\)/ untracked_files+=(\"\1\");/p ' ` + + modified=${modified_files[0]:+modified} + added=${added_files[0]:+added} + deleted=${deleted_files[0]:+deleted} + untracked=${untracked_files[0]:+untracked} + conflicted=${conflicted_files[0]:+conflicted} + # TODO branch detection if standard repo layout [[ -z $modified ]] && \ @@ -720,13 +727,31 @@ parse_hg_status() { eval `hg status 2>/dev/null | sed -n ' - s/^M \([^.].*\)/modified=modified; modified_files+=(\"\1\");/p - s/^A \([^.].*\)/added=added; added_files+=(\"\1\");/p - s/^R \([^.].*\)/deleted=deleted; deleted_files+=(\"\1\");/p - s/^\! \([^.].*\)/deleted=deleted; deleted_files+=(\"\1\");/p - s/^\? \([^.].*\)/untracked=untracked; untracked_files+=(\"\1\");/p + s/^M \([^.].*\)/ modified_files+=(\"\1\");/p + s/^A \([^.].*\)/ added_files+=(\"\1\");/p + s/^R \([^.].*\)/ deleted_files+=(\"\1\");/p + s/^\! \([^.].*\)/ deleted_files+=(\"\1\");/p + s/^\? \([^.].*\)/ untracked_files+=(\"\1\");/p '` +### EXPERIMENTAL: it is actually faster, especially for many files +# eval `hg status 2>/dev/null | +# perl -lne ' +# push @{$x{substr($_,0,1)}}, substr($_,2); +# END { +# print qq/modified_files=(/, (map {qq/ "$_" /} @{$x{M}}), q/);/; +# print qq/added_files=(/, (map {qq/ "$_" /} @{$x{A}}), q/);/; +# print qq/deleted_files=(/, (map {qq/ "$_" /} @{$x{R}}, @{$x{"!"}}), q/);/; +# print qq/untracked_files=(/, (map {qq/ "$_" /} @{$x{"?"}}), q/);/; +# } +# '` + + + modified=${modified_files[0]:+modified} + added=${added_files[0]:+added} + deleted=${deleted_files[0]:+deleted} + untracked=${untracked_files[0]:+untracked} + local branch bookmark branch=`hg branch 2> /dev/null` @@ -846,21 +871,27 @@ parse_git_status() { eval " $( LANG=C git status --porcelain 2>/dev/null | sed -n ' - s,^U. \([^\"][^/]*/\?\).*, conflicted=conflicted; conflicted_files+=(\"\1\"),p - s,^U. \"\([^/]\+/\?\).*\"$, conflicted=conflicted; conflicted_files+=(\"\1\"),p - s,^.U \([^\"][^/]*/\?\).*, conflicted=conflicted; conflicted_files+=(\"\1\"),p - s,^.U \"\([^/]\+/\?\).*\"$, conflicted=conflicted; conflicted_files+=(\"\1\"),p - s,^D. \([^\"][^/]*/\?\).*, deleted=deleted; deleted_files+=(\"\1\"),p - s,^D. \"\([^/]\+/\?\).*\"$, deleted=deleted; deleted_files+=(\"\1\"),p - s,^[MARC]. \([^\"][^/]*/\?\).*, added=added; added_files+=(\"\1\"),p - s,^[MARC]. \"\([^/]\+/\?\).*\"$, added=added; added_files+=(\"\1\"),p - s,^.[MA] \([^\"][^/]*/\?\).*, modified=modified; modified_files+=(\"\1\"),p - s,^.[MA] \"\([^/]\+/\?\).*\"$, modified=modified; modified_files+=(\"\1\"),p - s,^?? \([^\"][^/]*/\?\).*, untracked=untracked; untracked_files+=(\"\1\"),p - s,^?? \"\([^/]\+/\?\).*\"$, untracked=untracked; untracked_files+=(\"\1\"),p + s,^U. \([^\"][^/]*/\?\).*, conflicted_files+=(\"\1\"),p + s,^U. \"\([^/]\+/\?\).*\"$, conflicted_files+=(\"\1\"),p + s,^.U \([^\"][^/]*/\?\).*, conflicted_files+=(\"\1\"),p + s,^.U \"\([^/]\+/\?\).*\"$, conflicted_files+=(\"\1\"),p + s,^D. \([^\"][^/]*/\?\).*, deleted_files+=(\"\1\"),p + s,^D. \"\([^/]\+/\?\).*\"$, deleted_files+=(\"\1\"),p + s,^[MARC]. \([^\"][^/]*/\?\).*, added_files+=(\"\1\"),p + s,^[MARC]. \"\([^/]\+/\?\).*\"$, added_files+=(\"\1\"),p + s,^.[MA] \([^\"][^/]*/\?\).*, modified_files+=(\"\1\"),p + s,^.[MA] \"\([^/]\+/\?\).*\"$, modified_files+=(\"\1\"),p + s,^?? \([^\"][^/]*/\?\).*, untracked_files+=(\"\1\"),p + s,^?? \"\([^/]\+/\?\).*\"$, untracked_files+=(\"\1\"),p ' # |tee /dev/tty )" + modified=${modified_files[0]:+modified} + added=${added_files[0]:+added} + deleted=${deleted_files[0]:+deleted} + untracked=${untracked_files[0]:+untracked} + conflicted=${conflicted_files[0]:+conflicted} + if ! grep -q "^ref:" "$git_dir/HEAD" 2>/dev/null; then detached=detached fi From 75e6a81b31dc5dd985e0ba196fefec6b3c801232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Thu, 17 Oct 2013 22:59:43 +0200 Subject: [PATCH 075/118] [load_module] -Fix: suppress display of load if it's exactly load_threshold[0] --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 7679d17..a5c8474 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -613,7 +613,7 @@ create_load_indicator () { load_value=${load_str/\./} load_value=$((10#$load_value)) - if [[ $load_value -lt ${load_thresholds[0]} ]]; then + if [[ $load_value -le ${load_thresholds[0]} ]]; then load_indicator="" return fi From 7bf9d6edfebdc6786d38cc02bd44633a600e9800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Thu, 17 Oct 2013 23:34:17 +0200 Subject: [PATCH 076/118] [git_module] -Add: stash detection and display --- git-prompt.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/git-prompt.sh b/git-prompt.sh index a5c8474..44a528b 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -837,10 +837,12 @@ parse_git_status() { git_up_char="↑" git_dn_char="↓" git_updn_char="↕" + git_stash_char="☡"; else git_up_char="^" git_dn_char="v" git_updn_char="*" + git_stash_char="$" fi @@ -954,6 +956,10 @@ parse_git_status() { # branch=$(git symbolic-ref -q HEAD || { echo -n "detached:" ; git name-rev --name-only HEAD 2>/dev/null; } ) # branch=${branch#refs/heads/} + ### stash + local stash_num + stash_num=$(git stash list 2>/dev/null | wc -l) + ### compose vcs_info if [[ $init ]]; then @@ -973,6 +979,9 @@ parse_git_status() { fi vcs_info="$branch$freshness$rawhex" + if [[ $stash_num -gt 0 ]]; then + vcs_info+="${white}$git_stash_char$stash_num" + fi fi } From 303e74c4a1e3fe692edc9cec6aa46d3bfa281ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Fri, 18 Oct 2013 23:05:54 +0200 Subject: [PATCH 077/118] -Add: clock module with optional alert interval --- git-prompt.conf | 13 ++++++++++++- git-prompt.conf.mine | 12 +++++++++++- git-prompt.sh | 45 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index f548e1c..ff18830 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -25,11 +25,12 @@ # jobs_module=on # rc_module=on # command_time_module=on +# clock_module=off # load_module=on ### Order of modules -# prompt_modules_order="RC LOAD CTIME VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE" +# prompt_modules_order="RC LOAD CLOCK CTIME VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE" ########################################################### DEFAULT OBJECTS ### Default user and hostname can be abbreviated or suppressed. @@ -93,6 +94,15 @@ ### * bar # display mark and unicode bar chart # load_display_style=bar + +### Clock options +### Display style - analog or digital +# clock_style=analog + +### Alert interval, in minutes +### if 0, clock is always shown, otherwise it's displayed only every x minutes +# clock_alert_interval=30 + ########################################################### COLOR ### directory, exit code, root color @@ -113,6 +123,7 @@ # jobs_color_stop=red # at_color=green # at_color_remote=RED + # clock_color=BLACK # else # B/W terminal # dir_color=bw_bold # rc_color=bw_bold diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine index 555a6fc..5d74e5d 100644 --- a/git-prompt.conf.mine +++ b/git-prompt.conf.mine @@ -26,10 +26,11 @@ make_module=on rc_module=on command_time_module=on load_module=on +clock_module=on ### order of modules -prompt_modules_order="RC LOAD CTIME VIRTUALENV WHO_WHERE JOBS BATTERY CWD VCS MAKE" +prompt_modules_order="RC LOAD CLOCK CTIME VIRTUALENV WHO_WHERE JOBS BATTERY CWD VCS MAKE" ########################################################### DEFAULT OBJECTS ### Default user and hostname can be abbreviated or suppressed. @@ -93,6 +94,14 @@ hg_revision_display=num ### * bar # display mark and unicode bar chart # load_display_style=bar +### Clock options +### Display style - analog or digital +clock_style=analog + +### Alert interval, in minutes +### if 0, clock is always shown, otherwise it's displayed only every x minutes +clock_alert_interval=30 + ########################################################### COLOR ### directory, exit code, root color @@ -113,6 +122,7 @@ hg_revision_display=num jobs_color_stop=red at_color=green at_color_remote=RED + clock_color=WHITE # else # B/W terminal # dir_color=bw_bold diff --git a/git-prompt.sh b/git-prompt.sh index 44a528b..24ce668 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -6,7 +6,7 @@ ##### read config file if any. unset make_color_ok make_color_dirty jobs_color_bkg jobs_color_stop slash_color slash_color_readonly at_color at_color_remote - unset command_time_color + unset command_time_color clock_color unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color unset modified_vcs_color added_vcs_color untracked_vcs_color deleted_vcs_color op_vcs_color detached_vcs_color hex_vcs_color unset rawhex_len @@ -31,6 +31,7 @@ rc_module=${rc_module:-on} command_time_module=${command_time_module:-on} load_module=${load_module:-on} + clock_module=${clock_module:-off} error_bell=${error_bell:-off} cwd_cmd=${cwd_cmd:-\\w} @@ -65,6 +66,7 @@ make_color_ok=${make_color_ok:-BLACK} make_color_dirty=${make_color_dirty:-RED} command_time_color=${command_time_color:-YELLOW} + clock_color=${clock_color:-BLACK} else # only B/W dir_color=${dir_color:-bw_bold} @@ -98,6 +100,8 @@ hg_revision_display=${hg_revision_display:-none} hg_multiple_heads_display=${hg_multiple_heads_display:-on} command_time_threshold=${command_time_threshold:-15} + clock_style=${clock_style:-analog} + clock_alert_interval=${clock_alert_interval:-30} if [[ -z "$load_colors" ]]; then load_colors=(BLACK red RED whiteonred) @@ -213,7 +217,7 @@ # assemble prompt command string based on the module order specified above - # RC, LOAD, CTIME, VIRTUALENV and VCS has to be flanked by spaces on either side + # RC, LOAD, CLOCK, CTIME, VIRTUALENV and VCS has to be flanked by spaces on either side # except if they are at the start or end of the sequence. # excess spaces (which may occur if some of the modules produce empty output) # will be trimmed at runtime, in the prompt_command_function. @@ -222,6 +226,7 @@ sed ' s/RC/\$space\$rc\$space/; s/LOAD/$space$load_indicator$space/; + s/CLOCK/$space$clock_indicator$space/; s/CTIME/$space$command_time$space/; s/VIRTUALENV/\$space\$virtualenv_string\$space/; s/VCS/\$space\$head_local\$space/; @@ -237,6 +242,11 @@ s/\$space/ /g; ') + # save startup and midnight timestamp for clock + _gp_clock_timestamp_start=$(date +%s) + _gp_clock_timestamp_midnight=$(date -d 0:0 +%s) + _gp_clock_timestamp_last=${_gp_clock_timestamp_start} + #################################################################### MARKERS ellipse_marker_utf8="…" ellipse_marker_plain="..." @@ -606,6 +616,31 @@ meas_command_time() { unset _gp_timestamp } +create_clock() { + clock_indicator="" + + # this contrived calculation is done to avoid calling `date` every time + local current_time time_of_day index + current_time=$(($SECONDS + ${_gp_clock_timestamp_start})) + + if [[ $clock_alert_interval -gt 0 ]]; then + [[ $(( ($current_time - ${_gp_clock_timestamp_last})/(60 * $clock_alert_interval) )) -eq 0 ]] && return + fi + + if [[ $clock_style == "analog" ]]; then + # unicode clock face characters + # U+1F550 (ONE OCLOCK) .. U+1F55B (TWELVE OCLOCK), for the plain hours + # U+1F55C (ONE-THIRTY) .. U+1F567 (TWELVE-THIRTY), for the thirties + local clockfaces=(🕧 🕐 🕜 🕑 🕝 🕒 🕞 🕓 🕟 🕔 🕠 🕕 🕡 🕖 🕢 🕗 🕣 🕘 🕤 🕙 🕥 🕚 🕦 🕛) + time_of_day=$((${current_time} - ${_gp_clock_timestamp_midnight})) + index=$(( (($time_of_day - 900) % 43200) / 1800 )) + clock_indicator="${!clock_color}${clockfaces[$index]}${colors_reset}" + else + clock_indicator="${!clock_color}\t${colors_reset}" + fi + _gp_clock_timestamp_last=$current_time +} + create_load_indicator () { local load_color load_value load_str load_bar load_mark i j @@ -1171,6 +1206,12 @@ prompt_command_function() { load_indicator="" fi + if [[ $clock_module == "on" ]]; then + create_clock + else + clock_indicator="" + fi + # autojump if [[ ${aj_dir_list[aj_idx%aj_max]} != $PWD ]] ; then aj_dir_list[++aj_idx%aj_max]="$PWD" From aace46ab21b716dddde6d3acc11013a4c28f4438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Fri, 18 Oct 2013 23:42:54 +0200 Subject: [PATCH 078/118] [clock] -Fix: check for utf8, fall back to digital if unavailable --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 24ce668..9b28f24 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -627,7 +627,7 @@ create_clock() { [[ $(( ($current_time - ${_gp_clock_timestamp_last})/(60 * $clock_alert_interval) )) -eq 0 ]] && return fi - if [[ $clock_style == "analog" ]]; then + if [[ $clock_style == "analog" && $utf8_prompt ]]; then # unicode clock face characters # U+1F550 (ONE OCLOCK) .. U+1F55B (TWELVE OCLOCK), for the plain hours # U+1F55C (ONE-THIRTY) .. U+1F567 (TWELVE-THIRTY), for the thirties From cf0df0a62131df3bca0de78a62e01b2f4c88ab34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Fri, 18 Oct 2013 23:56:05 +0200 Subject: [PATCH 079/118] [load] -Fix: stricter test for user-overridden defaults; better documentation in config --- git-prompt.conf | 2 ++ git-prompt.conf.mine | 2 ++ git-prompt.sh | 4 +--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index ff18830..fe048b5 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -80,10 +80,12 @@ # hg_multiple_heads_display=on ### Display elapsed time used by long-running command if it's above this threshold: +### (seconds) # command_time_threshold=15 ### Colors and color change thresholds for load display. ### If the load is under the first value in the list, the display is supressed. +### Both have to be arrays with the same number of elements # load_colors=(BLACK red RED whiteonred) # load_thresholds=(100 200 300 400) diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine index 5d74e5d..8097160 100644 --- a/git-prompt.conf.mine +++ b/git-prompt.conf.mine @@ -80,10 +80,12 @@ hg_revision_display=num # hg_multiple_heads_display=on ### Display elapsed time used by long-running command if it's above this threshold: +### (seconds) # command_time_threshold=15 ### Colors and color change thresholds for load display. ### If the load is under the first value in the list, the display is supressed. +### Both have to be arrays with the same number of elements # load_colors=(BLACK red RED whiteonred) # load_thresholds=(100 200 300 400) diff --git a/git-prompt.sh b/git-prompt.sh index 9b28f24..f2624fd 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -103,10 +103,8 @@ clock_style=${clock_style:-analog} clock_alert_interval=${clock_alert_interval:-30} - if [[ -z "$load_colors" ]]; then + if [[ -z "$load_colors" || -z "$load_thresholds" || ${#load_colors[@]} -ne ${#load_thresholds[@]} ]]; then load_colors=(BLACK red RED whiteonred) - fi - if [[ -z "$load_thresholds" ]]; then load_thresholds=(100 200 300 400) fi load_display_style=${load_display_style:-bar} From a9fdf3b444d04419fb6d52a8a877c380d7cb1ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Fri, 18 Oct 2013 23:59:43 +0200 Subject: [PATCH 080/118] [clock] -Fix: array index calculation for analog clock --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index f2624fd..e62b560 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -631,7 +631,7 @@ create_clock() { # U+1F55C (ONE-THIRTY) .. U+1F567 (TWELVE-THIRTY), for the thirties local clockfaces=(🕧 🕐 🕜 🕑 🕝 🕒 🕞 🕓 🕟 🕔 🕠 🕕 🕡 🕖 🕢 🕗 🕣 🕘 🕤 🕙 🕥 🕚 🕦 🕛) time_of_day=$((${current_time} - ${_gp_clock_timestamp_midnight})) - index=$(( (($time_of_day - 900) % 43200) / 1800 )) + index=$(( (($time_of_day - 4500) % 43200) / 1800 )) clock_indicator="${!clock_color}${clockfaces[$index]}${colors_reset}" else clock_indicator="${!clock_color}\t${colors_reset}" From cc4353873d7f33d285c9246bbc5c46f5fefeea60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 19 Oct 2013 00:09:12 +0200 Subject: [PATCH 081/118] -Fix: some cleanup (unset, local) --- git-prompt.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index e62b560..887fca3 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -515,10 +515,8 @@ create_battery_indicator () { # if laptop on battery: one of ▕▁▏▕▂▏▕▃▏▕▄▏▕▅▏▕▆▏▕▇▏▕█▏ # color: red if power < 30 %, else normal - local battery_string - local battery_percent - local battery_color - local tmp + local battery_string battery_percent battery_color battery_pwr_index tmp + local -a battery_diagrams battery_string=$(acpi -b) if [[ $battery_string ]]; then @@ -1107,7 +1105,7 @@ parse_vcs_status() { } parse_virtualenv_status() { - unset virtualenv + local virtualenv [[ $virtualenv_module = "on" ]] || return 1 @@ -1235,7 +1233,7 @@ prompt_command_function() { # old static string with default order left here for reference ###PS1="$colors_reset$rc$virtualenv_string$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$make_indicator$prompt_color$prompt_char $colors_reset" - unset head_local raw_rc jobs_indicator virtualenv_string make_indicator battery_indicator command_time load_indicator + unset head_local raw_rc jobs_indicator virtualenv_string make_indicator battery_indicator command_time load_indicator clock_indicator } # provide functions to turn the fancy prompt functions on and off From bc8a84749df6a6475ce1a212c250d7aa36ac35b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 19 Oct 2013 00:29:48 +0200 Subject: [PATCH 082/118] [vcs] -Fix: simplify revision parsing for svn and hg --- git-prompt.sh | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 887fca3..f0fd54e 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -681,17 +681,6 @@ create_load_indicator () { parse_svn_status() { local svn_info_str myrc rev - extract_rev() { - local lrev - eval ` - printf "%s" "$1" | - sed -n " - s/^Revision: /lrev=/p - " - ` - echo -n $lrev - } - case $svn_method in svnversion) rev=$(svnversion) [[ "$rev" == "exported" || "$rev" =~ "Unversioned" ]] && return 1 @@ -700,12 +689,14 @@ parse_svn_status() { info) svn_info_str=$(svn info 2> /dev/null) myrc=$? [[ $myrc -eq 0 ]] || return 1 - rev=$(extract_rev "$svn_info_str") + rev=${svn_info_str##*Revision: } + rev=${rev%%[[:space:]]*} ;; dotsvn) [[ -d .svn ]] || return 1 svn_info_str=$(svn info 2> /dev/null) - rev=$(extract_rev "$svn_info_str") + rev=${svn_info_str##*Revision: } + rev=${rev%%[[:space:]]*} ;; *) return 1 @@ -819,10 +810,12 @@ parse_hg_status() { # get the local rev number, global rev hash and tag in one go from hg id's output # if tag does not contain "tip", the working dir is not up to date - local id_str re num rev tags tip_regex not_uptodate - id_str=$(hg id -nit) - re="^([^ ]+) ([^ ]+) ?(.*)$" - [[ $id_str =~ $re ]] && rev="${BASH_REMATCH[1]}" && num="${BASH_REMATCH[2]}" && tags="${BASH_REMATCH[3]}" + local num rev tags tip_regex not_uptodate + local -a id_array + id_array=($(hg id -nit)) + rev="${id_array[0]}" + num="${id_array[1]}" + tags="${id_array[2]}" tip_regex=\\btip\\b if [[ ! $tags =~ $tip_regex ]]; then From 6c4dedf50336bd262819f0efb95cbfc6a017e0c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 19 Oct 2013 01:16:41 +0200 Subject: [PATCH 083/118] [clock] -Fix: array index calculation for analog clock (really fix it) --- git-prompt.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index f0fd54e..91cb814 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -628,8 +628,8 @@ create_clock() { # U+1F550 (ONE OCLOCK) .. U+1F55B (TWELVE OCLOCK), for the plain hours # U+1F55C (ONE-THIRTY) .. U+1F567 (TWELVE-THIRTY), for the thirties local clockfaces=(🕧 🕐 🕜 🕑 🕝 🕒 🕞 🕓 🕟 🕔 🕠 🕕 🕡 🕖 🕢 🕗 🕣 🕘 🕤 🕙 🕥 🕚 🕦 🕛) - time_of_day=$((${current_time} - ${_gp_clock_timestamp_midnight})) - index=$(( (($time_of_day - 4500) % 43200) / 1800 )) + time_of_day=$(( (${current_time} - ${_gp_clock_timestamp_midnight}) % 86400 )) + index=$(( (($time_of_day - 900) % 43200) / 1800 )) clock_indicator="${!clock_color}${clockfaces[$index]}${colors_reset}" else clock_indicator="${!clock_color}\t${colors_reset}" From b101a9af263a81aca75807e24639cf5abaa3c823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 19 Oct 2013 14:04:08 +0200 Subject: [PATCH 084/118] [load] -Fix: replaced full block character with inverse circle so that the integer part of the load can be more easily read at a glance --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 91cb814..9dba6b2 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -666,7 +666,7 @@ create_load_indicator () { local -a load_chars=( " " "▏" "▎" "▍" "▌" "▋" "▊" "▉" "█" ) printf -v load_str "%${load_int}s" - load_str=${load_str// /█} + load_str=${load_str// /◙} load_str+=${load_chars[$load_frac]} fi else From 4d0632f0c3c463b23bae184b7e341c1aff73b356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 19 Oct 2013 22:07:44 +0200 Subject: [PATCH 085/118] [hg] -Fix: instead of calling hg root, hg branch and hg id separately, get all info from hg log in one go --- git-prompt.sh | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 9dba6b2..29929e8 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -740,7 +740,29 @@ parse_svn_status() { parse_hg_status() { # ☿ - hg_root=`hg root 2>/dev/null` || return 1 + # Get all information we need in one go from hg log's output + # if we're not in a hg directory, this takes exactly the same time as 'hg root' would do, + # and if we're in a hg dir, we don't have to call 'hg branch' and 'hg id' separately. + local id_str + id_str=$(hg log --follow -l 1 --template '{rev}\x1f{node}\x1f{tags}\x1f{branch}\x1f{bookmarks}' 2> /dev/null) || return 1 + + # This contrived way is necessary because branch names and tags can contain spaces. + # The ASCII "Unit separator" \x1f was chosen as a "safe" separator character + # because it was intended for exactly this purpose. + # Nowadays nobody knows that such a character exists at all :) + local oldIFS + oldIFS="$IFS" + IFS=$'\x1f' + local -a id_array + id_array=($id_str) + IFS="$oldIFS" + + local branch bookmark num rev tags tip_regex not_uptodate + num="${id_array[0]}" + rev="${id_array[1]}" + tags="${id_array[2]}" + branch="${id_array[3]}" + bookmark="${id_array[4]}" vcs=hg @@ -774,12 +796,6 @@ parse_hg_status() { deleted=${deleted_files[0]:+deleted} untracked=${untracked_files[0]:+untracked} - local branch bookmark - - branch=`hg branch 2> /dev/null` - - [[ -f $hg_root/.hg/bookmarks.current ]] && bookmark=`cat "$hg_root/.hg/bookmarks.current"` - [[ -z $modified ]] && [[ -z $untracked ]] && [[ -z $added ]] && [[ -z $deleted ]] && clean=clean vcs_info=${branch/default/D} @@ -802,21 +818,11 @@ parse_hg_status() { if [[ $utf8_prompt ]]; then hg_vcs_char="☿" hg_up_char="⬆" - else hg_vcs_char=":" hg_up_char="^" fi - # get the local rev number, global rev hash and tag in one go from hg id's output - # if tag does not contain "tip", the working dir is not up to date - local num rev tags tip_regex not_uptodate - local -a id_array - id_array=($(hg id -nit)) - rev="${id_array[0]}" - num="${id_array[1]}" - tags="${id_array[2]}" - tip_regex=\\btip\\b if [[ ! $tags =~ $tip_regex ]]; then not_uptodate="$YELLOW$hg_up_char" From a19d810b50b7529d0674c1396b1ce1fe97a5f62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 20 Oct 2013 00:40:58 +0200 Subject: [PATCH 086/118] -Fix: set window and pane titles with tmux as well as screen --- git-prompt.sh | 54 +++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 29929e8..bab7896 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -322,40 +322,44 @@ cwd_truncate() { set_shell_label() { xterm_label() { - local args="$*" - printf "\033]0;%s\033\\" "${args:0:200}" + local args="$*" + printf "\033]0;%s\033\\" "${args:0:200}" } screen_label() { - local param - param="$plain_who_where $@" - # workaround screen UTF-8 bug - param=${param//$ellipse_marker/$ellipse_marker_plain} + local param full + full="$plain_who_where $@" + param="$*" + + # FIXME $STY not inherited though "su -" + if [[ "$STY" ]]; then + # workaround screen UTF-8 bug + param=${param//$ellipse_marker/$ellipse_marker_plain} + full=${full//$ellipse_marker/$ellipse_marker_plain} + fi - # FIXME: run this only if screen is in xterm (how to test for this?) - xterm_label "$param" + # FIXME: run this only if screen is in xterm (how to test for this?) + xterm_label "$full" - # FIXME $STY not inherited though "su -" - [ "$STY" ] && screen -S $STY -X title "$*" + printf "\033k%s\033\\" "$param" } - if [[ -n "$STY" ]]; then - screen_label "$*" - else - case $TERM in - screen*) - screen_label "$*" - ;; + if [[ -n "$STY" || -n "$TMUX" ]]; then + screen_label "$*" + else + case $TERM in + screen*) + screen_label "$*" + ;; - xterm* | rxvt* | gnome-* | konsole | eterm | wterm ) - # is there a capability which we can to test - # for "set term title-bar" and its escapes? - xterm_label "$plain_who_where $@" - ;; + xterm* | rxvt* | gnome-* | konsole | eterm | wterm ) + # is there a capability which we can to test + # for "set term title-bar" and its escapes? + xterm_label "$plain_who_where $@" + ;; - *) - ;; - esac + *) ;; + esac fi } From 361d52cf5de213cd823958c32797063ec875f5c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 20 Oct 2013 01:02:31 +0200 Subject: [PATCH 087/118] -Fix: remove dead code from section that sets screen window number, add tmux support --- git-prompt.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index bab7896..58dbfaa 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -388,20 +388,20 @@ set_shell_label() { tty=`echo $tty | sed "s:/dev/pts/:p:; s:/dev/tty::" ` # RH tty devs tty=`echo $tty | sed "s:/dev/vc/:vc:" ` # gentoo tty devs + # replace tty name with screen number + # however, "screen" as $TERM may also mean tmux if [[ "$TERM" =~ "screen" ]] ; then - - # [ "$WINDOW" = "" ] && WINDOW="?" - # - # # if under screen then make tty name look like s1-p2 - # # tty="${WINDOW:+s}$WINDOW${WINDOW:+-}$tty" - # tty="${WINDOW:+s}$WINDOW" # replace tty name with screen number - tty="$WINDOW" # replace tty name with screen number + if [[ "$STY" ]]; then + tty="$WINDOW" + elif [[ "$TMUX" ]]; then + tty=$(tmux display-message -p "#I") + fi fi # we don't need tty name under X11 case $TERM in - xterm* | rxvt* | gnome-terminal | konsole | eterm* | wterm | cygwin) unset tty ;; - *);; + xterm* | rxvt* | gnome-terminal | konsole | eterm* | wterm | cygwin) unset tty ;; + *);; esac dir_color=${!dir_color} From 9ad879e927109196e43056dc315bec0d0165013d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 20 Oct 2013 01:23:59 +0200 Subject: [PATCH 088/118] -Add: replace screen tty number with unicode circled numbers --- git-prompt.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 58dbfaa..0eb8d7d 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -396,6 +396,17 @@ set_shell_label() { elif [[ "$TMUX" ]]; then tty=$(tmux display-message -p "#I") fi + + # replace tty number with circled numbers + if [[ $utf8_prompt ]]; then + declare -a circled_digits=(⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳) + if [[ "$tty" -ge 0 && "$tty" -le 20 ]]; then + tty="${circled_digits[$tty]} " + fi + unset circled_digits + else + tty=" $tty" + fi fi # we don't need tty name under X11 @@ -480,7 +491,7 @@ set_shell_label() { if [[ -n $id || -n $host ]] ; then [[ -n $id && -n $host ]] && at='@' || at='' - color_who_where="${id//\\/\\\\}${host:+$at_color$at$host_color$host}${tty:+ $tty}" + color_who_where="${id//\\/\\\\}${host:+$at_color$at$host_color$host}${tty:+$tty}" plain_who_where="${id}$at$host" # if root then make it root_color From c1bb4204df457bc36875850cc8c689855581728e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 20 Oct 2013 13:43:44 +0200 Subject: [PATCH 089/118] [load] -Fix: on linux, read load from /proc/loadavg --- git-prompt.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 0eb8d7d..f4eb891 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -655,7 +655,13 @@ create_clock() { create_load_indicator () { local load_color load_value load_str load_bar load_mark i j - load_str=$(uptime | sed -ne 's/.* load average: \([0-9]\.[0-9]\{1,2\}\).*/\1/p') + if [[ "$OSTYPE" =~ "linux" ]]; then + local eol + read load_str eol < /proc/loadavg + load_str=${load_str## *} + else + load_str=$(uptime | sed -ne 's/.* load average: \([0-9]\.[0-9]\{1,2\}\).*/\1/p') + fi load_value=${load_str/\./} load_value=$((10#$load_value)) From 19deaa6d17bf185439ecb103f309a2c3d9f2ab83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 20 Oct 2013 19:02:45 +0200 Subject: [PATCH 090/118] -Add: display tmux session name in xterm title --- git-prompt.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/git-prompt.sh b/git-prompt.sh index f4eb891..2365b6f 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -338,6 +338,10 @@ set_shell_label() { full=${full//$ellipse_marker/$ellipse_marker_plain} fi + if [[ "$TMUX" ]]; then + full="$plain_who_where|${_gp_tmux_session} $@" + fi + # FIXME: run this only if screen is in xterm (how to test for this?) xterm_label "$full" @@ -395,6 +399,8 @@ set_shell_label() { tty="$WINDOW" elif [[ "$TMUX" ]]; then tty=$(tmux display-message -p "#I") + # also save tmux session name so that we can include it in the window title + _gp_tmux_session=$(tmux display-message -p "#S") fi # replace tty number with circled numbers From 10288e1c6e9ad3ed927e30c58234d72911b44063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 20 Oct 2013 19:17:00 +0200 Subject: [PATCH 091/118] -Fix: display tmux session name in xterm title, a bit more safely --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 2365b6f..f427e8b 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -339,7 +339,7 @@ set_shell_label() { fi if [[ "$TMUX" ]]; then - full="$plain_who_where|${_gp_tmux_session} $@" + full="$plain_who_where${_gp_tmux_session:+|${_gp_tmux_session}} $@" fi # FIXME: run this only if screen is in xterm (how to test for this?) From dd94581e746bd42c767c878d08a6be528b6b327d Mon Sep 17 00:00:00 2001 From: Juhasz Peter Date: Mon, 21 Oct 2013 11:08:02 +0200 Subject: [PATCH 092/118] [hg] -Fix: older hg versions' 'hg log' report empty branch name if default, handle this case --- git-prompt.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/git-prompt.sh b/git-prompt.sh index f427e8b..7d3ebf7 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -825,6 +825,9 @@ parse_hg_status() { [[ -z $modified ]] && [[ -z $untracked ]] && [[ -z $added ]] && [[ -z $deleted ]] && clean=clean + # older versions of hg log --template '{branch}' report empty if branch is default + [[ -z $branch ]] && branch=default + vcs_info=${branch/default/D} if [[ "$bookmark" ]] ; then vcs_info+=/$bookmark From 02b4c1eb040f26b67122be47cd469ac23918e99d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Mon, 21 Oct 2013 21:33:51 +0200 Subject: [PATCH 093/118] [screen] -Fix: don't display tty number if xterm is screen but or is empty (e.g. when an ssh connection is started from within a screen session) --- git-prompt.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 7d3ebf7..0e5ef1a 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -403,15 +403,21 @@ set_shell_label() { _gp_tmux_session=$(tmux display-message -p "#S") fi - # replace tty number with circled numbers - if [[ $utf8_prompt ]]; then - declare -a circled_digits=(⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳) - if [[ "$tty" -ge 0 && "$tty" -le 20 ]]; then - tty="${circled_digits[$tty]} " + # if we start an ssh connection from within a screen/tmux session, + # the "screen" $TERM setting tends to be preserved. + # In this case we don't want a tty (it would be a misleading "0"), + # unless there is an actual screen/tmux session on the server too. + if [[ -n "$tty" ]]; then + # replace tty number with circled numbers + if [[ $utf8_prompt ]]; then + declare -a circled_digits=(⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳) + if [[ "$tty" -ge 0 && "$tty" -le 20 ]]; then + tty="${circled_digits[$tty]} " + fi + unset circled_digits + else + tty=" $tty" fi - unset circled_digits - else - tty=" $tty" fi fi From 9b3149a1f5ad9df6d06a0f8db5e194346d1d3073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Mon, 21 Oct 2013 21:37:11 +0200 Subject: [PATCH 094/118] [screen] -Fix: don't display tty number if xterm is screen but or is empty (those responsible for the previous fix were fixed) --- git-prompt.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 0e5ef1a..820d460 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -401,11 +401,13 @@ set_shell_label() { tty=$(tmux display-message -p "#I") # also save tmux session name so that we can include it in the window title _gp_tmux_session=$(tmux display-message -p "#S") + else + tty= fi # if we start an ssh connection from within a screen/tmux session, # the "screen" $TERM setting tends to be preserved. - # In this case we don't want a tty (it would be a misleading "0"), + # In this case we don't want the tty displayed (it would be a misleading "0"), # unless there is an actual screen/tmux session on the server too. if [[ -n "$tty" ]]; then # replace tty number with circled numbers From 4153458445bafa1091beed122745e9531406a6e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Mon, 21 Oct 2013 22:04:08 +0200 Subject: [PATCH 095/118] [screen] -Fix: display host name in screen/tmux window title if remote shell --- git-prompt.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/git-prompt.sh b/git-prompt.sh index 820d460..ec4e8ae 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -345,6 +345,11 @@ set_shell_label() { # FIXME: run this only if screen is in xterm (how to test for this?) xterm_label "$full" + # display host name in window title if remote shell + if [[ -n ${SSH_CLIENT} || -n ${SSH2_CLIENT} ]]; then + param="@$host:$param" + fi + printf "\033k%s\033\\" "$param" } From 5a0247de9927e283483ab16a520dc6bc34abd621 Mon Sep 17 00:00:00 2001 From: Juhasz Peter Date: Tue, 22 Oct 2013 11:14:18 +0200 Subject: [PATCH 096/118] -Fix: don't display // in screen/xterm title if in root dir --- git-prompt.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index ec4e8ae..72c5b7b 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -1208,8 +1208,10 @@ prompt_command_function() { fi previous_rc="$raw_rc" - cwd=${PWD/$HOME/\~} # substitute "~" - set_shell_label "${cwd##[/~]*/}/" # default label - path last dir + local slash='/' + cwd=${PWD/$HOME/\~} # substitute "~" + cwd="${cwd##[/~]*/}/" # default label - path last dir + set_shell_label "${cwd/$slash$slash/$slash}" # remove // if root dir parse_virtualenv_status parse_vcs_status @@ -1259,7 +1261,6 @@ prompt_command_function() { # else eval cwd_cmd, cwd should have path after exection eval "${cwd_cmd/\\/cwd=\\\\}" - local slash='/' if [[ -w "$PWD" ]]; then cwd="${cwd//$slash/$slash_color$slash$dir_color}" else From 099ec06277e50a429af64559d37484a73d5db779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Wed, 23 Oct 2013 14:59:54 +0200 Subject: [PATCH 097/118] -Fix: more reliable ssh session detection via $SSH_CONNECTION variable --- git-prompt.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 72c5b7b..9471ed5 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -346,7 +346,7 @@ set_shell_label() { xterm_label "$full" # display host name in window title if remote shell - if [[ -n ${SSH_CLIENT} || -n ${SSH2_CLIENT} ]]; then + if [[ -n ${SSH_CLIENT} || -n ${SSH2_CLIENT} || -n ${SSH_CONNECTION} ]]; then param="@$host:$param" fi @@ -452,7 +452,7 @@ set_shell_label() { # if { for ((pid=$$; $pid != 1 ; pid=`ps h -o pid --ppid $pid`)); do ps h -o command -p $pid; done | grep -q sshd && echo == REMOTE ==; } #then - if [[ -n ${SSH_CLIENT} || -n ${SSH2_CLIENT} ]]; then + if [[ -n ${SSH_CLIENT} || -n ${SSH2_CLIENT} || -n ${SSH_CONNECTION} ]]; then probably_ssh_session=1 at_color=$at_color_remote else From 0a405c8241192a9a7d0e7ad4d7d8a7c9d3a86118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Wed, 23 Oct 2013 22:32:27 +0200 Subject: [PATCH 098/118] [set_shell_label] -Fix: display host name in screen/tmux window name only if not inside a screen/tmux on the remote system --- git-prompt.sh | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 9471ed5..05b07cb 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -320,16 +320,16 @@ cwd_truncate() { set_shell_label() { + local param full + full="$plain_who_where $@" + short="$*" xterm_label() { - local args="$*" - printf "\033]0;%s\033\\" "${args:0:200}" + local args="$*" + printf "\033]0;%s\033\\" "${args:0:200}" } screen_label() { - local param full - full="$plain_who_where $@" - param="$*" # FIXME $STY not inherited though "su -" if [[ "$STY" ]]; then @@ -345,26 +345,29 @@ set_shell_label() { # FIXME: run this only if screen is in xterm (how to test for this?) xterm_label "$full" - # display host name in window title if remote shell - if [[ -n ${SSH_CLIENT} || -n ${SSH2_CLIENT} || -n ${SSH_CONNECTION} ]]; then - param="@$host:$param" - fi - - printf "\033k%s\033\\" "$param" + printf "\033k%s\033\\" "$short" } if [[ -n "$STY" || -n "$TMUX" ]]; then - screen_label "$*" + # in this case, do not prepend host name, + # because screen/tmux statusbar should display it only once - + # displaying it in every window name would waste space + screen_label "$short" else case $TERM in screen*) - screen_label "$*" + # display host name in window title if we're inside screen or tmux locally, + # and ssh'd to a remote server + if [[ -n ${SSH_CLIENT} || -n ${SSH2_CLIENT} || -n ${SSH_CONNECTION} ]]; then + short="@$host:$short" + fi + screen_label "$short" ;; xterm* | rxvt* | gnome-* | konsole | eterm | wterm ) # is there a capability which we can to test # for "set term title-bar" and its escapes? - xterm_label "$plain_who_where $@" + xterm_label "$full" ;; *) ;; From 402b510833087b916295cd6c5dd90954b5510237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Wed, 23 Oct 2013 22:43:32 +0200 Subject: [PATCH 099/118] [set_shell_label] -Fix: forgotten variable name in previous commit --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 05b07cb..a6050af 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -334,7 +334,7 @@ set_shell_label() { # FIXME $STY not inherited though "su -" if [[ "$STY" ]]; then # workaround screen UTF-8 bug - param=${param//$ellipse_marker/$ellipse_marker_plain} + short=${param//$ellipse_marker/$ellipse_marker_plain} full=${full//$ellipse_marker/$ellipse_marker_plain} fi From 529ce5778b3845d017b8061fccc4d523ee59fbc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Tue, 29 Oct 2013 21:47:01 +0100 Subject: [PATCH 100/118] -Fix: get id and tty in a function; more robust tmux session and tty detection --- git-prompt.sh | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index a6050af..033aedc 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -378,6 +378,7 @@ set_shell_label() { export -f set_shell_label ###################################################### ID (user name) +_gp_get_id() { id=`id -un` # abbreviate user name if needed @@ -394,21 +395,38 @@ set_shell_label() { #else # keep full user name fi +} + +_gp_get_id ########################################################### TTY - tty=`tty` - tty=`echo $tty | sed "s:/dev/pts/:p:; s:/dev/tty::" ` # RH tty devs - tty=`echo $tty | sed "s:/dev/vc/:vc:" ` # gentoo tty devs +_gp_get_tty() { + local tty + tty=$(tty) + tty=${tty/\/dev\/pts\//p} # RH tty devs + tty=${tty/\/dev\/tty/} + tty=${tty/\/dev\/vc\//vc} # gentoo tty devs # replace tty name with screen number # however, "screen" as $TERM may also mean tmux if [[ "$TERM" =~ "screen" ]] ; then if [[ "$STY" ]]; then tty="$WINDOW" - elif [[ "$TMUX" ]]; then - tty=$(tmux display-message -p "#I") - # also save tmux session name so that we can include it in the window title - _gp_tmux_session=$(tmux display-message -p "#S") + elif [[ -n $TMUX && -n $TMUX_PANE ]]; then + # get tmux session name so that we can include it in the window title + # and window number, to display it in the prompt + # TODO configurable prompt marker + # we have to do it like this, because session name may contain spaces + local sep tmux_info oldIFS + sep=$'\x1f' + tmux_info=$(tmux display-message -t $TMUX_PANE -p "#S${sep}#I" 2> /dev/null) + oldIFS="$IFS" + IFS="$sep" + local -a tmux_array + tmux_array=($tmux_info) + IFS="$oldIFS" + _gp_tmux_session=${tmux_array[0]} + tty=${tmux_array[1]} else tty= fi @@ -420,11 +438,10 @@ set_shell_label() { if [[ -n "$tty" ]]; then # replace tty number with circled numbers if [[ $utf8_prompt ]]; then - declare -a circled_digits=(⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳) + local -a circled_digits=(⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳) if [[ "$tty" -ge 0 && "$tty" -le 20 ]]; then tty="${circled_digits[$tty]} " fi - unset circled_digits else tty=" $tty" fi @@ -433,10 +450,15 @@ set_shell_label() { # we don't need tty name under X11 case $TERM in - xterm* | rxvt* | gnome-terminal | konsole | eterm* | wterm | cygwin) unset tty ;; + xterm* | rxvt* | gnome-terminal | konsole | eterm* | wterm | cygwin) tty= ;; *);; esac + _gp_tty="$tty" +} + +_gp_get_tty + dir_color=${!dir_color} slash_color=${!slash_color} slash_color_readonly=${!slash_color_readonly} @@ -513,7 +535,7 @@ set_shell_label() { if [[ -n $id || -n $host ]] ; then [[ -n $id && -n $host ]] && at='@' || at='' - color_who_where="${id//\\/\\\\}${host:+$at_color$at$host_color$host}${tty:+$tty}" + color_who_where="${id//\\/\\\\}${host:+$at_color$at$host_color$host}${_gp_tty:+$_gp_tty}" plain_who_where="${id}$at$host" # if root then make it root_color @@ -1315,6 +1337,6 @@ prompt_OFF() { prompt_on - unset rc id tty modified_files file_list + unset rc id _gp_tty modified_files file_list # vim: set ft=sh ts=8 sw=8 et: From 2446732cba16853d0f029dbc3365c5f12f70dd06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 16 Nov 2013 22:12:14 +0100 Subject: [PATCH 101/118] -Fix: add new runtime functions to enable/disable utf8, separate host/who_where info into functions --- git-prompt.conf | 1 + git-prompt.conf.mine | 1 + git-prompt.sh | 38 +++++++++++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index fe048b5..f72f862 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -12,6 +12,7 @@ # max_file_list_length=100 # in characters # count_only=off # off - display file list; on - display file count # rawhex_len=5 # length of git rawhex revision id display (use 0 to hide it) +# enable_utf8=on # use utf8 characters in prompt ############################################################ MODULES diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine index 8097160..82d8b9a 100644 --- a/git-prompt.conf.mine +++ b/git-prompt.conf.mine @@ -12,6 +12,7 @@ max_file_list_length=30 # in characters count_only=on # off - display file list; on - display file count # rawhex_len=5 # length of git rawhex revision id display (use 0 to hide it) +# enable_utf8=on # use utf8 characters in prompt ############################################################ MODULES diff --git a/git-prompt.sh b/git-prompt.sh index 033aedc..56bc040 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -102,6 +102,7 @@ command_time_threshold=${command_time_threshold:-15} clock_style=${clock_style:-analog} clock_alert_interval=${clock_alert_interval:-30} + enable_utf8=${enable_utf8:-on} if [[ -z "$load_colors" || -z "$load_thresholds" || ${#load_colors[@]} -ne ${#load_thresholds[@]} ]]; then load_colors=(BLACK red RED whiteonred) @@ -248,15 +249,20 @@ #################################################################### MARKERS ellipse_marker_utf8="…" ellipse_marker_plain="..." - if [[ ("$LC_CTYPE $LC_ALL $LANG" =~ "UTF" || $LANG =~ "utf") && $TERM != "linux" ]]; then + +_gp_check_utf8() { + if [[ $enable_utf8 == "on" && ("$LC_CTYPE $LC_ALL $LANG" =~ "UTF" || $LANG =~ "utf") && $TERM != "linux" ]]; then utf8_prompt=1 ellipse_marker=$ellipse_marker_utf8 else utf8_prompt= ellipse_marker=$ellipse_marker_plain fi +} + +_gp_check_utf8 - export who_where +export who_where cwd_truncate() { @@ -476,7 +482,8 @@ _gp_get_tty ## is sshd our parent? # if { for ((pid=$$; $pid != 1 ; pid=`ps h -o pid --ppid $pid`)); do ps h -o command -p $pid; done | grep -q sshd && echo == REMOTE ==; } #then - + +_gp_get_host() { if [[ -n ${SSH_CLIENT} || -n ${SSH2_CLIENT} || -n ${SSH_CONNECTION} ]]; then probably_ssh_session=1 at_color=$at_color_remote @@ -529,10 +536,14 @@ _gp_get_tty host=${host%.$default_domain} unset probably_ssh_session +} + +_gp_get_host #################################################################### WHO_WHERE # [[user@]host[-tty]] +_gp_set_who_where() { if [[ -n $id || -n $host ]] ; then [[ -n $id && -n $host ]] && at='@' || at='' color_who_where="${id//\\/\\\\}${host:+$at_color$at$host_color$host}${_gp_tty:+$_gp_tty}" @@ -565,7 +576,9 @@ _gp_get_tty fi return 0 fi +} +_gp_set_who_where create_battery_indicator () { # if not a laptop: : @@ -1335,6 +1348,25 @@ prompt_OFF() { disable_set_shell_label } +prompt_disable_utf8() { + enable_utf8="off" + _gp_check_utf8 + _gp_get_id + _gp_get_tty + _gp_get_host + _gp_set_who_where +} + +prompt_enable_utf8() { + enable_utf8="on" + _gp_check_utf8 + _gp_get_id + _gp_get_tty + _gp_get_host + _gp_set_who_where +} + + prompt_on unset rc id _gp_tty modified_files file_list From 483e77d4347fcbe13eb0b9d77524f74c0cf447dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 16 Nov 2013 22:52:01 +0100 Subject: [PATCH 102/118] -Fix: at_color logic, don't swallow one dot from abbreviated host name --- git-prompt.sh | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 56bc040..04d6748 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -212,6 +212,18 @@ deleted_vcs_color=${!deleted_vcs_color} hex_vcs_color=${!hex_vcs_color} + dir_color=${!dir_color} + slash_color=${!slash_color} + slash_color_readonly=${!slash_color_readonly} + prompt_color=${!prompt_color} + rc_color=${!rc_color} + virtualenv_color=${!virtualenv_color} + user_id_color=${!user_id_color} + root_id_color=${!root_id_color} + at_color=${!at_color} + at_color_remote=${!at_color_remote} + + unset PROMPT_COMMAND # assemble prompt command string based on the module order specified above @@ -465,15 +477,6 @@ _gp_get_tty() { _gp_get_tty - dir_color=${!dir_color} - slash_color=${!slash_color} - slash_color_readonly=${!slash_color_readonly} - prompt_color=${!prompt_color} - rc_color=${!rc_color} - virtualenv_color=${!virtualenv_color} - user_id_color=${!user_id_color} - root_id_color=${!root_id_color} - ########################################################### HOST ### we don't display home host/domain $SSH_* set by SSHD or keychain @@ -486,9 +489,10 @@ _gp_get_tty _gp_get_host() { if [[ -n ${SSH_CLIENT} || -n ${SSH2_CLIENT} || -n ${SSH_CONNECTION} ]]; then probably_ssh_session=1 - at_color=$at_color_remote + at_color_cur=$at_color_remote else probably_ssh_session= + at_color_cur=$at_color fi host=${HOSTNAME} @@ -529,11 +533,10 @@ _gp_get_host() { fi fi - at_color=${!at_color} host_color=${!host_color} # we might already have short host name - host=${host%.$default_domain} + [[ -n $default_domain ]] && host=${host%.$default_domain} unset probably_ssh_session } @@ -546,7 +549,7 @@ _gp_get_host _gp_set_who_where() { if [[ -n $id || -n $host ]] ; then [[ -n $id && -n $host ]] && at='@' || at='' - color_who_where="${id//\\/\\\\}${host:+$at_color$at$host_color$host}${_gp_tty:+$_gp_tty}" + color_who_where="${id//\\/\\\\}${host:+$at_color_cur$at$host_color$host}${_gp_tty:+$_gp_tty}" plain_who_where="${id}$at$host" # if root then make it root_color From 19887ae9ccd581a915f8cae63cd1df01d63eea4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sat, 23 Nov 2013 22:09:32 +0100 Subject: [PATCH 103/118] -Fix: suppress svnversion's stderr, return on error --- git-prompt.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 04d6748..522b3cb 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -763,8 +763,9 @@ parse_svn_status() { local svn_info_str myrc rev case $svn_method in - svnversion) rev=$(svnversion) - [[ "$rev" == "exported" || "$rev" =~ "Unversioned" ]] && return 1 + svnversion) rev=$(svnversion 2> /dev/null) + myrc=$? + [[ $myrc -ne 0 || "$rev" == "exported" || "$rev" =~ "Unversioned" ]] && return 1 ;; info) svn_info_str=$(svn info 2> /dev/null) @@ -776,6 +777,8 @@ parse_svn_status() { dotsvn) [[ -d .svn ]] || return 1 svn_info_str=$(svn info 2> /dev/null) + myrc=$? + [[ $myrc -eq 0 ]] || return 1 rev=${svn_info_str##*Revision: } rev=${rev%%[[:space:]]*} ;; From 7172a9d2b62044fd160873cb555460d84b41197e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Fri, 13 Dec 2013 17:49:40 +0100 Subject: [PATCH 104/118] [git] -Fix: git status in git 1.8 omits #'s, fixed regexps to parse new format --- git-prompt.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 522b3cb..0cf0156 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -967,12 +967,12 @@ parse_git_status() { eval " $( LANG=C git status 2>/dev/null | sed -n ' - s/^# On branch /branch=/p + s/^\(# \)*On branch /branch=/p s/^nothing to commi.*/clean=clean/p - s/^# Initial commi.*/init=init/p - s/^# Your branch is ahead of \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${WHITE}${git_up_char}/p - s/^# Your branch is behind \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${YELLOW}${git_dn_char}/p - s/^# Your branch and \(.\).\+\1 have diverged.*/freshness=${YELLOW}${git_updn_char}/p + s/^\(# \)*Initial commi.*/init=init/p + s/^\(# \)*Your branch is ahead of \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${WHITE}${git_up_char}/p + s/^\(# \)*Your branch is behind \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${YELLOW}${git_dn_char}/p + s/^\(# \)*Your branch and \(.\).\+\1 have diverged.*/freshness=${YELLOW}${git_updn_char}/p ' )" From 29affa957671e0875f340013eb539cffafab3701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Fri, 13 Dec 2013 18:01:16 +0100 Subject: [PATCH 105/118] [git] -Fix: previous commit broke ahead/behind detection --- git-prompt.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 0cf0156..d36d6a1 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -970,9 +970,9 @@ parse_git_status() { s/^\(# \)*On branch /branch=/p s/^nothing to commi.*/clean=clean/p s/^\(# \)*Initial commi.*/init=init/p - s/^\(# \)*Your branch is ahead of \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${WHITE}${git_up_char}/p - s/^\(# \)*Your branch is behind \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${YELLOW}${git_dn_char}/p - s/^\(# \)*Your branch and \(.\).\+\1 have diverged.*/freshness=${YELLOW}${git_updn_char}/p + s/^\(# \)*Your branch is ahead of \(.\).\+\2 by [[:digit:]]\+ commit.*/freshness=${WHITE}${git_up_char}/p + s/^\(# \)*Your branch is behind \(.\).\+\2 by [[:digit:]]\+ commit.*/freshness=${YELLOW}${git_dn_char}/p + s/^\(# \)*Your branch and \(.\).\+\2 have diverged.*/freshness=${YELLOW}${git_updn_char}/p ' )" From 77fe95139d7fe55498afa2398d3a72d903fea3d2 Mon Sep 17 00:00:00 2001 From: Juhasz Peter Date: Thu, 9 Jan 2014 12:30:55 +0100 Subject: [PATCH 106/118] -Fix: recent refactoring broke mc special case, apply bandaid --- git-prompt.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index d36d6a1..99607f1 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -577,12 +577,15 @@ _gp_set_who_where() { else PS1="\w$prompt_char " fi - return 0 + return 1 fi } _gp_set_who_where +# exit if in mc (see above) +[[ $? -ne 0 ]] && return 1 + create_battery_indicator () { # if not a laptop: : # if laptop on AC, not charging: ⚡ From e206c7d44329b463c3d1297db3be0031df740730 Mon Sep 17 00:00:00 2001 From: Juhasz Peter Date: Thu, 9 Jan 2014 12:41:06 +0100 Subject: [PATCH 107/118] [git] -Fix: show locally deleted files for git --- git-prompt.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/git-prompt.sh b/git-prompt.sh index 99607f1..cb7a589 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -999,6 +999,8 @@ parse_git_status() { s,^.U \"\([^/]\+/\?\).*\"$, conflicted_files+=(\"\1\"),p s,^D. \([^\"][^/]*/\?\).*, deleted_files+=(\"\1\"),p s,^D. \"\([^/]\+/\?\).*\"$, deleted_files+=(\"\1\"),p + s,^.D \([^\"][^/]*/\?\).*, deleted_files+=(\"\1\"),p + s,^.D \"\([^/]\+/\?\).*\"$, deleted_files+=(\"\1\"),p s,^[MARC]. \([^\"][^/]*/\?\).*, added_files+=(\"\1\"),p s,^[MARC]. \"\([^/]\+/\?\).*\"$, added_files+=(\"\1\"),p s,^.[MA] \([^\"][^/]*/\?\).*, modified_files+=(\"\1\"),p From a10a8dced5aa770c2841b14485fa4f59717e9de5 Mon Sep 17 00:00:00 2001 From: Juhasz Peter Date: Thu, 23 Jan 2014 13:47:50 +0100 Subject: [PATCH 108/118] [hg] -Fix: suppress stderr of hg heads --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index cb7a589..bda861d 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -895,7 +895,7 @@ parse_hg_status() { if [[ $hg_multiple_heads_display == "on" ]]; then local hg_heads - hg_heads=$(hg heads --template '{rev}\n' $branch | wc -l) + hg_heads=$(hg heads --template '{rev}\n' $branch 2> /dev/null | wc -l) if [[ $hg_heads -gt 1 ]]; then detached=detached From a242d01ee3d6409f822ab7754664a126e8f339fa Mon Sep 17 00:00:00 2001 From: Juhasz Peter Date: Mon, 2 Jun 2014 18:00:13 +0200 Subject: [PATCH 109/118] [hg] -Fix: use more backwards compatible hg log template to get branch name --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index bda861d..e7bb3f8 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -831,7 +831,7 @@ parse_hg_status() { # if we're not in a hg directory, this takes exactly the same time as 'hg root' would do, # and if we're in a hg dir, we don't have to call 'hg branch' and 'hg id' separately. local id_str - id_str=$(hg log --follow -l 1 --template '{rev}\x1f{node}\x1f{tags}\x1f{branch}\x1f{bookmarks}' 2> /dev/null) || return 1 + id_str=$(hg log --follow -l 1 --template '{rev}\x1f{node}\x1f{tags}\x1f{branches}\x1f{bookmarks}' 2> /dev/null) || return 1 # This contrived way is necessary because branch names and tags can contain spaces. # The ASCII "Unit separator" \x1f was chosen as a "safe" separator character From fc222fb65c63da56a29f304f2373479f8d24b303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Sun, 19 Oct 2014 18:21:45 +0200 Subject: [PATCH 110/118] -Fix: escape backslahses in VCS names lists --- git-prompt.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index e7bb3f8..890adee 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -794,7 +794,7 @@ parse_svn_status() { ### get status unset status modified added clean init deleted untracked conflicted op detached - eval `svn status 2>/dev/null | + eval `svn status 2>/dev/null | sed 's/\\\\/x/g' | sed -n ' s/^A... \([^.].*\)/ added_files+=(\"\1\");/p s/^M... \([^.].*\)/ modified_files+=(\"\1\");/p @@ -856,7 +856,7 @@ parse_hg_status() { ### get status unset status modified added clean init deleted untracked op detached - eval `hg status 2>/dev/null | + eval `hg status 2>/dev/null | sed 's/\\\\/x/g' | sed -n ' s/^M \([^.].*\)/ modified_files+=(\"\1\");/p s/^A \([^.].*\)/ added_files+=(\"\1\");/p @@ -968,7 +968,7 @@ parse_git_status() { # info not in porcelain status eval " $( - LANG=C git status 2>/dev/null | + LANG=C git status 2>/dev/null | sed 's/\\\\/x/g' | sed -n ' s/^\(# \)*On branch /branch=/p s/^nothing to commi.*/clean=clean/p @@ -991,7 +991,7 @@ parse_git_status() { # A "with space" <------------- WITH QOUTES eval " $( - LANG=C git status --porcelain 2>/dev/null | + LANG=C git status --porcelain 2>/dev/null | sed 's/\\\\/x/g' | sed -n ' s,^U. \([^\"][^/]*/\?\).*, conflicted_files+=(\"\1\"),p s,^U. \"\([^/]\+/\?\).*\"$, conflicted_files+=(\"\1\"),p From 6853a5148e13fe2c5ecafc083e930cf61f93cec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Tue, 6 Oct 2015 22:58:03 +0200 Subject: [PATCH 111/118] -Fix: hack for mc-wrapper on Fedora/Centos --- git-prompt.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 890adee..3a25a4a 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -342,9 +342,15 @@ set_shell_label() { full="$plain_who_where $@" short="$*" + # hack to replace garbled bash command under mc on some systems + if [[ "$short" == ". /usr/libexec/mc/mc-wrapper.sh" ]]; then + short="mc" + full="$plain_who_where $short" + fi + xterm_label() { local args="$*" - printf "\033]0;%s\033\\" "${args:0:200}" + printf "\033]0;%s\007" "${args:0:200}" } screen_label() { @@ -357,7 +363,7 @@ set_shell_label() { fi if [[ "$TMUX" ]]; then - full="$plain_who_where${_gp_tmux_session:+|${_gp_tmux_session}} $@" + full="$plain_who_where${_gp_tmux_session:+|${_gp_tmux_session}} $short" fi # FIXME: run this only if screen is in xterm (how to test for this?) From c75c2fb1ab9c31ff862feaa97e9c47bfa6d24286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Wed, 7 Oct 2015 21:40:38 +0200 Subject: [PATCH 112/118] [hg] -Add: support for hg phase --- git-prompt.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 3a25a4a..b1c74e2 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -837,7 +837,7 @@ parse_hg_status() { # if we're not in a hg directory, this takes exactly the same time as 'hg root' would do, # and if we're in a hg dir, we don't have to call 'hg branch' and 'hg id' separately. local id_str - id_str=$(hg log --follow -l 1 --template '{rev}\x1f{node}\x1f{tags}\x1f{branches}\x1f{bookmarks}' 2> /dev/null) || return 1 + id_str=$(hg log --follow -l 1 --template '{rev}\x1f{node}\x1f{tags}\x1f{branches}\x1f{bookmarks}\x1f{phase}' 2> /dev/null) || return 1 # This contrived way is necessary because branch names and tags can contain spaces. # The ASCII "Unit separator" \x1f was chosen as a "safe" separator character @@ -850,12 +850,13 @@ parse_hg_status() { id_array=($id_str) IFS="$oldIFS" - local branch bookmark num rev tags tip_regex not_uptodate + local branch bookmark num rev tags tip_regex not_uptodate phase num="${id_array[0]}" rev="${id_array[1]}" tags="${id_array[2]}" branch="${id_array[3]}" bookmark="${id_array[4]}" + phase="${id_array[5]}" vcs=hg @@ -914,9 +915,23 @@ parse_hg_status() { if [[ $utf8_prompt ]]; then hg_vcs_char="☿" hg_up_char="⬆" + case $phase in + public) phase="${green}⚌";; # ☻ + draft) phase="${yellow}⚍";; # ☺ + secret) phase="${red}⚏";; # ☹ + *) phase="" ;; + esac else hg_vcs_char=":" hg_up_char="^" + phase=${phase:0:3} + case $phase in + public) phase="${green}pub";; + draft) phase="${yellow}dra";; + secret) phase="${red}sec";; + *) phase="";; + esac + fi tip_regex=\\btip\\b @@ -936,7 +951,7 @@ parse_hg_status() { *) hg_revision="" ;; esac - vcs_info+=$hg_revision$not_uptodate + vcs_info+=$hg_revision$phase$not_uptodate } From 20ac93e003c7c5a03cb917a1548cfaeb504cbdb6 Mon Sep 17 00:00:00 2001 From: Peter Juhasz Date: Wed, 14 Oct 2015 22:16:11 +0200 Subject: [PATCH 113/118] [sudo] -Add: sudo module --- git-prompt.conf | 3 ++- git-prompt.conf.mine | 4 +++- git-prompt.sh | 22 ++++++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/git-prompt.conf b/git-prompt.conf index f72f862..7722d68 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -28,10 +28,11 @@ # command_time_module=on # clock_module=off # load_module=on +# sudo_module=off ### Order of modules -# prompt_modules_order="RC LOAD CLOCK CTIME VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE" +# prompt_modules_order="RC LOAD CLOCK CTIME VIRTUALENV VCS SUDO WHO_WHERE JOBS BATTERY CWD MAKE" ########################################################### DEFAULT OBJECTS ### Default user and hostname can be abbreviated or suppressed. diff --git a/git-prompt.conf.mine b/git-prompt.conf.mine index 82d8b9a..b2b2e1b 100644 --- a/git-prompt.conf.mine +++ b/git-prompt.conf.mine @@ -28,10 +28,11 @@ rc_module=on command_time_module=on load_module=on clock_module=on +sudo_module=on ### order of modules -prompt_modules_order="RC LOAD CLOCK CTIME VIRTUALENV WHO_WHERE JOBS BATTERY CWD VCS MAKE" +prompt_modules_order="RC LOAD CLOCK CTIME VIRTUALENV SUDO WHO_WHERE JOBS BATTERY CWD VCS MAKE" ########################################################### DEFAULT OBJECTS ### Default user and hostname can be abbreviated or suppressed. @@ -126,6 +127,7 @@ clock_alert_interval=30 at_color=green at_color_remote=RED clock_color=WHITE + sudo_color=RED # else # B/W terminal # dir_color=bw_bold diff --git a/git-prompt.sh b/git-prompt.sh index b1c74e2..35abd3b 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -32,13 +32,14 @@ command_time_module=${command_time_module:-on} load_module=${load_module:-on} clock_module=${clock_module:-off} + sudo_module=${sudo_module:-off} error_bell=${error_bell:-off} cwd_cmd=${cwd_cmd:-\\w} default_host_abbrev_mode=${default_host_abbrev_mode:-delete} default_id_abbrev_mode=${default_id_abbrev_mode:-delete} - prompt_modules_order=${prompt_modules_order:-RC LOAD CTIME VIRTUALENV VCS WHO_WHERE JOBS BATTERY CWD MAKE} + prompt_modules_order=${prompt_modules_order:-RC LOAD CTIME VIRTUALENV VCS SUDO WHO_WHERE JOBS BATTERY CWD MAKE} #### check for acpi, make, disable corresponding module if not installed if [[ -z $(which acpi 2> /dev/null) || -z $(acpi -b) ]]; then @@ -67,6 +68,7 @@ make_color_dirty=${make_color_dirty:-RED} command_time_color=${command_time_color:-YELLOW} clock_color=${clock_color:-BLACK} + sudo_color=${sudo_color:-RED} else # only B/W dir_color=${dir_color:-bw_bold} @@ -246,6 +248,7 @@ s/BATTERY/\$battery_indicator/; s/CWD/\$dir_color\$cwd/; s/MAKE/\$make_indicator/; + s/SUDO/\$sudo_marker/; s/ //g; s/\$space\$space/\$space/g; s/^\$space//; @@ -768,6 +771,15 @@ create_load_indicator () { load_indicator="$load_color$load_mark$load_str$colors_reset" } +create_sudo_marker() { + sudo_marker= + if [[ $utf8_prompt ]]; then + sudo -nl &> /dev/null && sudo_marker="${!sudo_color}⚷$colors_reset" + else + sudo -nl &> /dev/null && sudo_marker="${!sudo_color}!$colors_reset" + fi +} + parse_svn_status() { local svn_info_str myrc rev @@ -1322,6 +1334,12 @@ prompt_command_function() { clock_indicator="" fi + if [[ $sudo_module == "on" ]]; then + create_sudo_marker + else + sudo_marker="" + fi + # autojump if [[ ${aj_dir_list[aj_idx%aj_max]} != $PWD ]] ; then aj_dir_list[++aj_idx%aj_max]="$PWD" @@ -1346,7 +1364,7 @@ prompt_command_function() { # old static string with default order left here for reference ###PS1="$colors_reset$rc$virtualenv_string$head_local$color_who_where$colors_reset$jobs_indicator$battery_indicator$dir_color$cwd$make_indicator$prompt_color$prompt_char $colors_reset" - unset head_local raw_rc jobs_indicator virtualenv_string make_indicator battery_indicator command_time load_indicator clock_indicator + unset head_local raw_rc jobs_indicator virtualenv_string make_indicator battery_indicator command_time load_indicator clock_indicator sudo_marker } # provide functions to turn the fancy prompt functions on and off From ff4238cab053d3698a80d25a105ce49452d1e4e8 Mon Sep 17 00:00:00 2001 From: Peter Juhasz Date: Thu, 23 Nov 2017 11:53:47 +0100 Subject: [PATCH 114/118] -Fix: unset color var at init to avoid warning when running repeatedly --- git-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-prompt.sh b/git-prompt.sh index 35abd3b..34b6955 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -8,7 +8,7 @@ unset make_color_ok make_color_dirty jobs_color_bkg jobs_color_stop slash_color slash_color_readonly at_color at_color_remote unset command_time_color clock_color unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color - unset modified_vcs_color added_vcs_color untracked_vcs_color deleted_vcs_color op_vcs_color detached_vcs_color hex_vcs_color + unset modified_vcs_color added_vcs_color untracked_vcs_color deleted_vcs_color op_vcs_color detached_vcs_color hex_vcs_color conflicted_vcs_color unset rawhex_len conf=git-prompt.conf; [[ -r $conf ]] && . $conf From a654ed2a8b8f44eba8a36aac61971761f2b86a1c Mon Sep 17 00:00:00 2001 From: Peter Juhasz Date: Wed, 22 May 2019 10:59:59 +0200 Subject: [PATCH 115/118] -Fix: display first (0th) battery status from acpi output --- git-prompt.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 34b6955..c55962e 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -607,9 +607,9 @@ create_battery_indicator () { battery_string=$(acpi -b) if [[ $battery_string ]]; then - tmp=${battery_string%\%*} + tmp=${battery_string%%\%*} battery_percent=${tmp##* } - if [[ "$battery_string" =~ "Discharging" ]]; then + if [[ "$tmp" =~ "Discharging" ]]; then if [[ $utf8_prompt ]]; then battery_diagrams=( ▕▁▏ ▕▂▏ ▕▃▏ ▕▄▏ ▕▅▏ ▕▆▏ ▕▇▏ ▕█▏ ) battery_pwr_index=$(($battery_percent/13)) @@ -617,7 +617,7 @@ create_battery_indicator () { else battery_indicator="|$battery_percent|" fi - elif [[ "$battery_string" =~ "Charging" ]]; then + elif [[ "$tmp" =~ "Charging" ]]; then if [[ $utf8_prompt ]]; then battery_indicator="▕⚡▏" else From 66731d6a96bd621978dde1e778fefaee5f68f24a Mon Sep 17 00:00:00 2001 From: Peter Juhasz Date: Mon, 27 May 2019 17:08:16 +0200 Subject: [PATCH 116/118] [battery] -Change: no longer use acpi -b to get battery status, its output is unreliable if there are more than one batteries in the system, use the /sys/class/power_supply/BAT0 filesystem directly instead --- git-prompt.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index c55962e..9050504 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -41,8 +41,9 @@ prompt_modules_order=${prompt_modules_order:-RC LOAD CTIME VIRTUALENV VCS SUDO WHO_WHERE JOBS BATTERY CWD MAKE} - #### check for acpi, make, disable corresponding module if not installed - if [[ -z $(which acpi 2> /dev/null) || -z $(acpi -b) ]]; then + #### check for battery files, make, disable corresponding module if not installed + # FIXME check other possible locations (BAT1, /proc ?) + if [[ ! -f /sys/class/power_supply/BAT0/present || ! $(< /sys/class/power_supply/BAT0/present) ]]; then battery_module=off fi if [[ -z $(which make 2> /dev/null) ]]; then @@ -602,14 +603,14 @@ create_battery_indicator () { # if laptop on battery: one of ▕▁▏▕▂▏▕▃▏▕▄▏▕▅▏▕▆▏▕▇▏▕█▏ # color: red if power < 30 %, else normal - local battery_string battery_percent battery_color battery_pwr_index tmp + local battery_present battery_status battery_percent battery_color battery_pwr_index tmp local -a battery_diagrams - battery_string=$(acpi -b) + battery_present=$(< /sys/class/power_supply/BAT0/present) - if [[ $battery_string ]]; then - tmp=${battery_string%%\%*} - battery_percent=${tmp##* } - if [[ "$tmp" =~ "Discharging" ]]; then + if [[ $battery_present ]]; then + battery_status=$(< /sys/class/power_supply/BAT0/status) + battery_percent=$(< /sys/class/power_supply/BAT0/capacity) + if [[ "$battery_status" =~ "Discharging" ]]; then if [[ $utf8_prompt ]]; then battery_diagrams=( ▕▁▏ ▕▂▏ ▕▃▏ ▕▄▏ ▕▅▏ ▕▆▏ ▕▇▏ ▕█▏ ) battery_pwr_index=$(($battery_percent/13)) @@ -617,7 +618,7 @@ create_battery_indicator () { else battery_indicator="|$battery_percent|" fi - elif [[ "$tmp" =~ "Charging" ]]; then + elif [[ "$battery_status" =~ "Charging" ]]; then if [[ $utf8_prompt ]]; then battery_indicator="▕⚡▏" else From 301928077275cdbd8bc21df46c4df4a96ea327c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Tue, 26 Dec 2023 17:16:40 +0100 Subject: [PATCH 117/118] [tmux] -Fix: tty/tmux session breakage (because tmux display-message escapes arguments now) --- git-prompt.sh | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 9050504..6e2da7d 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -445,16 +445,11 @@ _gp_get_tty() { # and window number, to display it in the prompt # TODO configurable prompt marker # we have to do it like this, because session name may contain spaces - local sep tmux_info oldIFS - sep=$'\x1f' + local sep tmux_info + sep="~@~" # used to be \x1f, bug tmux escapes arguments now tmux_info=$(tmux display-message -t $TMUX_PANE -p "#S${sep}#I" 2> /dev/null) - oldIFS="$IFS" - IFS="$sep" - local -a tmux_array - tmux_array=($tmux_info) - IFS="$oldIFS" - _gp_tmux_session=${tmux_array[0]} - tty=${tmux_array[1]} + _gp_tmux_session=${tmux_info/$sep*/} + tty=${tmux_info/*$sep/} else tty= fi From 68821474274e75070254f6dc1975e97b12c2f93f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juh=C3=A1sz=20P=C3=A9ter?= Date: Tue, 26 Dec 2023 17:24:29 +0100 Subject: [PATCH 118/118] [vcs] -Fix: dim color tput command, and change hex_vcs_color default to dim --- git-prompt.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-prompt.sh b/git-prompt.sh index 6e2da7d..36c287a 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -92,7 +92,7 @@ op_vcs_color=${op_vcs_color:-MAGENTA} detached_vcs_color=${detached_vcs_color:-RED} - hex_vcs_color=${hex_vcs_color:-BLACK} # gray + hex_vcs_color=${hex_vcs_color:-dim} # gray max_file_list_length=${max_file_list_length:-100} @@ -194,7 +194,7 @@ whiteonred='\['`tput setaf 7; tput setab 1; tput bold`'\]' - dim='\['`tput sgr0; tput setaf p1`'\]' # half-bright + dim='\['`tput sgr0; tput dim`'\]' # half-bright bw_bold='\['`tput bold`'\]'