auto up 02:09:52 up 2:18, 2 users, load average: 0.53, 0.69, 0.98

This commit is contained in:
2025-11-02 02:09:53 +01:00
parent 45397093c8
commit abffff1454

37
shell/open_sess.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -euo pipefail
PROJECT_DIR=$(find ~/projects -mindepth 1 -maxdepth 1 -type d | fzf --prompt='Select project: ')
[ -z "$PROJECT_DIR" ] && exit 0
SESSION_NAME=$(basename "$PROJECT_DIR")
# If session exists, switch or attach depending on context
if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
if [ -n "${TMUX:-}" ]; then
tmux switch-client -t "$SESSION_NAME"
else
tmux attach -t "$SESSION_NAME"
fi
exit 0
fi
# Choose startup command
if [ -f "$PROJECT_DIR/shell.nix" ]; then
START_CMD="cd \"$PROJECT_DIR\" && nix-shell"
else
START_CMD="cd \"$PROJECT_DIR\""
fi
# Create a new detached session
tmux new-session -d -s "$SESSION_NAME" "bash -c '$START_CMD; exec bash'"
# Create a second window running Neovim
tmux new-window -t "$SESSION_NAME" -n nvim "bash -c 'cd \"$PROJECT_DIR\" && nvim'"
# Attach or switch, depending on whether we're inside tmux
if [ -n "${TMUX:-}" ]; then
tmux switch-client -t "$SESSION_NAME"
else
tmux attach -t "$SESSION_NAME"
fi