English 中文(简体)
TMUX: how to make new window stay when start shell-command quits?
原标题:
  • 时间:2011-03-15 12:18:13
  •  标签:
  • shell
  • tmux

In tmux command mode, the following creates new window and opens vim inside:

:new-window vim

When you quit vim, the window is also closed. Is there a way to make it stay?

最佳回答

tmux has an option for this: remain-on-exit:

tmux set remain-on-exit on
问题回答

I realise this is a long dead question. But I m a recent user of tmux and I had this same question. It turns out that you might want to do this:

tmux new-session bash -l 

That gets you a bash window (login shell). Then, run whatever commands you want. When they re done, they return to a command prompt, like you expect. I think a lot of people are looking for an interactive screen -like behaviour. This is an easy way to do that.

I use send-keys so that it "types" the command into the shell. Here s my get.all script, which fires up many commands, some of which I may need to interact with after they re done (and the ones I don t, have exit):

#!/bin/sh
tmux att -t get ||
tmux 
  new -s get -n emacs ; 
  send-keys  get.emacs  C-m ; 
  neww -n git ; 
  send-keys  get.git  C-m ; 
  neww -n mini ; 
  send-keys  get.mini  C-m ; 
  neww -n port ; 
  send-keys  get.port  C-m ; 
  neww -n rakudo ; 
  send-keys  get.rakudo  C-m ; 
  neww -n neil ; 
  send-keys  get.neil && get.neil2 && exit  C-m ; 
  neww -n red ; 
  send-keys  get.red && exit  C-m ; 
  neww -n cpan ; 
  send-keys  get.cpan && exit  C-m ; 
  selectw -t emacs

Moving good comment of @Jo So to a separate answer.

This command drops to shell once the first ls -la finishes: tmux new-window "/bin/sh -c ls -la; exec bash "

If you intend to quit the process in the new window normally (as in, proper exit), then tmux new-window "vim ; exec bash" would mostly be fine.

However, if you would intend to quit the new process via system interrupt (SIGINT for example). You will have to use trap.

tmux new-window "bash -c trap "bash" INT; tail -f foo "





相关问题
KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

unix find command

how to use the find command to find files/directories which are not matching the pattern. for eg: find <some options > -name "dontfile.txt" should give me output of all the find whose file ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

1. 露台式照像

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......

热门标签