From 93b701a6373d9f240317eded8da8dfea30b956e9 Mon Sep 17 00:00:00 2001 From: nojhan Date: Tue, 31 Jul 2012 21:27:53 +0200 Subject: [PATCH 1/4] undo commit a00de370c58fe2c18a49944821e113617caff1c4, let Darwin be specific again --- liquidprompt.bash | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/liquidprompt.bash b/liquidprompt.bash index 4dd0aa7..353902f 100755 --- a/liquidprompt.bash +++ b/liquidprompt.bash @@ -80,7 +80,7 @@ OS="Linux" case $(uname) in "Linux" ) OS="Linux" ;; "FreeBSD") OS="FreeBSD" ;; - "Darwin") OS="FreeBSD" ;; + "Darwin") OS="Darwin" ;; "DragonFly") OS="FreeBSD" ;; "SunOS") OS="SunOS" ;; esac @@ -167,6 +167,11 @@ __cpunum_FreeBSD() sysctl -n hw.ncpu } +__cpunum_Darwin() +{ + __cpunum_FreeBSD +} + __cpunum_SunOS() { kstat -m cpu_info | grep "module: cpu_info" | wc -l @@ -189,6 +194,11 @@ __load_FreeBSD() echo -n "$load" } +__load_Darwin() +{ + __load_FreeBSD +} + __load_SunOS() { load=$(LANG=C uptime | awk '{print $10}'| sed -e 's/,//') From 8d5d088f1d91cbe1af4c3de59a132076cd72cd77 Mon Sep 17 00:00:00 2001 From: nojhan Date: Tue, 31 Jul 2012 22:15:07 +0200 Subject: [PATCH 2/4] move configuration variables in a separated file --- liquidprompt.bash | 37 ++++++++++++------------------------- liquidpromptrc-dist | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 liquidpromptrc-dist diff --git a/liquidprompt.bash b/liquidprompt.bash index 353902f..731c6fc 100755 --- a/liquidprompt.bash +++ b/liquidprompt.bash @@ -49,26 +49,13 @@ unset bash bmajor bminor # CONFIGURATION # ################# -# Maximal value under which the battery level is displayed -# Recommended value is 75 -BATTERY_THRESHOLD=75 +LP_BATTERY_THRESHOLD=75 +LP_LOAD_THRESHOLD=60 +LP_PATH_LENGTH=35 +LP_PATH_KEEP=2 +LP_REVERSE=0 -# Minimal value after which the load average is displayed -# Recommended value is 60 -LOAD_THRESHOLD=60 - -# The maximum percentage of the screen width used to display the path -# Recommended value is 35 -PATH_LENGTH=35 - -# How many directories to keep at the beginning of a shortened path -# Recommended value is 2 -PATH_KEEP=2 - -# Do we use reverse colors (black on white) instead of normal theme (white on black) -# Defaults to 0 (normal colors) -# set to 1 if you use black on white -REVERSE=0 +source ~/.liquidpromptrc 2> /dev/null ############### @@ -150,7 +137,7 @@ fi # can be set to white or black FG=$WHITE BOLD_FG=$BOLD_WHITE -if [[ $REVERSE == 1 ]] ; then +if [[ $LP_REVERSE == 1 ]] ; then FG=$BLACK BOLD_FG=$BOLD_GRAY fi @@ -300,7 +287,7 @@ __shorten_path() # the character that will replace the part of the path that is masked local mask=" … " # index of the directory to keep from the root (starts at 0) - local keep=$((PATH_KEEP-1)) + local keep=$((LP_PATH_KEEP-1)) local len_percent=$2 @@ -556,7 +543,7 @@ __battery() if [[ "${bat}" == "" ]] ; then return 1 fi - if [[ ${bat} -le $BATTERY_THRESHOLD ]] ; then + if [[ ${bat} -le $LP_BATTERY_THRESHOLD ]] ; then echo -n "${bat}" return 0 else @@ -571,7 +558,7 @@ __battery_color() if [[ "$?" = "1" ]] ; then return; fi; # no battery support if [[ "$bat" != "" ]] ; then - if [[ ${bat} -gt $BATTERY_THRESHOLD ]] ; then + if [[ ${bat} -gt $LP_BATTERY_THRESHOLD ]] ; then return; # nothing displayed above 75% fi @@ -614,7 +601,7 @@ __load_color() fi let "load=$load/$__CPUNUM" - if [[ $load -ge $LOAD_THRESHOLD ]] + if [[ $load -ge $LP_LOAD_THRESHOLD ]] then ret="l${NO_COL}" if [[ $load -lt 70 ]] ; then @@ -702,7 +689,7 @@ __set_bash_prompt() __USER=$(__user) __HOST=$(__host_color) __PERM=$(__permissions_color) - __PWD=$(__shorten_path $PWD $PATH_LENGTH) + __PWD=$(__shorten_path $PWD $LP_PATH_LENGTH) # right of main prompt: space at left __GIT=$(__sl "$(__git_branch_color)") diff --git a/liquidpromptrc-dist b/liquidpromptrc-dist new file mode 100644 index 0000000..08d4f14 --- /dev/null +++ b/liquidpromptrc-dist @@ -0,0 +1,26 @@ + +#################################### +# LIQUID PROMPT CONFIGURATION FILE # +#################################### + +# Maximal value under which the battery level is displayed +# Recommended value is 75 +LP_BATTERY_THRESHOLD=75 + +# Minimal value after which the load average is displayed +# Recommended value is 60 +LP_LOAD_THRESHOLD=60 + +# The maximum percentage of the screen width used to display the path +# Recommended value is 35 +LP_PATH_LENGTH=35 + +# How many directories to keep at the beginning of a shortened path +# Recommended value is 2 +LP_PATH_KEEP=2 + +# Do we use reverse colors (black on white) instead of normal theme (white on black) +# Defaults to 0 (normal colors) +# set to 1 if you use black on white +LP_REVERSE=0 + From 65b9e62ab37afc4965e0f35280e8b6898e48ba2d Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 1 Aug 2012 19:33:32 +0200 Subject: [PATCH 3/4] update the doc about the configuration --- README.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 345964a..af5ab0b 100644 --- a/README.md +++ b/README.md @@ -53,18 +53,35 @@ there is changes, in yellow if there is pending commits to push; * a smart mark: ± for VCS directories, $ for simple user, a red # for root. -## USAGE +## INSTALL Include the file in your bash configuration, for example in your `.bashrc`: `source liquidprompt.bash` +Copy the `liquidpromptrc-dist` file in your home directory as +`~/.liquidpromptrc` and edit it according to your preferences. If you skip this +step, the default behaviour will be used. + ## PUT THE PROMPT IN A DIFFERENT ORDER +You can configure some variables in the `~/.liquidpromptrc` file: + +* `LP_BATTERY_THRESHOLD`, the maximal value under which the battery level is +displayed +* `LP_LOAD_THRESHOLD`, the minimal value after which the load average is +displayed +* `LP_PATH_LENGTH`, the maximum percentage of the screen width used to display +the path +* `LP_PATH_KEEP`, how many directories to keep at the beginning of a shortened +path +* `LP_REVERSE`, choose between reverse colors (black on white) instead of normal +theme (white on black) + Most of the display is prepared in the `__set_bash_prompt` function, apart from features that needs several colors (such as the load colormap). You can sort -what you want to see by editing the PS1 variable. +what you want to see by editing the PS1 variable here. ## KNOWN LIMITATIONS AND BUGS From 7dc9e82d8a13fc75f12ea27efc79c2b69f5d4034 Mon Sep 17 00:00:00 2001 From: Thomas DEBESSE Date: Fri, 3 Aug 2012 21:29:59 +0200 Subject: [PATCH 4/4] bugfix: do not use 158 if not set, defaults to 80 --- liquidprompt.bash | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/liquidprompt.bash b/liquidprompt.bash index 731c6fc..475b9df 100755 --- a/liquidprompt.bash +++ b/liquidprompt.bash @@ -293,7 +293,14 @@ __shorten_path() local p=$(echo "$1" | sed -e "s|$HOME|~|") local len="${#p}" - local max_len=$(($COLUMNS*$len_percent/100)) + + if [ -z "$COLUMNS" ] + then + local columns=80 + else + local columns=$COLUMNS + fi + local max_len=$(($columns*$len_percent/100)) local mask_len="${#mask}" if [[ "$len" -gt "$max_len" ]]