Welcome to Coding : Sécurité Programmation Réseaux

Search   in  

 Create an Account Home | Submit News Your Account Content | Topics | Top 10  


Accueil
· Home
· Listing des Articles
· Top 10
· Repository des Exploits

Les sujets / parties
· C / C ++
· Visual Basic
· Asm
· Reseaux
· Java
· Securite
· Divers

Utile
· Listing des Articles

· Telecharger
· Le Forum
· Liens
· Proposer un article

Top20 des Downloads
· 1: Etude des reseaux generalites et protocoles
· 2: Cheval de troie en VB avec sources
· 3: Netcat 1.1
· 4: Keylogger
· 5: Etudes des reseaux hauts debits architectures et protocoles
· 6: Ecoute de port
· 7: Etude du Smart Spoofing
· 8: Win Packet Capture Utils
· 9: Tutorial on Traffic Interception on Switched Lan using ARP spoofing
· 10: Cours de C

User Info
Welcome, Anonymous
Nickname
Password
(Register)
Membership:
Latest: gold-os
New Today: 0
New Yesterday: 1
Overall: 2179

People Online:
Visitors: 38
Members: 0
Total: 38

  
Coding : Sécurité Programmation Réseaux: Forums

Coding :: View topic - repeating key strokes in bash
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

repeating key strokes in bash

 
Post new topic   Reply to topic    Coding Forum Index -> Scripting
View previous topic :: View next topic  
Author Message
Jeenu
Guest





PostPosted: Thu May 15, 2008 6:10 pm    Post subject: repeating key strokes in bash Reply with 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
Back to top
mop2
Guest





PostPosted: Thu May 15, 2008 6:10 pm    Post subject: Re: repeating key strokes in bash Reply with quote

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";}

/tmp/buildk/k7-2.6.21.3/include/config$ d 4
/tmp$
Back to top
mop2
Guest





PostPosted: Thu May 15, 2008 6:10 pm    Post subject: Re: repeating key strokes in bash Reply with quote

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.
Back to top
Jeenu
Guest





PostPosted: Thu May 15, 2008 6:10 pm    Post subject: Re: repeating key strokes in bash Reply with quote

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.

Thanks mop2!
Back to top
mop2
Guest





PostPosted: Thu May 15, 2008 6:10 pm    Post subject: Re: repeating key strokes in bash Reply with quote

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";}
Back to top
mop2
Guest





PostPosted: Thu May 15, 2008 6:10 pm    Post subject: Re: repeating key strokes in bash Reply with quote

This perhaps is better than previous,
only need d ENTER digit (one digit, 1-9):

d(){ read -n 1&&eval "for x in {1..$1};do cd ..;done";}
Back to top
Jeenu
Guest





PostPosted: Thu May 15, 2008 6:10 pm    Post subject: Re: repeating key strokes in bash Reply with quote

On May 15, 9:41 am, mop2 <mop2bky4mz5tyjwa8ersp7hrg5u...@gmail.com>
wrote:
Quote:
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?
Back to top
Stephane CHAZELAS
Guest





PostPosted: Thu May 15, 2008 11:10 pm    Post subject: Re: repeating key strokes in bash Reply with quote

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.

--
Stéphane
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Coding Forum Index -> Scripting All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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

Powered by phpBB © 2001, 2005 phpBB Group
PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.38 Seconds