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

Should set session start-diretory to current working directory. #4

Open
waynr opened this issue Oct 18, 2014 · 3 comments · May be fixed by #33
Open

Should set session start-diretory to current working directory. #4

waynr opened this issue Oct 18, 2014 · 3 comments · May be fixed by #33

Comments

@waynr
Copy link

waynr commented Oct 18, 2014

If you are concerned about making this the default behavior, then maybe make it opt-in using a variable set in ~/.tmux.conf

@bruno-
Copy link
Member

bruno- commented Oct 18, 2014

Hi, I'm curious, why do you need this feature?
I usually start new sessions in directories that are different than the current working dir.

@waynr
Copy link
Author

waynr commented Oct 18, 2014

@bruno- by default the behavior of <prefix>, C is to use the same start-directory as whatever the current session's start-directory is--regardless of what directory your pane happens to be in at the time <prefix>, C is invoked.

Most of the time when when I create new sessions I am doing so because I want to be working in an entirely different context--I want new panes & windows to start off in a specific directory.

As a shortcut, the create named session feature doesn't have much practical value for me if the new named session always has the same start-directory as the old.`

In the past I have simply created a new terminal window and started my tmux sessions after navigating to the specific project directory that I wanted to be the start directory.

@fab4100
Copy link

fab4100 commented Mar 6, 2016

Hi.

I was bothered by this issue as well and solved it by making the following changes to new_session_promt.sh:

#!/usr/bin/env bash

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

main() {
tmux command -p "new session name:" "run '$CURRENT_DIR/new_session.sh "%1" #{pane_current_path}'"
}
main

and then to use the current pane directory I have added this in new_session.sh:

#!/usr/bin/env bash

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

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

source "$CURRENT_DIR/helpers.sh"

session_name_not_provided() {
[ -z "$SESSION_NAME" ]
}

create_new_tmux_session() {
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}" "2000"
else
TMUX="" tmux -S "$(tmux_socket)" new-session -d -s "$SESSION_NAME" -c "$SESSION_PATH"
switch_to_session "$SESSION_NAME"
fi
}

main() {
create_new_tmux_session
}
main

This will always use the directory of the current pane when a new session is created. Please let me know if you can include this in the current plugin.

Best
Fab

NB: It is just a quick hack, the checks for provided session names etc. should be modified in a release version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants