Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user set variable for directory that new sessions are started in #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion scripts/new_session.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# global variable
SESSION_NAME="$1"
SESSION_START_DIR="$2"

source "$CURRENT_DIR/helpers.sh"

Expand All @@ -18,7 +19,7 @@ create_new_tmux_session() {
switch_to_session "$SESSION_NAME"
display_message "Switched to existing session ${SESSION_NAME}" "2000"
else
TMUX="" tmux -S "$(tmux_socket)" new-session -d -s "$SESSION_NAME"
TMUX="" tmux -S "$(tmux_socket)" new-session -d -s "$SESSION_NAME" -c "$SESSION_START_DIR"
switch_to_session "$SESSION_NAME"
fi
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/new_session_prompt.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env bash

CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SESSION_START_DIR="$1"

main() {
tmux command -p "new session name:" "run '$CURRENT_DIR/new_session.sh \"%1\"'"
tmux command -p "new session name:" "run '$CURRENT_DIR/new_session.sh \"%1\" \"$SESSION_START_DIR\"'"
}
main
4 changes: 3 additions & 1 deletion sessionist.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ tmux_option_alternate="@sessionist-alternate"

default_key_bindings_new="C"
tmux_option_new="@sessionist-new"
starting_directory="@sessionist-start-directory"

default_key_bindings_promote_pane="@"
tmux_option_promote_pane="@sessionist-promote-pane"
Expand Down Expand Up @@ -44,9 +45,10 @@ set_alternate_session_binding() {
# it will switch to existing session.
set_new_session_binding() {
local key_bindings=$(get_tmux_option "$tmux_option_new" "$default_key_bindings_new")
local start_directory=$(get_tmux_option "$starting_directory" "$HOME")
local key
for key in $key_bindings; do
tmux bind "$key" run "$CURRENT_DIR/scripts/new_session_prompt.sh"
tmux bind "$key" run "$CURRENT_DIR/scripts/new_session_prompt.sh '$start_directory'"
done
}

Expand Down