This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/bin/tmux-session-list
2020-04-20 10:38:19 -05:00

31 lines
897 B
Bash
Executable file

#!/usr/bin/env bash
ANY_SESSION_PREFIX="#[bg=colour18]#[fg=colour7]"
ANY_SESSION_SUFFIX="#[bg=default]#[fg=default] "
CUR_SESSION_PREFIX="#[bg=colour4]#[fg=colour0]"
CUR_SESSION_SUFFIX="${ANY_SESSION_SUFFIX}"
# TODO: implement urgent session highlighting
# URG_SESSION_SUFFIX="${ANY_SESSION_SUFFIX}"
# URG_SESSION_PREFIX="#[bg=colour1]#[fg=colour0]"
CUR_TMUX_SESSION="$1"
if [ -z "$1" ]; then
CUR_TMUX_SESSION="$(tmux display-message -p '#S')"
fi
export CUR_TMUX_SESSION
TMUX_SESSION_LIST="$(tmux list-sessions | awk \
-v curSesh="${CUR_TMUX_SESSION}" \
-v aspre="${ANY_SESSION_PREFIX}" \
-v assuf="${ANY_SESSION_SUFFIX}" \
-v cspre="${CUR_SESSION_PREFIX}" \
-v cssuf="${CUR_SESSION_SUFFIX}" \
'{s=substr($1,0,length($1)-1);
if(s==curSesh){
s=cspre" "s" "cssuf
}else{
s=aspre" "s" "assuf
}printf s}')"
# shellcheck disable=SC2001
echo "${TMUX_SESSION_LIST//\s*$/}" | sed -e 's/\s*$//'