tags:

views:

219

answers:

1
+1  A: 

So the command doesn't run arbitrary code. All it does is run man <whatever> in a new screen window if your cursor was over the word <whatever>.

The reason the copy command is there is that you need to tell screen that you want to copy something. You may not always be in screen's copy mode when over a path - for example, you could be using vim, and have vim's cursor over a path. If you are already in copy mode, then it's a no-op.

screen -t man /bin/sh -c 'cat | xargs man || read'
  • screen :: open a new window
  • -t man :: give it a title of man
  • /bin/sh -c 'cat | xargs man || read' :: run this command in the new window, rather than opening the default shell in the new window.
    • /bin/sh :: a shell program
    • -c 'cat | xargs man || read' :: run the given string as a script, rather than opening in interactive mode
    • cat | :: wait for user input (ended with a newline and a CTRL-D), then pipe it as user input to the next command
    • xargs man :: call man, using whatever's read from standard input as command line arguments for man
    • || read :: if the previous commands return non-zero, wait for the user to hit enter

From your output it looks like

  1. The -c part of the command isn't getting run, since it looks like a new shell (the $ is a hint).
  2. The stuff "^M^D" part wasn't transcribed correctly. The next non-comment line after paste '.' should be entered, keystroke for keystroke, as :

    's', 't', 'u', 'f', 'f', ' ', '"', <CTRL-V>, <ENTER>, <CTRL-V>, <CTRL-D>, '"'
    

If you had downloaded the file, rather than transcribed it, you may not have those issues.

Also, bindkey -m ^f is not the same as bind f. And neither bind a command to ^g.

  • bindkey -m ^f binds a command to <CTRL-f>, but only when in copy mode.
  • bind f binds a command to <CTRL-A> f, in all modes.
rampion
@rampion: Thank you for your answer!
Masi
Do you mean that if you use the command always in Screen's copy-mode, you do not need the command `copy`? --- I have always used such commands in Screen's copy-mode only. *What is the main benefit of using such commands outside Screen's copy-mode?* --- *How can you do that?*
Masi
Well, the cursor isn't always at the end of txt outside of copy mode. In vim, when using readline, etc, the cursor can point to various text. So I chose to make my commands able to work directly in those cases, without having to switch to copy mode first.
rampion
@rampion: I opened a new thread about `xargs` at http://stackoverflow.com/questions/1121776/to-understand-xargs-better
Masi
I need the command `xargs man` b/c I'm feeding the copied text in through a paste. So I need the command I run in the new screen window to wait for me to paste some text in, and not run before that. xargs waits on a user input, and makes it into a command line argument for me. Without xargs, screen would just run `man` (no arguments), which wouldn't be very helpful.
rampion