質問

I'm having some trouble getting a new session to execute a command after creation.

Here's a portion of my .tmux.conf:

set-window-option -g automatic-rename off
set-option -g allow-rename off
new -A -s 'main' -n 'servers' 'ls' # troubled line
splitw -h -p 35 htop
splitw -v
splitw -v -t 1
splitw -v -t 1
neww -n 'irc' weechat-curses
selectw -t 0

This is the line that I'm working on:

new -A -s 'main' -n 'servers' 'ls'

Here's how I open tmux:

alias tux='TERM=screen-256color-bce tmux -f ~/.tmux.conf attach-session -t main'

The 'ls' must be causing an error because when it is present, the initial pane doesn't get created. If I change it to 'top', it works fine and the command is executed.

So why does top work and not ls (or any other command I try)?

役に立ちましたか?

解決

top runs until you quit. ls exits after it prints the contents of the current directory. This causes the window in which ls runs to close.

setw -t servers remain-on-exit on

should keep the the window named 'servers' from closing after its command exits, but it is complicated by the fact that the window does not exist before the new-session command is run, and after new-session returns, it may be too late to run the setw command (although you can try).

Instead, create a new session in which the default is for a window to remain after its command exists:

new -A -s 'main' -n 'servers' 'ls' # troubled line
set -t main set-remain-on-exit on
neww -n 'servers' ls

Based on your last comment, ignore the above, and replace your new command with

new -A -s 'main' -n 'servers'
send-keys -t servers.0 ls Enter

This creates a regular window, whose command is a regular shell, but then simulates typing the ls command at the first shell prompt to provide you with the list of files in that directory. After ls completes, you are back in the shell, and the pane will continue to exist until the shell itself completes.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top