From 0ee5944f79d45b8da393939f0b459a9401256e00 Mon Sep 17 00:00:00 2001 From: nojhan Date: Tue, 12 Mar 2013 00:02:04 +0100 Subject: [PATCH 01/24] Differents colors for differents hosts you SSH in Adds the LP_ENABLE_SSH_COLORS option to use a numeric hash of the hostname as the displayed color. --- README.md | 13 +++++++------ liquidprompt | 16 +++++++++++++++- liquidpromptrc-dist | 3 +++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d345203..363e490 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,9 @@ in a git repository on a server, at branch "myb": `1r [user@server:~/liquidprompt] myb ± ` -A liquid prompt displaying everything may look like this: +A liquid prompt displaying everything (a rare event!) may look like this: -`⌁24% ⌂42% 3d/2&/1z [user@server:~/ … /code/liquidprompt]↥ master(+10/-5,3)* 125 ± ` +`code ⌁24% ⌂42% 3d/2&/1z [user@server:~/ … /code/liquidprompt]↥ master(+10/-5,3)*+ 125 ± ` It displays: @@ -48,9 +48,9 @@ any; terminal multiplexer (screen or tmux); * the current user, in bold yellow if it is root, in light white if it is not the same as the login user; -* a blue @ if the connection has X11 support; -* the current host, if you are connected via an SSH or telnet connection, with -different colors for each case; +* a green @ if the connection has X11 support, a yellow one if not; +* the current host, if you are connected via a telnet connection (in bold red) +or SSH (either a blue hostname or differents colors for different hosts); * a green colon if the user has write permissions on the current directory, a red one if he has not; * the current directory in bold, shortened if it takes too much space, while @@ -58,7 +58,7 @@ preserving the first two directories; * the current Python virtual environment, if any; * an up arrow if an HTTP proxy is in use; * the name of the current branch if you are in a version control repository -(git, mercurial, subversion or fossil), in green if everything is up +(git, mercurial, subversion, bazaar or fossil), in green if everything is up to date, in red if there is changes, in yellow if there is pending commits to push; * the number of added/deleted lines (git) or files (fossil), if @@ -138,6 +138,7 @@ building: * `LP_ENABLE_VCS_ROOT`, if you want to show VCS informations with root account * `LP_ENABLE_TITLE`, if you want to use the prompt as your terminal window's title * `LP_ENABLE_SCREEN_TITLE`, if you want to use the prompt as your screen window's title +* `LP_ENABLE_SSH_COLORS`, if you want different colors for hosts you SSH in Note that if required commands are not installed, enabling the corresponding feature will have no effect. diff --git a/liquidprompt b/liquidprompt index 0785fc5..a152884 100755 --- a/liquidprompt +++ b/liquidprompt @@ -216,6 +216,7 @@ _lp_source_config() LP_ENABLE_VCS_ROOT=${LP_ENABLE_VCS_ROOT:-0} LP_ENABLE_TITLE=${LP_ENABLE_TITLE:-0} LP_ENABLE_SCREEN_TITLE=${LP_ENABLE_SCREEN_TITLE:-0} + LP_ENABLE_SSH_COLORS=${LP_ENABLE_SSH_COLORS:-0} LP_DISABLED_VCS_PATH=${LP_DISABLED_VCS_PATH:-""} LP_MARK_BATTERY=${LP_MARK_BATTERY:-"⌁"} @@ -384,7 +385,20 @@ lcl) fi ;; ssh) - LP_HOST="${LP_HOST}${LP_COLOR_SSH}${_LP_HOST_SYMBOL}${NO_COL}" + # If we want a different color for each host + if [[ "$LP_ENABLE_SSH_COLORS" ]]; then + # compute the hash of the hostname + # and get the corresponding number in [1-6] (red,green,yellow,blue,purple or cyan) + # FIXME check portability of cksum and add more formats (bold? 256 colors?) + hash=$(( 1 + $(hostname | cksum | cut -d " " -f 1) % 6 )) + color=${_LP_OPEN_ESC}$(ti_setaf $hash)${_LP_CLOSE_ESC} + LP_HOST="${LP_HOST}${color}${_LP_HOST_SYMBOL}${NO_COL}" + unset hash + unset color + else + # the same color for all hosts + LP_HOST="${LP_HOST}${LP_COLOR_SSH}${_LP_HOST_SYMBOL}${NO_COL}" + fi ;; tel) LP_HOST="${LP_HOST}${LP_COLOR_TELNET}${_LP_HOST_SYMBOL}${NO_COL}" diff --git a/liquidpromptrc-dist b/liquidpromptrc-dist index 731d2ce..32b11dc 100644 --- a/liquidpromptrc-dist +++ b/liquidpromptrc-dist @@ -100,6 +100,9 @@ LP_ENABLE_TITLE=0 # Enable Title for screen and byobu LP_ENABLE_SCREEN_TITLE=0 +# Use differents colors for differents hosts you SSH in +LP_ENABLE_SSH_COLORS=0 + # Specify a list of complete and colon (":") separated paths in which, all vcs # will be disabled LP_DISABLED_VCS_PATH="" From d8d7e28be3a34fd79ccafa3ef26c2849b9fca27f Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Tue, 12 Mar 2013 20:33:25 +0100 Subject: [PATCH 02/24] Issue #107 - same error appears with LP_ENABLE_SSH_COLORS new feature Same problem as #107, same solution ;) --- liquidprompt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquidprompt b/liquidprompt index a152884..1a865d0 100755 --- a/liquidprompt +++ b/liquidprompt @@ -386,7 +386,7 @@ lcl) ;; ssh) # If we want a different color for each host - if [[ "$LP_ENABLE_SSH_COLORS" ]]; then + if [[ "$LP_ENABLE_SSH_COLORS" -eq "1" ]]; then # compute the hash of the hostname # and get the corresponding number in [1-6] (red,green,yellow,blue,purple or cyan) # FIXME check portability of cksum and add more formats (bold? 256 colors?) From e8649fc440d9c86a05c213d56505d4e4fb65a3fc Mon Sep 17 00:00:00 2001 From: Jonas Bengtsson Date: Tue, 12 Mar 2013 20:47:52 +0100 Subject: [PATCH 03/24] git: Add support for detached head state --- liquidprompt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/liquidprompt b/liquidprompt index 0785fc5..c5d87f2 100755 --- a/liquidprompt +++ b/liquidprompt @@ -660,6 +660,10 @@ _lp_git_branch() local gitdir="$(git rev-parse --git-dir 2>/dev/null)" [[ $? -ne 0 || "${gitdir##*/}" != .git ]] && return local branch="$(git symbolic-ref HEAD 2>/dev/null)" + if [[ $? -ne 0 || -z "$branch" ]] ; then + # In detached head state, use commit instead + branch="$(git rev-parse --short HEAD 2>/dev/null)" + fi [[ $? -ne 0 || -z "$branch" ]] && return echo "${branch#refs/heads/}" } From 6da70cc63d106dd9a6459926736fdc360845cf1a Mon Sep 17 00:00:00 2001 From: Jonas Bengtsson Date: Tue, 12 Mar 2013 20:51:22 +0100 Subject: [PATCH 04/24] git: check the correct remote branch for has_commit Previously it was always checking against origin/$branch, but the remote branch can have any name and the remote branch can also have any name. --- liquidprompt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/liquidprompt b/liquidprompt index c5d87f2..b7be217 100755 --- a/liquidprompt +++ b/liquidprompt @@ -704,10 +704,18 @@ _lp_git_branch_color() has_stash="$LP_COLOR_COMMITS$LP_MARK_STASH" fi + local remote + remote="$(git config --get branch.${branch}.remote 2>/dev/null)" + local remote_branch + remote_branch="$(git config --get branch.${branch}.merge 2>/dev/null)" + local has_commit - has_commit=$(git rev-list --no-merges --count origin/${branch}..${branch} 2>/dev/null) - if [[ -z "$has_commit" ]] ; then - has_commit=0 + has_commit=0 + if [[ -n "$remote" && -n "$remote_branch" ]] ; then + has_commit=$(git rev-list --no-merges --count $remote/${remote_branch}..${branch} 2>/dev/null) + if [[ -z "$has_commit" ]] ; then + has_commit=0 + fi fi if [[ "$GD" -eq 1 || "$GDC" -eq "1" ]] ; then local has_line From 48743da6e3b865d52e80d7eec7f6402f3f802ea7 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Tue, 12 Mar 2013 21:02:28 +0100 Subject: [PATCH 05/24] Fix custom.ps1 sourcing --- liquidprompt | 2 ++ liquidpromptrc-dist | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/liquidprompt b/liquidprompt index 0785fc5..0a6d2b0 100755 --- a/liquidprompt +++ b/liquidprompt @@ -1299,6 +1299,8 @@ _lp_set_prompt() esac fi + source $LP_PS1_FILE + if [[ -z $LP_PS1 ]] ; then # add title escape time, jobs, load and battery PS1="${LP_PS1_PREFIX}${LP_TIME}${LP_BATT}${LP_LOAD}${LP_JOBS}" diff --git a/liquidpromptrc-dist b/liquidpromptrc-dist index 731d2ce..9bd6987 100644 --- a/liquidpromptrc-dist +++ b/liquidpromptrc-dist @@ -6,7 +6,7 @@ # If you want to use different themes and features, # you can load the corresponding files here: #source ~/code/liquidprompt/nojhan.theme -#source ~/code/liquidprompt/nojhan.ps1 +#LP_PS1_FILE="~/code/liquidprompt/nojhan.ps1" ############# # BEHAVIOUR # From bb992127ee08a081c1bf9fae9911794987bfcac1 Mon Sep 17 00:00:00 2001 From: nojhan Date: Tue, 12 Mar 2013 22:14:09 +0100 Subject: [PATCH 06/24] bugfix: do not try to source if there is no file --- liquidprompt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/liquidprompt b/liquidprompt index 47c019f..2fd0f3f 100755 --- a/liquidprompt +++ b/liquidprompt @@ -1330,7 +1330,9 @@ _lp_set_prompt() esac fi - source $LP_PS1_FILE + if [[ -f "$LP_PS1_FILE" ]]; then + source "$LP_PS1_FILE" + fi if [[ -z $LP_PS1 ]] ; then # add title escape time, jobs, load and battery From 9d4ded579961ad2d90c47d1b26a82eb61839d215 Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 13 Mar 2013 11:56:28 +0100 Subject: [PATCH 07/24] Update the README Bazaar support and LP_PS1_FILE were missing. --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 363e490..6453f9f 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ it only when he is different from the logged one You can also force some features to be disabled, to save some time in the prompt building: * `LP_ENABLE_PERM`, if you want to detect if the directory is writable -* `LP_ENABLE_SHORTEN_PATH`, if you to shorten the path display +* `LP_ENABLE_SHORTEN_PATH`, if you want to shorten the path display * `LP_ENABLE_PROXY`, if you want to detect if a proxy is used * `LP_ENABLE_JOBS`, if you want to have jobs informations * `LP_ENABLE_LOAD`, if you want to have load informations @@ -134,6 +134,7 @@ building: * `LP_ENABLE_GIT`, if you want to have git informations * `LP_ENABLE_SVN`, if you want to have subversion informations * `LP_ENABLE_HG`, if you want to have mercurial informations +* `LP_ENABLE_BZR`, if you want to have bazaar informations * `LP_ENABLE_FOSSIL`, if you want to have fossil informations * `LP_ENABLE_VCS_ROOT`, if you want to show VCS informations with root account * `LP_ENABLE_TITLE`, if you want to use the prompt as your terminal window's title @@ -174,6 +175,10 @@ a keyword to your different terminals: You can sort what you want to see by sourcing your favorite template file (`*.ps1`) in the configuration file. +You can start from the `liquid.ps1` file, which show the default settings. +To use your own configuration, just set `LP_PS1_FILE` to your own file path in +your `~/.liquipromptrc` and you're done. + Those scripts basically export the `LP_PS1` variable, by appending features and theme colors. @@ -244,7 +249,7 @@ Set to a null string "" if you do not want color. * `LP_COLOR_TELNET` connected via telnet * `LP_COLOR_X11_ON` connected with X11 support * `LP_COLOR_X11_OFF` connected without X11 support -* Separation mark (aka permiison in the working dir) +* Separation mark (by default, the colon before the path) * `LP_COLOR_WRITE` have write permission * `LP_COLOR_NOWRITE` do not have write permission * VCS @@ -270,6 +275,7 @@ Special characters: * `LP_MARK_SVN` (default: "‡") prompt mark in svn repositories * `LP_MARK_GIT` (default: "±") prompt mark in git repositories * `LP_MARK_FOSSIL` (default: "⌘") prompt mark in fossil repositories +* `LP_MARK_BZR` (default: "⚯") prompt mark in bazaar repositories * `LP_MARK_UNTRACKED` (default: "*") if git has untracked files * `LP_MARK_STASH` (default: "+") if git has stashed modifications * `LP_MARK_BRACKET_OPEN` (default: "[") marks around the main part of the prompt From 5aa1484f051c2044f20ffa5525962122e86e852a Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 13 Mar 2013 12:14:48 +0100 Subject: [PATCH 08/24] More authors, sorted --- liquidprompt | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/liquidprompt b/liquidprompt index 2fd0f3f..2612a7c 100755 --- a/liquidprompt +++ b/liquidprompt @@ -24,18 +24,25 @@ # AUTHORS # ########### -# nojhan # Main author. -# Aurelien Requiem # Major clean refactoring, variable path length, error codes, several bugfixes. -# Joris Dedieu # Portability framework, FreeBSD support, bugfixes. -# Ludovic Rousseau # Lot of bugfixes. -# Yann 'Ze' Richard # Do not fail on missing commands. +# Alex Prengère # untracked git files +# Aurelien Requiem # Major clean refactoring, variable path length, error codes, several bugfixes. +# Clément Mathieu # Bazaar support +# David Loureiro # small portability fix +# Étienne Deparis # Fossil support +# Florian Le Frioux # Use ± mark when root in VCS dir. # François Schmidts # small code fix, _lp_get_dirtrim -# Thomas Debesse # Fix columns use. -# Florian Le Frioux # Use ± mark when root in VCS dir. -# Luc Didry # Zsh port -# Olivier Mengué # Major optimizations on host parsing -# Frédéric Lepied # Python virtual env -# Clément MATHIEU # Bazaar support +# Frédéric Lepied # Python virtual env +# Jonas Bengtsson # Git remotes fix +# Joris Dedieu # Portability framework, FreeBSD support, bugfixes. +# Joris Vaillant # small git fix +# Luc Didry # Zsh port, several fix +# Ludovic Rousseau # Lot of bugfixes. +# Nicolas Lacourte # screen title +# nojhan # Main author. +# Olivier Mengué # Major optimizations on host parsing +# Poil # speed improvements +# Thomas Debesse # Fix columns use. +# Yann 'Ze' Richard # Do not fail on missing commands. # See the README.md file for a summary of features. From b7ffd46f9b64dee510c03b88f9533e5f79101536 Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 13 Mar 2013 12:30:41 +0100 Subject: [PATCH 09/24] Add LP_PERCENTS_ALWAYS, can hide numeric values Do you want to display the percentages of load/batteries along with their corresponding marks? Set to 0 to only print the colored marks. Defaults to 1 (display percentages) --- liquidprompt | 77 +++++++++++++++++++++++++-------------------- liquidpromptrc-dist | 5 +++ 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/liquidprompt b/liquidprompt index 2612a7c..23fc097 100755 --- a/liquidprompt +++ b/liquidprompt @@ -200,6 +200,7 @@ _lp_source_config() LP_PATH_KEEP=${LP_PATH_KEEP:-2} LP_HOSTNAME_ALWAYS=${LP_HOSTNAME_ALWAYS:-0} LP_USER_ALWAYS=${LP_USER_ALWAYS:-1} + LP_PERCENTS_ALWAYS=${LP_PERCENTS_ALWAYS:-1} LP_PS1=${LP_PS1:-""} LP_PS1_PREFIX=${LP_PS1_PREFIX:-""} LP_TITLE_OPEN=${LP_TITLE_OPEN:-"\e]0;"} @@ -1054,35 +1055,39 @@ _lp_battery_color() elif [[ "$bat" != "" ]] ; then local ret ret="${LP_COLOR_DISCHARGING_UNDER}${mark}${NO_COL}" - if [[ ${bat} -le 100 ]] && [[ ${bat} -gt 80 ]] ; then # -20 - ret="${ret}${LP_COLORMAP_1}" - elif [[ ${bat} -le 80 ]] && [[ ${bat} -gt 65 ]] ; then # -15 - ret="${ret}${LP_COLORMAP_2}" - elif [[ ${bat} -le 65 ]] && [[ ${bat} -gt 50 ]] ; then # -15 - ret="${ret}${LP_COLORMAP_3}" - elif [[ ${bat} -le 50 ]] && [[ ${bat} -gt 40 ]] ; then # -10 - ret="${ret}${LP_COLORMAP_4}" - elif [[ ${bat} -le 40 ]] && [[ ${bat} -gt 30 ]] ; then # … - ret="${ret}${LP_COLORMAP_5}" - elif [[ ${bat} -le 30 ]] && [[ ${bat} -gt 20 ]] ; then - ret="${ret}${LP_COLORMAP_6}" - elif [[ ${bat} -le 20 ]] && [[ ${bat} -gt 10 ]] ; then - ret="${ret}${LP_COLORMAP_7}" - elif [[ ${bat} -le 10 ]] && [[ ${bat} -gt 5 ]] ; then - ret="${ret}${LP_COLORMAP_8}" - elif [[ ${bat} -le 5 ]] && [[ ${bat} -gt 0 ]] ; then - ret="${ret}${LP_COLORMAP_9}" - else - # for debugging purpose - ret="${ret}${LP_COLORMAP_0}" - fi - if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then - echo -ne "${ret}${bat}%${NO_COL}" - elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then - echo -ne "${ret}${bat}%%${NO_COL}" - fi - fi + if [[ "$LP_PERCENTS_ALWAYS" -eq "1" ]]; then + if [[ ${bat} -le 100 ]] && [[ ${bat} -gt 80 ]] ; then # -20 + ret="${ret}${LP_COLORMAP_1}" + elif [[ ${bat} -le 80 ]] && [[ ${bat} -gt 65 ]] ; then # -15 + ret="${ret}${LP_COLORMAP_2}" + elif [[ ${bat} -le 65 ]] && [[ ${bat} -gt 50 ]] ; then # -15 + ret="${ret}${LP_COLORMAP_3}" + elif [[ ${bat} -le 50 ]] && [[ ${bat} -gt 40 ]] ; then # -10 + ret="${ret}${LP_COLORMAP_4}" + elif [[ ${bat} -le 40 ]] && [[ ${bat} -gt 30 ]] ; then # … + ret="${ret}${LP_COLORMAP_5}" + elif [[ ${bat} -le 30 ]] && [[ ${bat} -gt 20 ]] ; then + ret="${ret}${LP_COLORMAP_6}" + elif [[ ${bat} -le 20 ]] && [[ ${bat} -gt 10 ]] ; then + ret="${ret}${LP_COLORMAP_7}" + elif [[ ${bat} -le 10 ]] && [[ ${bat} -gt 5 ]] ; then + ret="${ret}${LP_COLORMAP_8}" + elif [[ ${bat} -le 5 ]] && [[ ${bat} -gt 0 ]] ; then + ret="${ret}${LP_COLORMAP_9}" + else + # for debugging purpose + ret="${ret}${LP_COLORMAP_0}" + fi + + if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then + ret="${ret}${bat}%" + elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then + ret="${ret}${bat}%%" + fi + fi # LP_PERCENTS_ALWAYS + echo -ne "${ret}${NO_COL}" + fi # ret } @@ -1109,7 +1114,7 @@ _lp_load_color() if [[ $load -ge $LP_LOAD_THRESHOLD ]] then local ret - ret="${LP_MARK_LOAD}" + ret="" if [[ $load -ge 0 ]] && [[ $load -lt 20 ]] ; then ret="${ret}${LP_COLORMAP_0}" elif [[ $load -ge 20 ]] && [[ $load -lt 40 ]] ; then @@ -1133,12 +1138,16 @@ _lp_load_color() else ret="${ret}${LP_COLORMAP_0}" fi - if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then - ret="${ret}$load%${NO_COL}" - elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then - ret="${ret}$load%%${NO_COL}" + ret="$ret${LP_MARK_LOAD}" + + if [[ "$LP_PERCENTS_ALWAYS" -eq "1" ]]; then + if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then + ret="${ret}$load%" + elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then + ret="${ret}$load%%" + fi fi - echo -ne "${ret}" + echo -ne "${ret}${NO_COL}" fi } diff --git a/liquidpromptrc-dist b/liquidpromptrc-dist index 655a04c..712f950 100644 --- a/liquidpromptrc-dist +++ b/liquidpromptrc-dist @@ -38,6 +38,11 @@ LP_HOSTNAME_ALWAYS=0 # set to 0 if you want to hide the logged user (it will always display different users) LP_USER_ALWAYS=1 +# Do you want to display the percentages of load/batteries along with their +# corresponding marks? Set to 0 to only print the colored marks. +# Defaults to 1 (display percentages) +LP_PERCENTS_ALWAYS=1 + # Do you want to use the permissions feature ? # Recommended value is 1 LP_ENABLE_PERM=1 From 92bd93390580f353e73700d951c9ca5e85086a18 Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 13 Mar 2013 15:58:56 +0100 Subject: [PATCH 10/24] Escape strings that may comes from remote sources Use printf "%q" to escape branch names. --- liquidprompt | 101 ++++++++++++++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 46 deletions(-) diff --git a/liquidprompt b/liquidprompt index 23fc097..1febfe9 100755 --- a/liquidprompt +++ b/liquidprompt @@ -317,6 +317,13 @@ unset _lp_source_config [[ "$LP_ENABLE_BZR" = 1 ]] && { command -v bzr > /dev/null || LP_ENABLE_BZR=0 ; } [[ "$LP_ENABLE_BATT" = 1 ]] && { command -v acpi >/dev/null || LP_ENABLE_BATT=0 ; } +# Escape the given strings +# Must be used for all strings that may comes from remote sources, +# like VCS branch names +_lp_escape() +{ + printf "%q" "$*" +} ############### @@ -688,7 +695,8 @@ _lp_git_branch() branch="$(git rev-parse --short HEAD 2>/dev/null)" fi [[ $? -ne 0 || -z "$branch" ]] && return - echo "${branch#refs/heads/}" + branch="${branch#refs/heads/}" + echo $(_lp_escape "$branch") } # Set a color depending on the branch state: @@ -772,7 +780,8 @@ _lp_hg_branch() [[ "$LP_ENABLE_HG" != 1 ]] && return local branch branch="$(hg branch 2>/dev/null)" - [[ $? -eq 0 ]] && echo "$branch" + [[ $? -eq 0 ]] && echo $(_lp_escape "$branch") + } # Set a color depending on the branch state: @@ -813,7 +822,7 @@ _lp_svn_branch() echo trunk else result=$(expr "$url" : '.*/branches/\([^/]*\)' || expr "$url" : '/\([^/]*\)' || basename "$root") - echo $result + echo $(_lp_escape "$result") fi } @@ -851,11 +860,11 @@ _lp_fossil_branch() local branch branch=$(fossil status 2>/dev/null | grep tags: | cut -c17-) if [[ -n "$branch" ]] ; then - echo "$branch" + echo $(_lp_escape "$branch") else - if fossil info &>/dev/null ; then - echo "no-tag" - fi + if fossil info &>/dev/null ; then + echo "no-tag" + fi fi } @@ -875,52 +884,52 @@ _lp_fossil_branch_color() branch=$(_lp_fossil_branch) if [[ ! -z "$branch" ]] ; then - local C2E # Modified files (added or edited) - local C2D # Deleted files - local C2A # Extras files - local ret - C2E=$(fossil changes | wc -l) - C2D=$(fossil changes | grep DELETED | wc -l) - let "C2E = $C2E - $C2D" - C2A=$(fossil extras | wc -l) - ret="" + local C2E # Modified files (added or edited) + local C2D # Deleted files + local C2A # Extras files + local ret + C2E=$(fossil changes | wc -l) + C2D=$(fossil changes | grep DELETED | wc -l) + let "C2E = $C2E - $C2D" + C2A=$(fossil extras | wc -l) + ret="" - if [[ "$C2E" -gt 0 ]] ; then - ret+="+$C2E" - fi + if [[ "$C2E" -gt 0 ]] ; then + ret+="+$C2E" + fi - if [[ "$C2D" -gt 0 ]] ; then - if [[ "$ret" = "" ]] ; then - ret+="-$C2D" - else - ret+="/-$C2D" - fi - fi + if [[ "$C2D" -gt 0 ]] ; then + if [[ "$ret" = "" ]] ; then + ret+="-$C2D" + else + ret+="/-$C2D" + fi + fi - if [[ "$C2A" -gt 0 ]] ; then - C2A="$LP_MARK_UNTRACKED" - else - C2A="" - fi + if [[ "$C2A" -gt 0 ]] ; then + C2A="$LP_MARK_UNTRACKED" + else + C2A="" + fi - if [[ "$ret" != "" ]] ; then - ret="(${LP_COLOR_DIFF}$ret${NO_COL})" - fi + if [[ "$ret" != "" ]] ; then + ret="(${LP_COLOR_DIFF}$ret${NO_COL})" + fi - if [[ "$branch" = "no-tag" ]] ; then + if [[ "$branch" = "no-tag" ]] ; then # Warning, your branch has no tag name ! - branch="${LP_COLOR_COMMITS}$branch${NO_COL}$ret${LP_COLOR_COMMITS}$C2A${NO_COL}" - else + branch="${LP_COLOR_COMMITS}$branch${NO_COL}$ret${LP_COLOR_COMMITS}$C2A${NO_COL}" + else if [[ "$C2E" -eq 0 && "$C2D" -eq 0 ]] ; then # All is up-to-date - branch="${LP_COLOR_UP}$branch$C2A${NO_COL}" + branch="${LP_COLOR_UP}$branch$C2A${NO_COL}" else # There're some changes to commit - branch="${LP_COLOR_CHANGES}$branch${NO_COL}$ret${LP_COLOR_CHANGES}$C2A${NO_COL}" + branch="${LP_COLOR_CHANGES}$branch${NO_COL}$ret${LP_COLOR_CHANGES}$C2A${NO_COL}" fi - fi - echo -ne "$branch" + fi + echo $(_lp_escape "$branch") fi } @@ -930,10 +939,10 @@ _lp_fossil_branch_color() _lp_bzr_branch() { [[ "$LP_ENABLE_BZR" != 1 ]] && return - local output - output=$(bzr nick 2> /dev/null) + local branch + branch=$(bzr nick 2> /dev/null) [[ $? -ne 0 ]] && return - echo "$output" + echo $(_lp_escape "$branch") } @@ -957,7 +966,7 @@ _lp_bzr_branch_color() if [[ "$clean" -eq 0 ]] ; then ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_COMMITS}$revno${NO_COL})" else - ret="${LP_COLOR_UP}${branch}${NO_COL}(${LP_COLOR_COMMITS}$revno${NO_COL})" + ret="${LP_COLOR_UP}${branch}${NO_COL}(${LP_COLOR_COMMITS}$revno${NO_COL})" fi fi @@ -1271,7 +1280,7 @@ _lp_set_prompt() case "$LP_OS" in Linux|FreeBSD|SunOS) $LP_OLD_PROMPT_COMMAND ;; Darwin) - case "$(LP_DWIN_KERNEL_REL_VER)" in + case "$(LP_DWIN_KERNEL_REL_VER)" in 11|12) update_terminal_cwd ;; *) $LP_OLD_PROMPT_COMMAND ;; esac ;; From 8beba7babe93b48ff7a358c5fc9fc0196fcb1da6 Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 13 Mar 2013 16:09:46 +0100 Subject: [PATCH 11/24] Handle cases where git has no upstream with default locals --- liquidprompt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/liquidprompt b/liquidprompt index 1febfe9..872d3c5 100755 --- a/liquidprompt +++ b/liquidprompt @@ -739,8 +739,16 @@ _lp_git_branch_color() local remote remote="$(git config --get branch.${branch}.remote 2>/dev/null)" + # if git has no upstream, use origin + if [[ -z "$remote" ]]; then + remote="origin" + fi local remote_branch remote_branch="$(git config --get branch.${branch}.merge 2>/dev/null)" + # without any remote branch, use the same name + if [[ -z "$remote_branch" ]]; then + remote_branch="$branch" + fi local has_commit has_commit=0 From a00944c490c9e49ca842d5f509c7abe8c991beb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Pajot?= Date: Wed, 13 Mar 2013 18:31:26 +0100 Subject: [PATCH 12/24] Add some Mercurial informations : nb of lines inserted, deleted and nb of changes to commit --- liquidprompt | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/liquidprompt b/liquidprompt index 4557e67..5e72ac3 100755 --- a/liquidprompt +++ b/liquidprompt @@ -754,10 +754,37 @@ _lp_hg_branch_color() local ret branch=$(_lp_hg_branch) if [[ ! -z "$branch" ]] ; then - if [[ $(( $(hg status --quiet -n | wc -l) )) = 0 ]] ; then - ret="${LP_COLOR_UP}${branch}${NO_COL}" + + local has_untracked + has_untracked=$(hg status 2>/dev/null | grep '\(^\?\)' | wc -l) + if [[ -z "$has_untracked" ]] ; then + has_untracked="" else - ret="${LP_COLOR_CHANGES}${branch}${NO_COL}" # changes to commit + has_untracked="$LP_COLOR_CHANGES$LP_MARK_UNTRACKED" + fi + + local has_commit + has_commit=$(hg outgoing --no-merges ${branch} 2>/dev/null | grep '\(^changeset\:\)' | wc -l) + if [[ -z "$has_commit" ]] ; then + has_commit=0 + fi + + if [[ $(( $(hg status --quiet -n | wc -l) )) = 0 ]] ; then + if [[ "$has_commit" -gt "0" ]] ; then + # some commit(s) to push + ret="${LP_COLOR_COMMITS}${branch}${NO_COL}(${LP_COLOR_COMMITS}$has_commit${NO_COL})${has_untracked}${NO_COL}" + else + ret="${LP_COLOR_UP}${branch}${has_untracked}${NO_COL}" # nothing to commit or push + fi + else + local has_line + has_lines=$(hg diff --stat 2>/dev/null | tail -n 1 | awk 'FS=" " {printf("+%s/-%s\n", $4, $6)}') + if [[ "$has_commit" -gt "0" ]] ; then + # Changes to commit and commits to push + ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL},${LP_COLOR_COMMITS}$has_commit${NO_COL})${has_untracked}${NO_COL}" + else + ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL})${has_untracked}${NO_COL}" # changes to commit + fi fi echo -ne "$ret" fi From 2869cbaeb4fb8e2ce60bf265b0ebec5ac4b98fe1 Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 13 Mar 2013 22:49:23 +0100 Subject: [PATCH 13/24] Test SVN root + temporary remove of result escape Now use a direct echo instead of an escaped string, should be fixed. --- liquidprompt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/liquidprompt b/liquidprompt index 872d3c5..4ba3f8f 100755 --- a/liquidprompt +++ b/liquidprompt @@ -824,13 +824,16 @@ _lp_svn_branch() local url local result eval $(LANG=C LC_ALL=C svn info 2>/dev/null | sed -n 's/^URL: \(.*\)/url="\1"/p;s/^Repository Root: \(.*\)/root="\1"/p' ) + if [[ "$root" == "" ]]; then + return + fi # Make url relative to root url="${url:${#root}}" if [[ "$url" == */trunk* ]] ; then - echo trunk + echo -n trunk else result=$(expr "$url" : '.*/branches/\([^/]*\)' || expr "$url" : '/\([^/]*\)' || basename "$root") - echo $(_lp_escape "$result") + echo -n $result # FIXME should be: echo -n $(_lp_escape "${result}") fi } From 8b1735659623cc4b7ed735215c9c51a1f4b4c06f Mon Sep 17 00:00:00 2001 From: Nicolas LACOURTE Date: Wed, 13 Mar 2013 23:36:15 +0100 Subject: [PATCH 14/24] Add git submodule support --- liquidprompt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquidprompt b/liquidprompt index 534ce9a..96db6f6 100755 --- a/liquidprompt +++ b/liquidprompt @@ -688,7 +688,7 @@ _lp_git_branch() [[ "$LP_ENABLE_GIT" != 1 ]] && return local gitdir gitdir="$(git rev-parse --git-dir 2>/dev/null)" - [[ $? -ne 0 || "${gitdir##*/}" != .git ]] && return + [[ $? -ne 0 || $gitdir =~ '*/.git*' ]] && return local branch="$(git symbolic-ref HEAD 2>/dev/null)" if [[ $? -ne 0 || -z "$branch" ]] ; then # In detached head state, use commit instead From ac927720612d3324be35e67b912de6a6e943e960 Mon Sep 17 00:00:00 2001 From: Nicolas LACOURTE Date: Wed, 13 Mar 2013 23:37:43 +0100 Subject: [PATCH 15/24] No title for linux console --- liquidprompt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/liquidprompt b/liquidprompt index 96db6f6..5ac0447 100755 --- a/liquidprompt +++ b/liquidprompt @@ -1234,6 +1234,9 @@ _lp_title() [[ "$LP_ENABLE_SCREEN_TITLE" != "1" ]] && return local title="${LP_SCREEN_TITLE_OPEN}${txt}${LP_SCREEN_TITLE_CLOSE}" ;; + linux*) + local title="" + ;; *) local title="${_LP_OPEN_ESC}${LP_TITLE_OPEN}${txt}${LP_TITLE_CLOSE}${_LP_CLOSE_ESC}" ;; From 9b9191823f668a91cbab39cfd786f7ea5ad21cdb Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Thu, 14 Mar 2013 08:33:21 +0100 Subject: [PATCH 16/24] Resolving Issue #115 --- liquidprompt | 1 - 1 file changed, 1 deletion(-) diff --git a/liquidprompt b/liquidprompt index 0785fc5..6f356d6 100755 --- a/liquidprompt +++ b/liquidprompt @@ -1014,7 +1014,6 @@ _lp_battery_color() # discharging and under threshold elif [[ "$bat" != "" ]] ; then - local ret ret="${LP_COLOR_DISCHARGING_UNDER}${mark}${NO_COL}" if [[ ${bat} -le 100 ]] && [[ ${bat} -gt 80 ]] ; then # -20 ret="${ret}${LP_COLORMAP_1}" From fc5da29acb5c019cb0c96a1d561c73cf8694f593 Mon Sep 17 00:00:00 2001 From: Brad Beyenhof Date: Thu, 14 Mar 2013 10:15:55 -0700 Subject: [PATCH 17/24] Handle remote sessions that have changed user Previously, if you were connected via SSH but had changed user with su/sudo, the _lp_connection function would report you as being connected via telnet. Now, if the parent process of your shell is 'su' or 'sudo', it sets the hostname to the color LP_COLOR_SU (default: bold yellow). This is probably only useful for people who have installed liquidprompt in a global location and run it with a globally-accessible shell config (/etc/profile or similar). But since there's already code to handle a current user of 'root', I assume this has already happened. --- liquidprompt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/liquidprompt b/liquidprompt index 5ac0447..a53cd1c 100755 --- a/liquidprompt +++ b/liquidprompt @@ -255,6 +255,7 @@ _lp_source_config() LP_COLOR_USER_ROOT=${_ROOT:-$BOLD_YELLOW} LP_COLOR_HOST=${LP_COLOR_HOST:-""} LP_COLOR_SSH=${LP_COLOR_SSH:-$BLUE} + LP_COLOR_SU=${LP_COLOR_SU:-$BOLD_YELLOW} LP_COLOR_TELNET=${LP_COLOR_TELNET:-$WARN_RED} LP_COLOR_X11_ON=${LP_COLOR_X11:-$GREEN} LP_COLOR_X11_OFF=${LP_COLOR_X11:-$YELLOW} @@ -353,13 +354,16 @@ fi _lp_connection() { - if [[ -n "$SSH_CLIENT$SSH2_CLIENT" ]] ; then + if [[ -n "$SSH_CLIENT$SSH2_CLIENT$SSH_TTY" ]] ; then echo ssh else # TODO check on *BSD local sess_src=$(who am i | sed -n 's/.*(\(.*\))/\1/p') + local sess_parent=$(ps -o comm= -p $PPID) if [[ -z "$sess_src" || "$sess_src" = ":"* ]] ; then echo lcl # Local + elif [[ "$sess_parent" = "su" || "$sess_parent" = "sudo" ]] ; then + echo su # Remote su/sudo else echo tel # Telnet fi @@ -415,6 +419,9 @@ ssh) LP_HOST="${LP_HOST}${LP_COLOR_SSH}${_LP_HOST_SYMBOL}${NO_COL}" fi ;; +su) + LP_HOST="${LP_HOST}${LP_COLOR_SU}${_LP_HOST_SYMBOL}${NO_COL}" + ;; tel) LP_HOST="${LP_HOST}${LP_COLOR_TELNET}${_LP_HOST_SYMBOL}${NO_COL}" ;; From 729459c9d983389b8d5d432e82e978f028eae55f Mon Sep 17 00:00:00 2001 From: "Julien Pecqueur (JPEC)" Date: Thu, 14 Mar 2013 20:09:06 +0100 Subject: [PATCH 18/24] Add Archlinux PKGBUILD. --- dist/archlinux-aur/PKGBUILD | 40 ++++++++++++++++++ .../liquidprompt-git-20130314-1.src.tar.gz | Bin 0 -> 657 bytes 2 files changed, 40 insertions(+) create mode 100644 dist/archlinux-aur/PKGBUILD create mode 100644 dist/archlinux-aur/liquidprompt-git-20130314-1.src.tar.gz diff --git a/dist/archlinux-aur/PKGBUILD b/dist/archlinux-aur/PKGBUILD new file mode 100644 index 0000000..6dfcfb3 --- /dev/null +++ b/dist/archlinux-aur/PKGBUILD @@ -0,0 +1,40 @@ +# Maintainer: Julien Pecqueur (JPEC) +pkgname=liquidprompt-git +pkgver=20130314 +pkgrel=1 +pkgdesc="An intelligent and non intrusive prompt for bash and zsh" +url="https://github.com/nojhan/liquidprompt" +arch=('any') +license=('AGPLv3') +depends=('acpi') +optdepends=('screen') +makedepends=('git') +md5sums=('SKIP') +_gitroot="git://github.com/nojhan/liquidprompt.git" +_gitname="liquidprompt" + +build() { + cd ${srcdir}/ + msg "Connecting to the GIT server...." + if [[ -d ${srcdir}/${_gitname} ]] ; then + cd ${_gitname} + git reset --hard + git pull origin + msg "The local files are updated..." + else + msg "Cloning git repo..." + git clone ${_gitroot} + cd ${_gitname} + fi + git reset --hard + msg "GIT checkout done." +} + +package() { + cd "${srcdir}/${_gitname}" + # install files + install -Dm755 liquidprompt "$pkgdir/usr/local/bin/liquidprompt" + install -Dm644 liquidpromptrc-dist "$pkgdir/etc/liquidpromptrc" +} + +# vim:set ts=2 sw=2 et: \ No newline at end of file diff --git a/dist/archlinux-aur/liquidprompt-git-20130314-1.src.tar.gz b/dist/archlinux-aur/liquidprompt-git-20130314-1.src.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..ded605ffcef44a30ac0a46cccb230b6ba3407e46 GIT binary patch literal 657 zcmV;C0&e{uiwFQ2AVN_91MO99PunmM=5v0#n z8-rs9+v&8S{`Z~JjFt|@7p4h~M{1LM?tJ(7&UK}@sYF&9U6igh6E50%e#CLy@Abex z37gNQk+hR`+-=8kCxJNWcG~?d==}vPzoD{@8IoeOc7KX{%D=g}7XrCC|Ka(`hcBlW z$In=U`fA}W?w zlYOp>Na?Gbsc2nG7%;>0boUKY-{0&7QgBoj$v!+8Ud%g0WmuxhtPkO(AVQaJ#aV6; z6|n`o#uZIPJ(u-tRe1aJ`RR~|uf+S~l7{s1q_%x>hxMAeh2eeO!K4y0+ueiP0Dxz( zb88LHgjqyn7j_2WkyZ-16KV!dgUb<4PA|ctp~mkMLJAa97>%H{zI^BQSIGs8$MDv# zR214&xpUSO8DP+&gH|hNCc7icN=nd1%*1kSt>}_8NX?mqsgP)a8HB3Ln8U2mgVN$E z{zz)&{=#t rJh~rHZ($qeq8RucJDaw_exomRgMWRiyy6wFcnSCk_)AO(01N;Ccos_b literal 0 HcmV?d00001 From 9221d0916cad546202b4621cbcad799b0a2c7ef7 Mon Sep 17 00:00:00 2001 From: polyphemus Date: Thu, 14 Mar 2013 22:41:09 +0100 Subject: [PATCH 19/24] tmux support. Cleanup of _lp_jobcount_color. Adds number of screens sessions and number of tmux sessions as a total of detached sessions. --- liquidprompt | 55 +++++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/liquidprompt b/liquidprompt index 5ac0447..50e1de2 100755 --- a/liquidprompt +++ b/liquidprompt @@ -596,50 +596,39 @@ _lp_virtualenv() # Related jobs # ################ -# Either attached running jobs (started with $ myjob &) -# or attached stopped jobs (suspended with Ctrl-Z) -# or detached screens sessions running on the host +# Display the count of each if non-zero: +# - detached screens sessions and/or tmux sessions running on the host +# - attached running jobs (started with $ myjob &) +# - attached stopped jobs (suspended with Ctrl-Z) _lp_jobcount_color() { [[ "$LP_ENABLE_JOBS" != 1 ]] && return local running=$(( $(jobs -r | wc -l) )) local stopped=$(( $(jobs -s | wc -l) )) - local screens=$(screen -ls 2> /dev/null | grep -c Detach ) # FIXME add tmux support + local n_screen=$(screen -ls 2> /dev/null | grep -c Detach) + local n_tmux=$(tmux list-sessions 2> /dev/null | wc -l) + local detached=$(( $n_screen + $n_tmux )) local m_detached="d" local m_stop="z" local m_run="&" - local rep + local ret="" - # d/&/z - if [[ $screens != "0" && $running != "0" && $stopped != "0" ]] ; then - rep="${LP_COLOR_JOB_D}${screens}${m_detached}${NO_COL}/${LP_COLOR_JOB_R}${running}${m_run}${NO_COL}/${LP_COLOR_JOB_Z}${stopped}${m_stop}${NO_COL}" - - # _/&/_ - elif [[ $screens == "0" && $running != "0" && $stopped == "0" ]] ; then - rep="${LP_COLOR_JOB_R}${running}${m_run}${NO_COL}" - - # _/_/z - elif [[ $screens == "0" && $running == "0" && $stopped != "0" ]] ; then - rep="${LP_COLOR_JOB_Z}${stopped}${m_stop}${NO_COL}" - - # d/_/_ - elif [[ $screens != "0" && $running == "0" && $stopped == "0" ]] ; then - rep="${LP_COLOR_JOB_D}${screens}${m_detached}${NO_COL}" - - # d/&/_ - elif [[ $screens != "0" && $running != "0" && $stopped == "0" ]] ; then - rep="${LP_COLOR_JOB_D}${screens}${m_detached}${NO_COL}/${LP_COLOR_JOB_R}${running}${m_run}${NO_COL}" - - # d/_/z - elif [[ $screens != "0" && $running == "0" && $stopped != "0" ]] ; then - rep="${LP_COLOR_JOB_D}${screens}${m_detached}${NO_COL}/${LP_COLOR_JOB_Z}${stopped}${m_stop}${NO_COL}" - - # _/&/z - elif [[ $screens == "0" && $running != "0" && $stopped != "0" ]] ; then - rep="${LP_COLOR_JOB_R}${running}${m_run}${NO_COL}/${LP_COLOR_JOB_Z}${stopped}${m_stop}${NO_COL}" + if [[ $detached != "0" ]] ; then + ret="${ret}${LP_COLOR_JOB_D}${detached}${m_detached}${NO_COL}" fi - echo -ne "$rep" + + if [[ $running != "0" ]] ; then + if [[ $ret != "" ]] ; then ret="${ret}/"; fi + ret="${ret}${LP_COLOR_JOB_R}${running}${m_run}${NO_COL}" + fi + + if [[ $stopped != "0" ]] ; then + if [[ $ret != "" ]] ; then ret="${ret}/"; fi + ret="${ret}${LP_COLOR_JOB_Z}${stopped}${m_stop}${NO_COL}" + fi + + echo -ne "$ret" } From ecfdc47a8d50bb79744bede6fa092637137e06da Mon Sep 17 00:00:00 2001 From: polyphemus Date: Thu, 14 Mar 2013 22:58:27 +0100 Subject: [PATCH 20/24] Only match detached tmux sessions, not all. --- liquidprompt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquidprompt b/liquidprompt index 50e1de2..586aa0c 100755 --- a/liquidprompt +++ b/liquidprompt @@ -607,7 +607,7 @@ _lp_jobcount_color() local running=$(( $(jobs -r | wc -l) )) local stopped=$(( $(jobs -s | wc -l) )) local n_screen=$(screen -ls 2> /dev/null | grep -c Detach) - local n_tmux=$(tmux list-sessions 2> /dev/null | wc -l) + local n_tmux=$(tmux list-sessions 2> /dev/null | grep -cv attached) local detached=$(( $n_screen + $n_tmux )) local m_detached="d" local m_stop="z" From 9bae88a686ef7fb5148d52bb58f6b72e737218a6 Mon Sep 17 00:00:00 2001 From: polyphemus Date: Thu, 14 Mar 2013 23:18:20 +0100 Subject: [PATCH 21/24] update README about tmux support. --- README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6453f9f..dd96997 100644 --- a/README.md +++ b/README.md @@ -39,13 +39,13 @@ a red ⌁ if the battery is discharging but above threshold; threshold, with a colormap, going more and more red with decreasing power; * the average of the processors load, if it is over a given limit, with a colormap that became more and more noticeable with increasing load; -* the number of detached sessions (`screen`), if there is any; +* the number of detached sessions (`screen` or `tmux`), if there are any; * the number of attached sleeping jobs (when you interrupt a command with Ctrl-Z -and bring it back with `fg`), if there is any; -* the number of attached running jobs (commands started with a `&`), if there is +and bring it back with `fg`), if there are any; +* the number of attached running jobs (commands started with a `&`), if there are any; * a pair of square brackets, in blue if your current shell is running in a -terminal multiplexer (screen or tmux); +terminal multiplexer (`screen` or `tmux`); * the current user, in bold yellow if it is root, in light white if it is not the same as the login user; * a green @ if the connection has X11 support, a yellow one if not; @@ -98,8 +98,8 @@ Apart from obvious ones, some features depends on specific commands. If you do not install them, the corresponding feature will not be available, but you will see no error. -* battery status need `acpi`, -* detached sessions is looking for `screen`. +* battery status needs `acpi`. +* detached sessions is looking for `screen` and/or `tmux`. * VCS support features needs… `git`, `hg` or `svn`, but you knew it. For other features, the script uses commands that should be available on a large @@ -185,7 +185,7 @@ theme colors. Available features: * `LP_BATT` battery * `LP_LOAD` load -* `LP_JOBS` screen sessions/running jobs/suspended jobs +* `LP_JOBS` detached screen or tmux sessions/running jobs/suspended jobs * `LP_USER` user * `LP_HOST` hostname * `LP_PERM` a colon ":" @@ -230,7 +230,7 @@ Set to a null string "" if you do not want color. * Color of the proxy mark * `LP_COLOR_PROXY` * Jobs count - * `LP_COLOR_JOB_D` Detached (aka screen sessions) + * `LP_COLOR_JOB_D` Detached (screen/tmux sessions without attached clients) * `LP_COLOR_JOB_R` Running (xterm &) * `LP_COLOR_JOB_Z` Sleeping (Ctrl-Z) * `LP_COLOR_IN_MULTIPLEXER` currently running in a terminal multiplexer @@ -291,7 +291,6 @@ Special characters: Liquid prompt is distributed under the GNU Affero General Public License version 3. -* detached sessions only looks for `screen`, a `tmux` support would be nice… * Does not display the number of commits to be pushed in Mercurial repositories. * Browsing into very large subversion repositories may dramatically slow down the display of the liquid prompt. From 79e51ded84eca357880c6d027eca1c8cd1545e94 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Wed, 20 Mar 2013 13:56:44 +0100 Subject: [PATCH 22/24] Use a double mark for git-svn repos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the current git repository is a git-svn one (if it has a .git/svn directory), use ±‡ as a prompt instead of just ±. --- liquidprompt | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/liquidprompt b/liquidprompt index 311632b..bfd0c84 100755 --- a/liquidprompt +++ b/liquidprompt @@ -1164,6 +1164,8 @@ _lp_smart_mark() fi if [[ "$1" == "git" ]]; then mark=$LP_MARK_GIT + elif [[ "$1" == "git-svn" ]]; then + mark="$LP_MARK_GIT$LP_MARK_SVN" elif [[ "$1" == "hg" ]]; then mark=$LP_MARK_HG elif [[ "$1" == "svn" ]]; then @@ -1224,7 +1226,7 @@ _lp_set_prompt() case "$LP_OS" in Linux|FreeBSD|SunOS) $LP_OLD_PROMPT_COMMAND ;; Darwin) - case "$(LP_DWIN_KERNEL_REL_VER)" in + case "$(LP_DWIN_KERNEL_REL_VER)" in 11|12) update_terminal_cwd ;; *) $LP_OLD_PROMPT_COMMAND ;; esac ;; @@ -1255,6 +1257,12 @@ _lp_set_prompt() if [[ "$(_lp_are_vcs_disabled)" -eq "0" ]] ; then LP_VCS="$(_lp_git_branch_color)" LP_VCS_TYPES="git" + if [[ -n "$LP_VCS" ]]; then + # If this is a git-svn repository + if [[ -d "$(git rev-parse --git-dir 2>/dev/null)/svn" ]]; then + LP_VCS_TYPES="git-svn" + fi + fi # git-svn if [[ -z "$LP_VCS" ]]; then LP_VCS="$(_lp_hg_branch_color)" LP_VCS_TYPES="hg" @@ -1267,11 +1275,11 @@ _lp_set_prompt() if [[ -z "$LP_VCS" ]]; then LP_VCS="$(_lp_bzr_branch_color)" LP_VCS_TYPES="bzr" - fi - fi - fi - fi - fi + fi # bzr + fi # fossil + fi # svn + fi # hg + fi # disabled if [[ -z "$LP_VCS" ]] ; then LP_VCS_TYPES="" else From 0b0398015b3597f1bc5446dd8ca5db6181fe705c Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Wed, 20 Mar 2013 14:02:09 +0100 Subject: [PATCH 23/24] bugfix: display git-svn branches --- liquidprompt | 1 + 1 file changed, 1 insertion(+) diff --git a/liquidprompt b/liquidprompt index 2c0cc83..98f44f5 100755 --- a/liquidprompt +++ b/liquidprompt @@ -1392,6 +1392,7 @@ _lp_set_prompt() elif [[ -n "$LP_VCS_TYPES" ]]; then case "$LP_VCS_TYPES" in git) LP_VCS=$(_lp_sl "$(_lp_git_branch_color)");; + git-svn)LP_VCS=$(_lp_sl "$(_lp_git_branch_color)");; hg) LP_VCS=$(_lp_sl "$(_lp_hg_branch_color)");; svn) LP_VCS=$(_lp_sl "$(_lp_svn_branch_color)");; fossil) LP_VCS=$(_lp_sl "$(_lp_fossil_branch_color)");; From a1db31b7e3e79f1dba5a10eca3e79fa02acd68df Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Mon, 25 Mar 2013 19:40:04 +0100 Subject: [PATCH 24/24] Fix bad regex for submodule from #118 The regex in bash and zsh doesn't need to be quoted. It resulted a bad regex warning in zsh (#127) and it didn't worked in submodule. Plus, bash and zsh regexes have perlish syntax. --- liquidprompt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquidprompt b/liquidprompt index 98f44f5..460ad87 100755 --- a/liquidprompt +++ b/liquidprompt @@ -684,7 +684,7 @@ _lp_git_branch() [[ "$LP_ENABLE_GIT" != 1 ]] && return local gitdir gitdir="$(git rev-parse --git-dir 2>/dev/null)" - [[ $? -ne 0 || $gitdir =~ '*/.git*' ]] && return + [[ $? -ne 0 || ! $gitdir =~ (.*\/)?\.git.* ]] && return local branch="$(git symbolic-ref HEAD 2>/dev/null)" if [[ $? -ne 0 || -z "$branch" ]] ; then # In detached head state, use commit instead