Mercurial > dotfiles
comparison .zshrc @ 526:852565046ed0 default tip
zsh: fidget with screen/tmux message
This should speed things up very slightly by avoiding some `grep` action
in the common case of no detached screens/tmuxes.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Mon, 14 Nov 2022 11:02:35 -0500 |
parents | b78aa03c0c00 |
children |
comparison
equal
deleted
inserted
replaced
525:b0fa9e7cadac | 526:852565046ed0 |
---|---|
8 | 8 |
9 if [ ! "$SHOWED_SCREEN_MESSAGE" = "true" ]; then | 9 if [ ! "$SHOWED_SCREEN_MESSAGE" = "true" ]; then |
10 # Use /bin/which explicitly because we have a shell function | 10 # Use /bin/which explicitly because we have a shell function |
11 # that confuses the zsh built-in which. | 11 # that confuses the zsh built-in which. |
12 if sh -c 'which screen' 2> /dev/null > /dev/null; then | 12 if sh -c 'which screen' 2> /dev/null > /dev/null; then |
13 detached_screens=`screen -list | grep Detached | sed -e 's/ (Detached)//'` | 13 SCREENS_OUTPUT="$(screen -list)" |
14 if [ ! -z "$detached_screens" ]; then | 14 if [[ "${SCREENS_OUTPUT}" =~ Detached ]] ; then |
15 detached_screens=`echo "${SCREENS_OUTPUT}" | grep Detached | sed -e 's/ (Detached)//'` | |
15 echo "+---------------------------------------+" | 16 echo "+---------------------------------------+" |
16 echo "| Detached screens are available: |" | 17 echo "| Detached screens are available: |" |
17 echo "$detached_screens" | 18 echo "$detached_screens" |
18 echo "+---------------------------------------+" | 19 echo "+---------------------------------------+" |
19 fi | 20 fi |
21 unset SCREENS_OUTPUT | |
22 unset detached_screens | |
20 fi | 23 fi |
21 export SHOWED_SCREEN_MESSAGE="true" | 24 export SHOWED_SCREEN_MESSAGE="true" |
22 fi | 25 fi |
23 | 26 |
24 if [ ! "$SHOWED_TMUX_MESSAGE" = "true" ]; then | 27 if [ ! "$SHOWED_TMUX_MESSAGE" = "true" ]; then |
25 if which tmux 2> /dev/null > /dev/null; then | 28 if which tmux 2> /dev/null > /dev/null; then |
26 detached_screens=$(tmux ls 2> /dev/null | grep -v attached) | 29 detached_screens="$(tmux ls 2> /dev/null)" |
30 if [ ! -z "$detached_screens" ]; then | |
31 detached_screens="$(echo "$detached_screens" | grep -v attached)" | |
32 fi | |
27 if [ ! -z "$detached_screens" ]; then | 33 if [ ! -z "$detached_screens" ]; then |
28 echo "+-----------------------------------------------------------+" | 34 echo "+-----------------------------------------------------------+" |
29 echo "| Detached tmux sessions are available: |" | 35 echo "| Detached tmux sessions are available: |" |
30 echo "$detached_screens" | 36 echo "$detached_screens" |
31 echo "+-----------------------------------------------------------+" | 37 echo "+-----------------------------------------------------------+" |
32 fi | 38 fi |
39 unset detached_screens | |
33 fi | 40 fi |
34 export SHOWED_TMUX_MESSAGE="true" | 41 export SHOWED_TMUX_MESSAGE="true" |
35 fi | 42 fi |
36 | 43 |
37 # If available, source private extensions stored in a different repo | 44 # If available, source private extensions stored in a different repo |