theniceboy/tmux/scripts/open_shell_here.sh
2026-04-09 10:07:43 -07:00

26 lines
554 B
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
mode="${1:-}"
target="${2:-}"
target_path="${3:-}"
shift 3 || true
if [[ -z "$target_path" || ! -d "$target_path" ]]; then
target_path="$HOME"
fi
printf -v start_cmd 'cd %q && exec ${SHELL:-/bin/zsh} -l' "$target_path"
case "$mode" in
split)
exec tmux split-window "$@" -t "$target" -c "$target_path" "$start_cmd"
;;
new-window)
exec tmux new-window "$@" -t "$target" -c "$target_path" "$start_cmd"
;;
*)
printf 'open_shell_here: unknown mode %s\n' "$mode" >&2
exit 1
;;
esac