1

I often want to paste things from terminal into my IDE. For example I might want to paste the path to something into the IDE. Is there some way to do

bash: pwd > "paste_variable"

where the content of "paste_variable" is then what comes out of pressing cmd+v?

langkilde
  • 1,473
  • 1
  • 20
  • 37

1 Answers1

2

If you are using the X11 window system (and it's clipboard), you can use xclip to access the clipboard from command line:

paste :

xclip -o             # Write clipboard's contents to stdout
VARIABLE=$(xclip -o) # Write clipboard's contents into a variable
xclip -o | command   # Pipe clipboard contents into command's stdin

copy:

xclip -i "Some text"     # Save static text in the clipboard
xclip -i $(command)      # Save the output of a command into clipboard
command | xclip -i       # Same as above but with a pipe

Note: xclip will probably not getting installed along with the default X11 installation, you'll need to install it explicitly then.

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • 1
    Thanks for the answer! Thanks to this answer I made my way to this question which I didn't find when asking the question: http://stackoverflow.com/questions/749544/pipe-to-from-clipboard Per that answer it can be useful to know that on a Mac you do for example pwd | pbcopy – langkilde Nov 14 '14 at 10:16