mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 14:49:14 +00:00
packages/tmux-sessionizer: tmux-sessionizer
This commit is contained in:
parent
db5a9ce92d
commit
c16d84e75e
1 changed files with 43 additions and 0 deletions
|
|
@ -2,6 +2,8 @@
|
||||||
writeShellApplication,
|
writeShellApplication,
|
||||||
tmux,
|
tmux,
|
||||||
procps,
|
procps,
|
||||||
|
fzf,
|
||||||
|
gnused,
|
||||||
lib,
|
lib,
|
||||||
symlinkJoin,
|
symlinkJoin,
|
||||||
}: let
|
}: let
|
||||||
|
|
@ -72,6 +74,46 @@
|
||||||
${lib.getExe tmux-attach-or-switch} "$session_name"
|
${lib.getExe tmux-attach-or-switch} "$session_name"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
tmux-sessionizer = writeShellApplication {
|
||||||
|
name = "tmux-sessionizer";
|
||||||
|
runtimeInputs = [fzf gnused];
|
||||||
|
text = ''
|
||||||
|
selected=$(
|
||||||
|
{
|
||||||
|
fd . "$REPO_PATH" --exact-depth 2 --hidden --type d
|
||||||
|
fd . "$WORKTREE_PATH" --exact-depth 4 --hidden --type d
|
||||||
|
fd . "$PLAYGROUND_PATH" --exact-depth 1 --hidden --type d
|
||||||
|
echo "dotfiles"
|
||||||
|
echo "password-store"
|
||||||
|
} 2> /dev/null | sed -e "s|^$HOME|~|" | fzf)
|
||||||
|
selected=''${selected//\~/$HOME}
|
||||||
|
|
||||||
|
if [ -z "$selected" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# derive session name based on selected path
|
||||||
|
# dots are meaningful in tmux, remove them
|
||||||
|
session_name=''${selected//./_}
|
||||||
|
|
||||||
|
# fixup special cases, override derived session_name if necessary
|
||||||
|
# this should be id for non-special cases
|
||||||
|
case "$selected" in
|
||||||
|
dotfiles)
|
||||||
|
selected=~/.dotfiles
|
||||||
|
;;
|
||||||
|
password-store)
|
||||||
|
selected="$PASSWORD_STORE_DIR"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# effects
|
||||||
|
${lib.getExe tmux-register-session} || :
|
||||||
|
${lib.getExe tmux-maybe-create} "$session_name" "$selected"
|
||||||
|
${lib.getExe tmux-attach-or-switch} "$session_name"
|
||||||
|
'';
|
||||||
|
};
|
||||||
in
|
in
|
||||||
symlinkJoin {
|
symlinkJoin {
|
||||||
name = "tmux-sessionizer";
|
name = "tmux-sessionizer";
|
||||||
|
|
@ -80,5 +122,6 @@ in
|
||||||
tmux-maybe-create
|
tmux-maybe-create
|
||||||
tmux-attach-or-switch
|
tmux-attach-or-switch
|
||||||
tmux-last
|
tmux-last
|
||||||
|
tmux-sessionizer
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue