Posted: Thu May 15, 2008 6:10 pm Post subject: repeating key strokes in bash
Hi,
I now work with a directory structure that nests very deep; some times
10 to 15 levels. And I do a lot of 'cd ../../' on traversing. I was
checking out something that might help me entering the repeated '../'.
I noticed I might benefit from bind -x command, which could be used to
trigger a shell command when a particular key is pressed. My intention
was, if I could do a 'cd ../' with a key stroke, then I could prefix
that keystroke with an argument (alt+n) so that I could do away with
this long 'cd ../../../../'. Sadly, my bind -x is not working as
expected.
I did:
bind -x '"\M-p": cd ..' and nothing happens; and "\M-p" is still bound
to: non-incremental-reverse-search-history
Can somebody point out what's going wrong here please. Or is there any
other better way?
Posted: Thu May 15, 2008 6:10 pm Post subject: Re: repeating key strokes in bash
Jeenu wrote:
Quote:
Hi,
I now work with a directory structure that nests very deep; some times
10 to 15 levels. And I do a lot of 'cd ../../' on traversing. I was
checking out something that might help me entering the repeated '../'.
I noticed I might benefit from bind -x command, which could be used to
trigger a shell command when a particular key is pressed. My intention
was, if I could do a 'cd ../' with a key stroke, then I could prefix
that keystroke with an argument (alt+n) so that I could do away with
this long 'cd ../../../../'. Sadly, my bind -x is not working as
expected.
I did:
bind -x '"\M-p": cd ..' and nothing happens; and "\M-p" is still bound
to: non-incremental-reverse-search-history
Can somebody point out what's going wrong here please. Or is there any
other better way?
Thanks
Jeenu
Many possibilities!
An idea using a function:
$ d(){ [ "${1//[0-9]}" ]||eval "for x in {1..$1};do cd ..;done";}
Posted: Thu May 15, 2008 6:10 pm Post subject: Re: repeating key strokes in bash
Jeenu wrote:
Quote:
On May 15, 9:41 am, mop2 <mop2bky4mz5tyjwa8ersp7hrg5u...@gmail.com
wrote:
This perhaps is better than the previous one,
only need d ENTER digit (one digit, 1-9):
d(){ read -n1 _D&&eval "for x in {1..$_D};do cd ..;done";}
Thanks; that's cool. Any idea about the bind built in?
$ bind -x '"\M-p": cd ..' # don't worked for me
$ bind -x '"\C-p": cd ..' # this is fine
/tmp/buildk/
k7-2.6.21.3$
/tmp/buildk/k7-2.6.21.3$
cd .
/tmp/buildk
$
/tmp/buildk$ cd .
/tmp$
But the prompt don't change, I need a "cd ." to change it.
If you need change the PWD between 2 or 3 dirs a funtion
with vars D1, D2,D3 can be a easy way to up and down to
specific points. The bind + function can be used if you like.
Sorry, I don't know anything about bind and my english is poor.
Posted: Thu May 15, 2008 6:10 pm Post subject: Re: repeating key strokes in bash
On May 15, 10:29 am, mop2 <mop2bky4mz5tyjwa8ersp7hrg5u...@gmail.com>
wrote:
Quote:
Jeenu wrote:
On May 15, 9:41 am, mop2 <mop2bky4mz5tyjwa8ersp7hrg5u...@gmail.com
wrote:
This perhaps is better than the previous one,
only need d ENTER digit (one digit, 1-9):
d(){ read -n1 _D&&eval "for x in {1..$_D};do cd ..;done";}
Thanks; that's cool. Any idea about the bind built in?
$ bind -x '"\M-p": cd ..' # don't worked for me
$ bind -x '"\C-p": cd ..' # this is fine
/tmp/buildk/
k7-2.6.21.3$
/tmp/buildk/k7-2.6.21.3$
cd .
/tmp/buildk
$
/tmp/buildk$ cd .
/tmp$
But the prompt don't change, I need a "cd ." to change it.
If you need change the PWD between 2 or 3 dirs a funtion
with vars D1, D2,D3 can be a easy way to up and down to
specific points. The bind + function can be used if you like.
Sorry, I don't know anything about bind and my english is poor.
Posted: Thu May 15, 2008 11:10 pm Post subject: Re: repeating key strokes in bash
2008-05-14, 20:47(-07), Jeenu:
Quote:
I now work with a directory structure that nests very deep; some times
10 to 15 levels. And I do a lot of 'cd ../../' on traversing. I was
checking out something that might help me entering the repeated '../'.
I noticed I might benefit from bind -x command, which could be used to
trigger a shell command when a particular key is pressed. My intention
was, if I could do a 'cd ../' with a key stroke, then I could prefix
that keystroke with an argument (alt+n) so that I could do away with
this long 'cd ../../../../'. Sadly, my bind -x is not working as
expected.
[...]
If you're ready to switch to zsh (which I'd recommand), you
could do something like:
rationalise-dot() {
if [[ $LBUFFER = *.. ]]; then
LBUFFER+=/..
else
LBUFFER+=.
fi
}
zle -N rationalise-dot
bindkey . rationalise-dot
If you type
cd ..
then press "." another time, it will turn into:
cd ../..
basically, it transforms "..." to "../.." on the fly while you type.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum