Skip to content

Commit

Permalink
Remove dependence of theme config JOBS for SESSIONS
Browse files Browse the repository at this point in the history
While the default theme will only show detached sessions if jobs are
enabled, not all themes might choose to do this. The check for screen
and tmux is done once at startup, so there isn't a good reason to not do
it.

Also remove the _LP_ENABLE_DETACHED_SESSIONS var, since it breaks even
at best in terms of speed, while adding another variable to the env.

Add a arithmetic context to the setting of those vars. It didn't used to
be needed, since they were set to integer types before, but now that
this is in a function we can't make that setting without also setting
them local, which will break them.
It was actually working though, because it was resolving to (( !0 )),
which actually resolves to true. Shell is awesome.
Anyway, this should cut down on runtime.
  • Loading branch information
Rycieos committed Nov 25, 2020
1 parent 73f2057 commit f9038e0
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions liquidprompt
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,8 @@ lp_activate() {

unset -f _lp_require_tool

if (( LP_ENABLE_JOBS )); then
command -v screen >/dev/null ; _LP_ENABLE_SCREEN=!$?
command -v tmux >/dev/null ; _LP_ENABLE_TMUX=!$?
(( _LP_ENABLE_DETACHED_SESSIONS = ( _LP_ENABLE_SCREEN || _LP_ENABLE_TMUX ) ))
fi
command -v screen >/dev/null ; _LP_ENABLE_SCREEN=$(( ! $? ))
command -v tmux >/dev/null ; _LP_ENABLE_TMUX=$(( ! $? ))

# Use standard path symbols inside Midnight Commander
[[ -n "${MC_SID-}" ]] && LP_ENABLE_SHORTEN_PATH=0
Expand Down Expand Up @@ -812,10 +809,8 @@ _lp_set_dirtrim() {
# return: lp_detached_sessions; the number of detached sessions
_lp_detached_sessions() {
local -i count=0
if (( _LP_ENABLE_DETACHED_SESSIONS )); then
(( _LP_ENABLE_SCREEN )) && count=$(screen -ls 2> /dev/null | \grep -c '[Dd]etach[^)]*)$')
(( _LP_ENABLE_TMUX )) && count+=$(tmux list-sessions 2> /dev/null | \grep -cv 'attached')
fi
(( _LP_ENABLE_SCREEN )) && count=$(screen -ls 2> /dev/null | \grep -c '[Dd]etach[^)]*)$')
(( _LP_ENABLE_TMUX )) && count+=$(tmux list-sessions 2> /dev/null | \grep -cv 'attached')
lp_detached_sessions=$count
(( lp_detached_sessions ))
}
Expand Down

0 comments on commit f9038e0

Please sign in to comment.