dotfiles/lib/shared/scripts/t.nix
Oliver Davies 1bc80ccef3 Update t script
Stop automatically running `.tmux` files as I don't always want
everything to run when opening a project. This also simplifies the code
within the script.

This also refactors the logic for creating and switching sessions as it
didn't work 100% of the time. This is nearer to Jess Archer's version of
the script with less error output and changes needed for shellcheck.
2024-10-28 16:29:22 +00:00

39 lines
925 B
Nix

{ pkgs }:
{
name = "t";
runtimeInputs = with pkgs; [
openssl
tmux
];
text = ''
# Based on similar scripts by ThePrimeagen and Jess Archer.
if [[ $# -eq 1 ]]; then
selected_path=$1
else
# Get the session name from fuzzy-finding list of directories and generating a
# tmux-safe version.
items=$(find "$REPOS" ~/Documents \
-maxdepth 1 -mindepth 1 -type d \
! -name "_archive" \
! -name "*-old" \
! -name "*.old"
)
selected_path=$(echo "''${items}" | sort | fzf --reverse)
fi
session_name=$(basename "$selected_path" | sed 's/\./_/g')
if tmux switch-client -t="$session_name" 2>/dev/null; then
exit 0
fi
( (tmux new-session -c "$selected_path" -d -s "$session_name" && tmux switch-client -t "$session_name") 2>/dev/null ) ||
tmux new-session -c "$selected_path" -A -s "$session_name"
'';
}