Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Byobu open new screens in home directory

Tags:

ubuntu

tmux

byobu

I don't know if this is something that's changed in a recent version of byobu, but now when I create a new screen, the new screen is in the same directory as my current window. At first this wasn't too annoying, a simple "cd ~" would get me where I wanted. But I've been noticing strange things. During a gem install, if I create a new window, I end up inside the directory that the gem is being installed to ( when using rbenv ).

I just want this to stop. How do I set up byobu/tmux so that it opens all new windows in my home directory?

I've looked through a few files, but I can't seem to see any commands ( such as errant 'chdir' ) that would be causing this.

like image 715
Sean Hagen Avatar asked Feb 15 '23 08:02

Sean Hagen


1 Answers

In Ubuntu, I can get the desired behavior by adding the following line to ${HOME}/.byobu/.tmuxrc :

set-option -g default-path $HOME

This option is document in tmux's manual page:

set-option [-agoqsuw] [-t target-session | target-window] option value
              (alias: set)
        Set a window option with -w (equivalent to the set-window-option
        command), a server option with -s, otherwise a session option.

        If -g is specified, the global session or window option is set.
        With -a, and if the option expects a string, value is appended
        to the existing setting.  The -u flag unsets an option, so a session
        inherits the option from the global options.  It is not possible to
        unset a global option.

        The -o flag prevents setting an option that is already set.

        The -q flag suppresses the informational message (as if the quiet
        server option was set).

        Available window options are listed under set-window-option.

        value depends on the option and may be a number, a string, or a flag
        (on, off, or omitted to toggle).

        Available server options are:

        <snip>

        default-path path

        Set the default working directory for new panes.  If empty (the
        default), the working directory is determined from the process running
        in the active pane, from the command line environment or from the
        working directory where the session was created.  Otherwise the same
        options are available as for the -c flag to new-window.

I initially tried with set-option -g default-path ~, but it appears that tmux doesn't understand that alias.

Update: the above doesn't work with byobu 5.92 (maybe other versions) and tmux 1.9, as tmux has removed the default-path option. It seems the byobu dev was using that to get the behavior where new windows open in the CWD, whereas I and the questioner wanted it to open in the HOME dir by default. In the new default bindings in /usr/share/byobu/keybindings/f-keys.tmux I found this:

bind-key -n F2 new-window -c "#{pane_current_path}" \; rename-window "-"
bind-key -n C-F2 display-panes \; split-window -h -c "#{pane_current_path}"
bind-key -n S-F2 display-panes \; split-window -v -c "#{pane_current_path}"

To get the desired behavior of always making byobu open new screens in your home directory, add the following to ~/.byobu/keybindings.tmux:

bind-key -n F2 new-window -c "$HOME" \; rename-window "-"
bind-key -n C-F2 display-panes \; split-window -h -c "$HOME"
bind-key -n S-F2 display-panes \; split-window -v -c "$HOME"
like image 179
Mr. Fix It Avatar answered Feb 16 '23 21:02

Mr. Fix It