I'm trying to improve my screen software, so I'll have a lot of questions because there are many answers that I have difficulty to find on internet... Anyway, this one is about a shell command that I would like screen to execute when opening, and it doesn't...
on a new session of screen, I ask screen to open some windows and to name them and to open a file in each of them, and then to split vertically and to open to new empty windows :
screen -t name1 vim /path/to/folder/file1.txt
screen -t name2 vim /path/to/folder/file2.txt
screen -t name3 vim /path/to/folder/file3.txt
screen -t name4 vim /path/to/folder/file4.txt
split -v
focus
screen
focus
screen
but those files create .file.txt.swp and .file.txt.swo hidden files, as usual, so when my computer shut down and files didn't close properly, when I reopen screen it ask what I must do with the .sw* files... I would like to run first this command rm /path/to/folder/.*.sw*
so it doesn't ask for the action when opening (".file.txt.swp already exist ! [O]open, [E]dit anyway, [R]ecover, [Q]uit, [A]bandoned")
In the shell rm path/to/folder/.*.sw*
deletes every swap files as intended, but I can't make it works in .screenrc
This doesn't work :
rm /path/to/folder/.*.sw*
screen -t name1 vim /path/to/folder/file1.txt
screen -t name2 vim /path/to/folder/file2.txt
screen -t name3 vim /path/to/folder/file3.txt
screen -t name4 vim /path/to/folder/file4.txt
split -v
focus
screen
focus
screen
neither does this :
exec rm /path/to/folder/.*.sw*
...
nor this :
eval 'rm /path/to/folder/.*.sw*'
...
or even this :
stuff rm /path/to/folder/.*.sw*
...
and a lot of other 'blind' tries...
Well I have no idea what I'm doing :p
In your
.screenrc
, thescreen
command takes a string which it evaluates itself rather than passing to a shell. So you can't gang multiple commands together so easily... For example, a config line like this:would result in three files being touched --
foo;
,touch
andbar
. :)Instead, you can run a shell interpreter to run multiple commands, including
vim
:The options passed to the
sh
command will be interpreted correctly because within screen, they're all just one option.If you really plan to do this, you may run in to collisions because
name2
andname3
etc will generate swap files at the same time as they are being deleted in another window, so you might do this:Note that another alternative might be to tell
vim
not to create swap files at all. Interatively, you can do this with:To put this on your command line (rather than making it a default for all your
vim
instances), you can use vim's-n
option, which causes vim to open files with no swap:The result will of course be that unsaved changes to your four files will be lost.
One more option might be to move your temporary files to a separate location. For example, if you use
tmpfs
/shmfs
and your /tmp directory is empty as of every reboot, you might use:Then you can still recover the file if a
vim
instance is killed for some other reason than than the server shutting down.