How to change the starting directory of a tmux session?

后端 未结 3 1002
失恋的感觉
失恋的感觉 2021-02-05 01:03

The directory where you start a tmux session in will be the directory that all new windows will start at.

My question is, how can you change this starting directory wit

3条回答
  •  攒了一身酷
    2021-02-05 01:50

    Here's how you can change the tmux session's working directory without detaching the session, and without needing use to the keystrokes:

    (Option 1) Enter the directory at tmux command prompt:

    tmux command-prompt "attach -c %1"

    ...will open a command prompt, then you type the working directory you want ~/my/dir and press ENTER

    (Option 2) Provide the directory on the in-pane command line:

    # Execute this in one of the shell panes of within your tmux session:
    tmux command-prompt -I $PWD -P "New session dir:" "attach -c %1"
    

    With this approach, the prompt for new-directory is pre-populated with the current dir of the pane which launched the command. Of course you can substitute anything else for $PWD if you please.

    Want a shell function?

    I have added this to my shell initialization:

    # Change the current directory for a tmux session, which determines
    # the starting dir for new windows/panes:
    function tmux-cwd {
        tmux command-prompt -I $PWD -P "New session dir:" "attach -c %1"
     }
    

    With all of these options, any future new windows will start in the given dir.

    Note: attach, attach-session, and a are all aliases for each other. The tmux command-prompt has many other powers, it's worth reading the man page

提交回复
热议问题