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

Adds sessionist-use-pane-directory option. #5

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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
13 changes: 12 additions & 1 deletion scripts/tmux_new_session.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/tmux_new_session_prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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