Skip to content

Instantly share code, notes, and snippets.

@davidh-raybeam
Created March 28, 2013 20:03
Show Gist options
  • Save davidh-raybeam/5266339 to your computer and use it in GitHub Desktop.
Save davidh-raybeam/5266339 to your computer and use it in GitHub Desktop.
These ruby and python scripts provide functions that allow you to copy their arguments to the clipboard.
# Put the following function definition into a file called ~/.pythonrc
# and add the line
# export PYTHONSTARTUP="$HOME/.pythonrc"
# to your .bash{rc,_profile}
import os
def clip(x):
os.popen('pbcopy','w').write(str(x))
# Put one of the following function definitions into a file called ~/.irbrc
# irb will run this file on startup
# For OS X
def clip(x)
IO.popen("pbcopy", "w") do |pb|
pb.write(x.to_s)
end
x
end
# For Linux
# Install xclip first ([sudo] apt-get install xclip on debian-like systems)
# Note: I have not tested this yet, but the internets seem to suggest xclip is the answer
# If this does not work, try changing the command to "xclip -selection clipboard"
def clip(x)
IO.popen("xclip", "w") do |xc|
xc.write(x.to_s)
end
x
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment