views:

404

answers:

3

Problem: to have a keyboard shortcut to google a current selection in Screen's copy mode from terminal to Firefox

You can copy the sentence to Screen's clipboard in copy-mode by pressing enter. However, I want to be able to press g to put the Screen's clipboard to the command below as the first parameter:

#!/bin/sh
q=$1
open "http://www.google.com/search?q=$q"

I do the same at the moment by

  1. C-a Esc [select the area] enter
  2. C-z [to put the current window out of the way]
  3. google C-a ]

How can you put Screen's clipboard to the command?

+1  A: 

I'm still trying to work out the exact syntax but take a look at using 'bind' with 'writebuf' (and possibly 'eval') within your .screenrc file.

EDIT

You can bind keys in the .screenrc file in your home directory. E.g.,

bind g eval 'writebuf' 'exec . /bin/sh/ -c "cp /tmp/screen-exchange ~/foo.txt"'

This runs the eval command when you use the g key in screen. Eval takes any number of arguments and runs them as a Tcl script.

writebuf dumps your screen copy/paste buffer into a file at /tmp/screen-exchange.

The second string starts with exec which will run a program external to the Tcl interpreter. In this case, I choose /bin/sh (a *nix shell) and pass an arbitrary system command. The example above copies the /tmp/screen-exchange file but you might:

open < /tmp/screen-exchange

Once the line has been added to ~/.screenrc, restart screen, copy some text and try

C-a g
steamer25
Could you give an example about how you would use these commands, please.
Masi
+1  A: 
open "http://www.google.com/search?q=`xclip -o`"

This works on X's copy buffer rather than Screen's but the X clipboard is usually what you want since it is set by simply highlighting text.

SpliFF
I use currently OS/X Leopard and X11. So I use MacPorts' xclipboard. I get the warning "Error: another clipboard is already running", while in X11 with a highlighted text.
Masi
@ My xclipboard does not have the option -o. It seems that I need to compile from source xclip.
Masi
xclipboard and xclip are quite different. xclipboard is a background daemon for managing the clipboard, xclip is a cli tool to copy/paste text programmically.
SpliFF
+1  A: 

Here's a description of how someone modified their .screenrc file to sync it with the X clipboard. You might try modifying it to send the selected text to Firefox instead of xsel.

dkaylor
I installed XSel. I get the following error: xsel: command not found after pressing > in copy-mode. I have XSel installed, since I can use it in shell by % echo Masi | xsel % and then paste xsel.
Masi
Does it work if you use the full path instead of just xsel?
dkaylor