diff --git a/README.md b/README.md index 152dca6..9c81d51 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,14 @@ Lightweight tmux utilities for switching and creating sessions. The same as built-in `prefix + shift + l` that everyone seems to override with some other binding. +### Configuration + +By default tmux-sessionist will use the same start-directory as the current +session directory. To configure it to use the current pane directory, add the +following to your tmux configuration: + + set -g @sessionist-use-pane-directory + ### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended) Add plugin to the list of TPM plugins in `.tmux.conf`: diff --git a/scripts/tmux_new_session.sh b/scripts/tmux_new_session.sh index 455bfc4..0425ffa 100755 --- a/scripts/tmux_new_session.sh +++ b/scripts/tmux_new_session.sh @@ -4,9 +4,13 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # global variable SESSION_NAME="$1" +SESSION_PATH="$2" source "$CURRENT_DIR/helpers.sh" +default_sessionist_use_pane_directory="" +tmux_option_sessionist_use_pane_directory="@sessionist-use-pane-directory" + session_name_not_provided() { [ -z "$SESSION_NAME" ] } @@ -21,13 +25,20 @@ switch_to_session() { } create_new_tmux_session() { + local use_pane_directory=$(get_tmux_option "$tmux_option_sessionist_use_pane_directory" "$default_sessionist_use_pane_directory") + local tmux_extra_args="" + + if [ "$use_pane_directory" = "true" ] ;then + tmux_extra_args=" -c $SESSION_PATH " + fi + if session_name_not_provided; then exit 0 elif session_exists; then switch_to_session "$SESSION_NAME" display_message "Switched to existing session ${SESSION_NAME}" "1000" else - TMUX="" tmux new -d -s "$SESSION_NAME" + TMUX="" tmux new $tmux_extra_args -d -s "$SESSION_NAME" switch_to_session "$SESSION_NAME" fi } diff --git a/scripts/tmux_new_session_prompt.sh b/scripts/tmux_new_session_prompt.sh index 5a48335..3ca6d90 100755 --- a/scripts/tmux_new_session_prompt.sh +++ b/scripts/tmux_new_session_prompt.sh @@ -3,6 +3,6 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" main() { - tmux command-prompt -p "new session name:" "run-shell '$CURRENT_DIR/tmux_new_session.sh %1'" + tmux command-prompt -p "new session name:" "run-shell '$CURRENT_DIR/tmux_new_session.sh %1 #{pane_current_path}'" } main