Is there a command like switch-session [-np] that switches based on the order appearing in choose-session? #4811
Replies: 2 comments 1 reply
-
|
There is nothing builtin... I'd like it if You could make If you want S=$(tmux display -p '#{session_id}')
N=$(tmux ls -F '#{session_id}'|sort -nk2 -t'$'|sed -n "/^$S$/{n;p}")
if [ x$N = x ]; then
N=$(tmux ls -F '#{session_id}'|sort -nk2 -t'$'|head -1)
fi
tmux switchc -t$NAnd for previous: S=$(tmux display -p '#{session_id}')
N=$(tmux ls -F '#{session_id}'|sort -nk2 -t'$'|sed -n "1!{/^$S$/{x;p}}; h")
if [ x$N = x ]; then
N=$(tmux ls -F '#{session_id}'|sort -nk2 -t'$'|tail -1)
fi
tmux switchc -t$NThere may be a tidier way to do this using the |
Beta Was this translation helpful? Give feedback.
-
|
I see, so the ids are in the order I want. Thanks for the script, this is what I ended up using: #!/usr/bin/env bash
SESSIONS=$(tmux ls -F "#{session_id}" | sort -nk2 -t"$")
CURRENT_SESSION=$(tmux display -p "#{session_id}")
if [[ $1 == p ]]; then
TARGET=$(echo "$SESSIONS" | sed -n "/^$CURRENT_SESSION$/{x;p}; h")
[[ -z $TARGET ]] && TARGET=$(echo "$SESSIONS" | tail -1)
else
TARGET=$(echo "$SESSIONS" | sed -n "/^$CURRENT_SESSION$/{n;p}")
[[ -z $TARGET ]] && TARGET=$(echo "$SESSIONS" | head -1)
fi
tmux switchc -t "$TARGET" |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I used these bindings assuming that they followed the same order order from choose-session and kept getting confused at where they would take me. I looked at the man page and found out about how they actually work but I cant find anything on choose-session or how to get the numbers it uses. I just want to go up and down this menu without actually opening it. Is there some way to output the sessions sorted by age?
Beta Was this translation helpful? Give feedback.
All reactions