From 9221d0916cad546202b4621cbcad799b0a2c7ef7 Mon Sep 17 00:00:00 2001 From: polyphemus Date: Thu, 14 Mar 2013 22:41:09 +0100 Subject: [PATCH] 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" }