solorice/local/bin/tmux-sessionizer
Kristofers Solo 1d7d0b7c22
Update 2025-05-31
Update 2025-05-06

Update 2025-05-09

Update 2025-05-11

Update 2025-05-13

Update 2025-05-18

Update 2025-05-19

Update 2025-05-24

Update 2025-05-27

Update 2025-05-29

Update 2025-05-31
2025-06-02 13:16:33 +03:00

33 lines
868 B
Bash
Executable File

#!/bin/bash
if [[ $# -eq 1 ]]; then
selected="$1"
else
selected=$(project-finder ~/repos/ ~/Nextcloud/ ~/Obsidian/ | sk --height 16)
fi
if [[ -z "$selected" ]]; then
exit 0
fi
selected_name=$(basename "$selected" | tr . _)
# Check if the session exists
if ! tmux has-session -t="$selected_name" 2>/dev/null; then
# Create a new session, detached, with window 0 in the selected directory
tmux new-session -d -s "$selected_name" -c "$selected"
# Create a second window (index 1) in the same directory
tmux new-window -t "$selected_name:" -c "$selected"
fi
# Always select window 0
tmux select-window -t "$selected_name:1"
if [[ -z "$TMUX" ]]; then
# Not inside tmux, attach to the session
tmux attach-session -t "$selected_name"
else
# Inside tmux, switch client to the session
tmux switch-client -t "$selected_name"
fi