0

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

#!/bin/sh

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[@]}"
do
    case $opt in
        "in new session")
            read -p "new session: " SESSION_NAME
            TMUX=  tmux new -s "$SESSION_NAME"
            break
            ;;
        *)
            tmux new-window -t ${opt}:
            tmux attach-session -t ${opt}
            break
            ;;
    esac
done

1 Answer 1

0

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 .