Lets say I have a script, "myscript.sh
", with contents being simply echo $PWD
. I'd like to bind somehow this script to a key combo in bash
(gnome-terminal
) - so that when I press this key combination, the output of "myscript.sh
" is inserted ("pasted") at the cursor position in the terminal.
Apparently, bash
history and line manipulation is handled by readline - and the references I got for bash
keyboard shortcuts, do reference readline
:
I've also seen in Bash Reference Manual: Readline Init File Syntax that the key bindings for bash
can be listed by using bind -p
(see help bind
[not 'man bind'] for more). So maybe this question would better be titled as "_binding macros to custom keyboard shortcuts in readline
" :) But in any case, is what I want possible to do?
I guess an alternative would be to have the script be something like "pwd | xsel -b
", and then I call it on terminal - and I can paste afterwards; but I'd still like a single keyboard shortcut instead, say like Ctrl-Alt-H (which seems to be not used for anything), which will immediately insert/paste script output when pressed.
Thanks in advance,
Cheers!
EDIT: Just to clarify - here is my use case where I'd like this facility. I'm usually cd
'd in a project folder, usually named something like myproject-folder-0012a
, which is under revision control by svn
. And there is a bunch of these folders. So quite often, I do commits where the first word of the message is the directory name, as in:
svn ci -m "myproject-folder-0012a: here a commit message"
But that is what I don't like - first I type 11 characters, which go rather fast:
svn ci -m "
And then, I cannot use autocompletion to get the name (i'm inside the folder) - which means I either have to fully type it (no way :)), or I copy paste it from the prompt (which requires selection - press mouse, drag, release mouse; then Ctrl+Shift+C, and then Ctrl+Shift+V, plus any left/right keys if I miss allignment - plus deletions and such if I make the copy wrong).
Meaning - so much work, just to get the bloody folder name for a bloody commit message :( I'd MUCH rather press something like (say) Ctrl-Alt-H, and have the folder name automatically inserted at cursor position, and be done with it :)
My suggestion for xsel
is only because I could put it into a "global" script - say symlink it as /usr/bin/myscript
(and obviously, the contents of the script are echo $(basename $PWD)
rather than just pwd
for my needs), and then I could do:
$ myscript # this puts directory name in clipboard
$ svn ci -m "[CTRL+SHIFT+V TO PASTE HERE]myproject-folder-0012a[NOW TYPE]: here a commit message"
... which sort of makes the workload less, but still - then I have to remember what the script name is, and call it, before I type the svn
command (and I don't always remember that)... And still - I have to call a command, and then press a key combo; why shouldn't I just press a key combo once, and be done with it ??! :)
Well, hope this clarifies my problem a bit better ....
EDIT2: However, another reason why a bash
keyboard shortcut would be useful, is that then I could also "paste/insert current directory name" not only in shell commands - but also in terminal programs, say like nano
(where it would, arguably, be more difficult to use bash
script or function expansion directly).