tmux support. Cleanup of _lp_jobcount_color. Adds number of screens sessions and number of tmux sessions as a total of detached sessions.

This commit is contained in:
polyphemus 2013-03-14 22:41:09 +01:00
parent 9d42e53c1e
commit 9221d0916c

View File

@ -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"
}