Wednesday, March 4, 2015

Copy current working directory in shell using hotkey.

In Linux we constantly deal with file paths and moving stuff around in shell. One thing that I've always wished is to have a shortcut key for copying the current working directory. Traditionally I will be doing this...

> pwd
> returns/the/current/working/dir

Leave keyboard, double click the path to copy it using mouse then back to keyboard and move to another tab and paste it with ctrl+shift+v and resume with the work.

Because I do this all the time and will also be helpful for fellow artists at work I wrote a small shell script and stick it in my bash.

bind '"\eOR":"echo -n $(pwd) | xclip -selection clipboard \n"'

With this, I just press F3 and it copies the current working directory to clipboard and I move to the next tab and past it with out moving my hand from the keyboard. Yeah!!

Setup:

For centos you need to install xclip. Run Sudo yum install xclip

Copy the bind command above to your ~/.bashrc. My shortcut key is currently configured to function key F3. You can configure yours by replacing the OR with the escape code for the respective key combination you want.

Hope its of some help.


No comments:

Post a Comment