add detached screen session count

This commit is contained in:
nojhan 2012-07-29 22:05:19 +02:00
parent f39fa12bc5
commit 1745851759
2 changed files with 23 additions and 12 deletions

View File

@ -24,7 +24,7 @@ in a git repository, on branch "myb":
A liquid prompt displaying everything may look like this: A liquid prompt displaying everything may look like this:
`25% 12.5 1s/1r [user@server:~/liquidprompt] master(3) 125 ± ` `25% 12.5 1s/1r/1t [user@server:~/liquidprompt] master(3) 125 ± `
It displays: It displays:
@ -32,6 +32,7 @@ It displays:
threshold, with a colormap too; threshold, with a colormap too;
* the average of the processors load, if it is over a given limit, with a * 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; colormap that became more and more noticeable with increasing load;
* the number of detached `screen` sessions, if there is any;
* the number of attached sleeping jobs (when you interrupt a command with Ctrl-Z * the number of attached sleeping jobs (when you interrupt a command with Ctrl-Z
and bring it back with `fg`), if there is any; and bring it back with `fg`), if there is any;
* the number of attached running jobs (commands started with a `&`), if there is * the number of attached running jobs (commands started with a `&`), if there is

View File

@ -23,7 +23,7 @@
# Below are function for having a flexible dynamic prompt for power user: # Below are function for having a flexible dynamic prompt for power user:
# - display the battery level (if necessary), with colormap (if any battery attached) # - display the battery level (if necessary), with colormap (if any battery attached)
# - if necessary, prints a counter for jobs that are attached to the current # - if necessary, prints a counter for jobs that are attached to the current
# term (e.g. xterm &) or that are sleeping (e.g. Ctrl-z) # term (e.g. xterm &) or that are sleeping (e.g. Ctrl-z) or detached "screen" sessions
# - display the load average, colored with a colormap # - display the load average, colored with a colormap
# - displays the colored login@hostname # - displays the colored login@hostname
# - when root displays in red # - when root displays in red
@ -265,20 +265,30 @@ __host_color()
# Either attached running jobs (started with $ myjob &) # Either attached running jobs (started with $ myjob &)
# or attached stopped jobs (suspended with Ctrl-Z) # or attached stopped jobs (suspended with Ctrl-Z)
# or detached screens sessions running on the host
__jobcount_color() __jobcount_color()
{ {
running=`jobs -r | wc -l | tr -d " "` local running=$(jobs -r | wc -l | tr -d " ")
stopped=`jobs -s | wc -l | tr -d " "` local stopped=$(jobs -s | wc -l | tr -d " ")
local screens=$(screen -ls | grep -c Detach )
if [ $running != "0" -a $stopped != "0" ] if [ $running != "0" -a $stopped != "0" -a $screens != "0" ] ; then
then rep="${NO_COL}${YELLOW}${screens}s${NO_COL}/${YELLOW}${running}r${NO_COL}/${LIGHT_YELLOW}${stopped}t${NO_COL}"
rep="${NO_COL}${YELLOW}${running}r${NO_COL}/${LIGHT_YELLOW}${stopped}s${NO_COL}"
elif [ $running != "0" -a $stopped == "0" ] elif [ $running != "0" -a $stopped == "0" -a $screens == "0" ] ; then
then
rep="${NO_COL}${YELLOW}${running}r${NO_COL}" rep="${NO_COL}${YELLOW}${running}r${NO_COL}"
elif [ $running == "0" -a $stopped != "0" ]
then elif [ $running == "0" -a $stopped != "0" -a $screens == "0" ] ; then
rep="${NO_COL}${LIGHT_YELLOW}${stopped}s${NO_COL}" rep="${NO_COL}${LIGHT_YELLOW}${stopped}t${NO_COL}"
elif [ $running == "0" -a $stopped == "0" -a $screens != "0" ] ; then
rep="${NO_COL}${YELLOW}${screens}s${NO_COL}"
elif [ $running != "0" -a $stopped == "0" -a $screens != "0" ] ; then
rep="${NO_COL}${YELLOW}${screens}s${NO_COL}/${YELLOW}${running}r${NO_COL}"
elif [ $running == "0" -a $stopped != "0" -a $screens != "0" ] ; then
rep="${NO_COL}${YELLOW}${screens}s${NO_COL}/${LIGHT_YELLOW}${stopped}t${NO_COL}"
fi fi
echo -ne "$rep" echo -ne "$rep"
} }