fetch

A MSYS2-compatible sys-info prompt
Log | Files | Refs | README | LICENSE

commit 9281b99ec4767c197e7ed92fd65e2c661dc6172d
parent 85d76eda80f09b717b57fa376b64e7655790d1e9
Author: Byron Torres <b@torresjrjr.com>
Date:   Fri, 23 Apr 2021 12:49:41 +0100

Sort tmux sessions by age

tmux has particular syntax for formatting internal state.
See tmux(1), /^FORMATS/.

This commit leverages the `tmux ls` subcommand, the tmux internal
`session_created` datetime variable, and the sort command to provide a
_tmux() statusline of sorted tmux sessions from oldest to youngest.

_sshd() and _tmux() are both improved with the usage of awk's `printf`
command instead of the `ORS` variable.

Diffstat:
Mfetch | 14++++----------
1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/fetch b/fetch @@ -59,19 +59,13 @@ _shell() { printf "$1" "$(readlink /proc/$PPID/exe)" } _sshd() { - sshd_pids=$( - ps ax | awk 'BEGIN {ORS=" "}; !/awk/ && /sshd/ {print $1}' - ) - printf "$1" "${sshd_pids:---}" + pids=$(ps ax | awk '!/awk/ && /sshd/ {printf $1 " "}') + printf "$1" "${pids:---}" } _tmux() { ps ax | grep -v 'grep' | grep -q 'tmux' && tmux_sessions=$( - tmux ls | sed " - s/ windows (created [^)]*)// - s/\([^(]*\)(attached)/$ul\1$c0/ - s/ //g - s/$/ / - " | tr -d '\n' + tmux ls -F "#{session_created} #{?session_attached,$ul,}#S:#{session_windows}$c0" \ + | sort | awk '{printf $2 " "}' | xargs -0 printf ) printf "$1" "${tmux_sessions:---}" }