From 5db1507b96578b76627f60f8cbfb81a61f7b5878 Mon Sep 17 00:00:00 2001 From: Poil Date: Mon, 13 Aug 2012 20:40:36 +0200 Subject: [PATCH 1/3] Small improvement --- liquidprompt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/liquidprompt b/liquidprompt index 4f99ed3..2aefd4a 100755 --- a/liquidprompt +++ b/liquidprompt @@ -195,7 +195,7 @@ __cpunum_Darwin() __cpunum_SunOS() { - kstat -m cpu_info | grep "module: cpu_info" | wc -l + kstat -m cpu_info | grep -c "module: cpu_info" } __CPUNUM=$(__cpunum_$OS) @@ -256,8 +256,8 @@ __user() __connection() { - THIS_TTY=tty$(ps aux | grep $$ | grep bash | awk '{ print $7 }') - SESS_SRC=$(who | grep $THIS_TTY | awk '{ print $6 }') + THIS_TTY=tty$(ps aux | awk -v pid=$$ '$0 ~ pid && /bash/{ print $7 }') + SESS_SRC=$(who | awk -v thistty="$THIS_TTY" '$0 ~ thistty { print $6 }') # Are we in an SSH connexion? SSH_FLAG=0 @@ -438,8 +438,8 @@ __permissions_color() # or detached screens sessions running on the host __jobcount_color() { - local running=$(jobs -r | wc -l | tr -d " ") - local stopped=$(jobs -s | wc -l | tr -d " ") + local running=$(( $(jobs -r | wc -l) )) + local stopped=$(( $(jobs -s | wc -l) )) local screens=$(screen -ls 2> /dev/null | grep -c Detach ) local m_detached="d" local m_stop="z" @@ -562,7 +562,7 @@ __hg_branch_color() command -v hg >/dev/null 2>&1 || return 1; branch=$(__hg_branch) if [[ ! -z "$branch" ]] ; then - if [[ $(hg status --quiet -n | wc -l | sed -e "s/ //g") = 0 ]] ; then + if [[ $(( $(hg status --quiet -n | wc -l) )) = 0 ]] ; then ret="${GREEN}${branch}${NO_COL}" else ret="${RED}${branch}${NO_COL}" # changes to commit @@ -601,8 +601,7 @@ __svn_branch_color() command -v svn >/dev/null 2>&1 || return 1; branch=$(__svn_branch) if [[ ! -z "$branch" ]] ; then - commits=$(svn status | grep -v "?" | wc -l) - commits=$((commits)) + commits=$(( $(svn status | grep -v "?" | wc -l) )) if [[ $commits = 0 ]] ; then ret="${GREEN}${branch}${NO_COL}" else From 7e8fc0e01fb6b366938b680eebc8fb6771cc9a08 Mon Sep 17 00:00:00 2001 From: Poil Date: Mon, 13 Aug 2012 20:47:29 +0200 Subject: [PATCH 2/3] New shell detection --- liquidprompt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquidprompt b/liquidprompt index 2aefd4a..987f4e6 100755 --- a/liquidprompt +++ b/liquidprompt @@ -37,7 +37,7 @@ # See the README.md file for a summary of features. -WORKING_SHELL=$(ps -p $$ | tail -n1 | awk '{print $NF}') +WORKING_SHELL=${SHELL##*/} if [[ "$WORKING_SHELL" == "bash" ]]; then # Check for recent enough version of bash. From 09d6ff48a762b6c6ff017b6b9c55977ee7bb2ce4 Mon Sep 17 00:00:00 2001 From: Poil Date: Mon, 13 Aug 2012 21:01:33 +0200 Subject: [PATCH 3/3] Other improvment --- liquidprompt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/liquidprompt b/liquidprompt index 987f4e6..4ef5bbf 100755 --- a/liquidprompt +++ b/liquidprompt @@ -580,8 +580,8 @@ __svn_branch() infos=$(svn info --xml 2>/dev/null) ret=$? if [[ $ret -eq 0 ]] ; then - root=$(echo "$infos" | grep "^" | sed "s/^.*\/\([^\/]*\)<\/root>$/\1/") - subrep=$(echo "$infos" | grep "^" | sed "s/^.*\/$root\/\(.*\)<\/url>$/\1/") + root=$(echo "$infos" | awk -v FS=">|/ { print $2 }') + subrep=$(echo "$infos" | awk -v FS=">|/ { print $2 }') if [[ "$subrep" == *"url>"* ]] ; then echo -n $root else @@ -601,7 +601,7 @@ __svn_branch_color() command -v svn >/dev/null 2>&1 || return 1; branch=$(__svn_branch) if [[ ! -z "$branch" ]] ; then - commits=$(( $(svn status | grep -v "?" | wc -l) )) + commits=$(( $(svn status | grep -v "?" -c) )) if [[ $commits = 0 ]] ; then ret="${GREEN}${branch}${NO_COL}" else