tmux will create new window under current session(with bind-key c). I want to select session when create window.

This script works fine when run it directly, but fails when called from tmux using bind key bind-key C run-shell '~/tmux/tmux.window.sh'. The output is 'tmux/tmux.window.sh' returned 1


export PATH=$PATH:/usr/local/bin

# present menu for user to choose which workspace to open
PS3="option: "
options=($(tmux list-sessions -F "#S") "in new session" )
select opt in "${options[@]}"
    case $opt in
        "in new session")
            read -p "new session: " SESSION_NAME
            TMUX=  tmux new -s "$SESSION_NAME"
            tmux new-window -t ${opt}:
            tmux attach-session -t ${opt}

1 Answer 1


You cannot use read from run-shell because it has no stdin. You could run your script in a pane (use split-window). Or if you are using tmux 3.1, you could generate a menu with display-menu or if using 3.2-rc or master use a popup with display-popup.

If you want to change session, window and pane together you can use the switch-client command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .