Depending on your distro, you should have a keyboard shortcut program already installed.
I wanted to be able to paste the following very oftenly typed command when pressing a certain key combination:
First, you’ll need xdotool
sudo apt-get install xdotool
I was having trouble putting the commands directly into the keyboard shortcut entry, so I put the commands in a mini bash script.
Open a text editor and paste the following:
cdp=$(echo 'cd /home/admin/web/*/public_html/')
xdotool type --clearmodifiers "$cdp"
Save the file, I saved mine as /home/user/scripts/xdotool-cdp.sh
Next, add a keyboard shortcut for the following (I used Alt+P):
Now when you press Alt + P keys, it executes the script.
The script sets a variable cdp to echo cd /home/admin/web/*/public_html/
Then it sleeps for 0.3 seconds.
Then it types cd /home/admin/web/*/public_html/
Make sure to include –clearmodifiers if you’re using keys such as ctrl, alt or shift as the shortcut as it will affect the way xdotool types.
Check it out: