Having the ability to drive your development using just a keyboard is very productive. However, when you are using a terminal and have to copy the output of a command to use it somewhere else, it breaks your flow, you need to move your hands away from your keyboard, use the mouse to select the text and then copy it.
When I want to copy passwords to be used elsewhere from my browser, I usually open the developer tools console, inspect element and click on the password input box and then run the following code:
$0 to refer to the currently selected DOM element and
will give us the value of the password field and sending it to the
function copies this text to the OS clipboard.
I have a similar script set up for my terminal, when I want to copy the output
of a command like
rake secret I run the following command:
rake secret | xc # copies a new secret to the clipboard.
xc is aliased to the following in my bashrc:
alias xc='tee /dev/tty | xclip -selection clipboard'
This command prints the output to the terminal (using
tee /dev/tty) and copies
it to the OS clipboard using the
I wanted the same ability in my ruby and elixir REPLs. It was pretty straightforward to do in ruby. Here is the annotated code:
puts 'loading ~/.pryrc ...'
Below is a similar script for Elixir:
iex(2)> :crypto.strong_rand_bytes(16) |> Base.encode16 |> H.copy
All these utilities (except for the browser’s
copy function) depend on the
xclip utility which can be installed on ubuntu using
sudo apt-get install
xclip. You can emulate the same behaviour on a Mac using the
you might have to tweak things a little bit, but it should be pretty straightforward.
You can do the same in your favorite programming language too, just find the
right way to spawn an
xclip process and send the text you want to be copied to
its’ stdin. Hope this makes your development a little more pleasant :)