mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-07 07:09:15 +00:00
packages/tmux-sessionizer: tmux-last
This commit is contained in:
parent
b69c80497f
commit
db5a9ce92d
1 changed files with 30 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
writeShellApplication,
|
writeShellApplication,
|
||||||
tmux,
|
tmux,
|
||||||
procps,
|
procps,
|
||||||
|
lib,
|
||||||
symlinkJoin,
|
symlinkJoin,
|
||||||
}: let
|
}: let
|
||||||
tmux-register-session = writeShellApplication {
|
tmux-register-session = writeShellApplication {
|
||||||
|
|
@ -9,6 +10,12 @@
|
||||||
runtimeInputs = [tmux];
|
runtimeInputs = [tmux];
|
||||||
text = ''
|
text = ''
|
||||||
last=/tmp/TMUX_LAST
|
last=/tmp/TMUX_LAST
|
||||||
|
|
||||||
|
# bail if tmux not running
|
||||||
|
if ! pgrep tmux >/dev/null 2>&1; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
this="$(tmux display-message -p '#S')"
|
this="$(tmux display-message -p '#S')"
|
||||||
if [ ! -f "$last" ] || [ "$(cat "$last")" != "$this" ]; then
|
if [ ! -f "$last" ] || [ "$(cat "$last")" != "$this" ]; then
|
||||||
echo "$this" >"$last"
|
echo "$this" >"$last"
|
||||||
|
|
@ -43,6 +50,28 @@
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tmux-last = writeShellApplication {
|
||||||
|
name = "tmux-last";
|
||||||
|
text = ''
|
||||||
|
tmux_last=/tmp/TMUX_LAST
|
||||||
|
if [ ! -f $tmux_last ]; then
|
||||||
|
echo "Last session is not yet set"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
session_name="$(cat $tmux_last)"
|
||||||
|
session_path="$session_name"
|
||||||
|
if [ ! -d "$session_path" ]; then
|
||||||
|
session_path="/tmp"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# bail if not in tmux, nothing to register
|
||||||
|
${lib.getExe tmux-register-session} || :
|
||||||
|
${lib.getExe tmux-maybe-create} "$session_name" "$session_path"
|
||||||
|
${lib.getExe tmux-attach-or-switch} "$session_name"
|
||||||
|
'';
|
||||||
|
};
|
||||||
in
|
in
|
||||||
symlinkJoin {
|
symlinkJoin {
|
||||||
name = "tmux-sessionizer";
|
name = "tmux-sessionizer";
|
||||||
|
|
@ -50,5 +79,6 @@ in
|
||||||
tmux-register-session
|
tmux-register-session
|
||||||
tmux-maybe-create
|
tmux-maybe-create
|
||||||
tmux-attach-or-switch
|
tmux-attach-or-switch
|
||||||
|
tmux-last
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue