dotfiles/nix/lib/shared/scripts/t.nix
Oliver Davies 69a397e624 Move Nix files into a nix directory
Move everything from `config` to the root level.
2024-11-21 08:56:12 +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"
'';
}