Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ set -g @sessionx-additional-options "--color pointer:9,spinner:92,marker:46"
# Upgrade, or use this setting for support
set -g @sessionx-legacy-fzf-support 'on'

# Define a command to be executed automatically when a new session is created.
# Use {session} as a placeholder for the new session's name and {path} for its working directory.
# Example: set -g @sessionx-startup-command 'tmux new-window -t {session}:1 -n editor "nvim {path}" && tmux new-window -t {session}:2 -n shell'
set -g @sessionx-startup-command '<command>'

# With Tmuxinator turned 'on' (off by default), the plugin will take a given name
# and look for a tmuxinator project with that name.
# If found, it'll launch the template using tmuxinator
Expand Down
18 changes: 18 additions & 0 deletions scripts/sessionx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ additional_input() {
fi
}

run_startup_command() {
local session_name="$1"
local session_path="$2"

local startup_command
startup_command=$(tmux show-option -gv @sessionx-startup-command 2>/dev/null)

if [[ -n "$startup_command" ]]; then
startup_command="${startup_command//\{session\}/$session_name}"
startup_command="${startup_command//\{path\}/$session_path}"
tmux send-keys -t "$session_name" "$startup_command" Enter
fi
}

handle_output() {
if [ -d "$*" ]; then
# No special handling because there isn't a window number or window name present
Expand Down Expand Up @@ -94,17 +108,21 @@ handle_output() {
tmuxinator start "$target"
elif test -n "$mark"; then
tmux new-session -ds "$mark" -c "$target"
run_startup_command "$mark" "$target"
target="$mark"
elif test -d "$target"; then
d_target="$(basename "$target" | tr -d '.')"
tmux new-session -ds $d_target -c "$target"
run_startup_command "$d_target" "$target"
target=$d_target
else
if [[ "$Z_MODE" == "on" ]]; then
z_target=$(zoxide query "$target")
tmux new-session -ds "$target" -c "$z_target" -n "$z_target"
run_startup_command "$target" "$z_target"
else
tmux new-session -ds "$target"
run_startup_command "$target" "$(pwd)"
fi
fi
fi
Expand Down