Rename t to tmux-sessionizer

This matches ThePrimeagen's script that mine is based on and that I'll
probably switch to in the future.

I've added to the Nix store as custom-tmux-sessionizer so it doesn't
conflict with the tmux-sessionzer packages that's already in the store.
This commit is contained in:
Oliver Davies 2024-12-06 12:38:40 +00:00
parent 5a9353ad17
commit 930473a896
9 changed files with 51 additions and 8 deletions
nix/lib/shared

View file

@ -17,7 +17,6 @@ let
import ./scripts/export-video-list.nix { inherit pkgs username; }
);
run = writeShellApplication (import ./scripts/run.nix { inherit pkgs; });
t = writeShellApplication (import ./scripts/t.nix { inherit pkgs; });
timer = writeShellApplication (import ./scripts/timer.nix);
in
with pkgs;
@ -69,7 +68,6 @@ with pkgs;
# Scripts.
deliver
run
t
]
++ pkgs.lib.optionals desktop [
# Scripts.

View file

@ -1,59 +0,0 @@
{ pkgs }:
{
name = "t";
runtimeInputs = with pkgs; [ tmux ];
text = ''
# https://github.com/ThePrimeagen/tmux-sessionizer.
switch_to() {
if [[ -z $TMUX ]]; then
tmux attach-session -t "$1"
else
tmux switch-client -t "$1"
fi
}
has_session() {
tmux list-sessions | grep -q "^$1:"
}
hydrate() {
if [ -f "$2/.tmux" ]; then
tmux send-keys -t "$1" "source $2/.tmux" Enter
elif [ -f "$2/.tmux-sessionizer" ]; then
tmux send-keys -t "$1" "source $2/.tmux-sessionizer" Enter
elif [ -f "$HOME/.tmux-sessionizer" ]; then
tmux send-keys -t "$1" "source $HOME/.tmux-sessionizer" Enter
fi
}
if [[ $# -eq 1 ]]; then
selected=$1
else
selected=$(find ~/ ~/Code ~/Code/personal ~/Code/os ~/Documents -mindepth 1 -maxdepth 1 -type d | fzf)
fi
if [[ -z "$selected" ]]; then
exit 0
fi
selected_name="$(basename "$selected" | tr . _)"
tmux_running="$(pgrep tmux)"
if [[ -z $TMUX ]] && [[ -z "$tmux_running" ]]; then
tmux new-session -s "$selected_name" -c "$selected"
hydrate "$selected_name" "$selected"
exit 0
fi
if ! has_session "$selected_name"; then
tmux new-session -ds "$selected_name" -c "$selected"
hydrate "$selected_name" "$selected"
fi
switch_to "$selected_name"
'';
}