On Fri, Mar 01, 2002 at 06:52:19PM +1100, Jamie Wilkinson wrote:
> This one time, at band camp, Andre Pang blessed us with more zsh-crack:
> > 16:33(0) ~% cat =kitkat
> ^
> Wow, nifty.
Want more zsh crack? (Hi Gus :).
# press M-CR to accept and keep the completion going
bindkey '\e^M' accept-and-menu-complete
Add that to your .zshrc. That allows you to scroll through the
list of completions (which you obtain with <Tab>), and when you
press <Esc><CR> (typically <M-CR>), you will insert the currently
selected option into the commandline -- but you can pick more.
e.g.
Step 1.
Your screen looks like:
19:10(0) ~% cp /usr/local/src/linux-kernels/linux-2.4.17-ll-mki/kernel/[]
(where the [] represents where your cursor currently is. Note
the stupidly long path name[1]).
Step 2.
Now press <Tab> twice. Your screen now looks like:
19:10(0) ~% cp /usr/local/src/linux-kernels/linux-2.4.17-ll-mki/kernel/Makefile
completing file
[Makefile] dma.c info.c module.c ptrace.c softirq.c
timer.c
acct.c exec_domain.c itimer.c panic.c resource.c sys.c
uid16.c
capability.c exit.c kmod.c pm.c sched.c sysctl.c
user.c
context.c fork.c ksyms.c printk.c signal.c time.c
The cursor can now be used to scroll through the completions
using the <Up>, <Down> etc arrow keys.
Step 3.
Press <M-CR> to insert the current completion and keep
completing. Your screen now looks like:
19:10(0) ~% cp
/usr/local/src/linux-kernels/linux-2.4.17-ll-mki/kernel/Makefile
/usr/local/src/linux-kernels/linux-2.4.17-ll-mki/kernel/acct.c
completing file
Makefile dma.c info.c module.c ptrace.c softirq.c
timer.c
[acct.c] exec_domain.c itimer.c panic.c resource.c sys.c
uid16.c
capability.c exit.c kmod.c pm.c sched.c sysctl.c
user.c
context.c fork.c ksyms.c printk.c signal.c time.c
Step 4.
Repeat as desired. I'll press <Right> to navigate to to
exec_domain.c and select that, and press <M-CR> to keep
completing. Then I'll press <Right><Right><Down> to go to
printk.c and press <CR> to complete my command:
19:10(0) ~% cp
/usr/local/src/linux-kernels/linux-2.4.17-ll-mki/kernel/Makefile
/usr/local/src/linux-kernels/linux-2.4.17-ll-mki/kernel/exec_domain.c
/usr/local/src/linux-kernels/linux-2.4.17-ll-mki/kernel/printk.c []
completing file
Makefile dma.c info.c module.c ptrace.c softirq.c
timer.c
acct.c exec_domain.c itimer.c panic.c resource.c sys.c
uid16.c
capability.c exit.c kmod.c pm.c sched.c sysctl.c
user.c
context.c fork.c ksyms.c printk.c signal.c time.c
As you can see, this is _really_ useful, especially when dealing
with very long pathnames. Of course, what you can't see in this
email is that all the filenames in the completion list are
actually colourised, typically according to the same colours that
your 'ls' uses.
How about context-sensitive completion, so that typing in 'zcat
<Tab><Tab>' will only complete compressed files?
19:30(0) ~% zcat
completing compressed file
[fishtank.ps.gz] wusage.tar.gz
You'd not believe how annoyed you get at bash(1) when you start
typing 'cd something<Tab>', and it goes and presents a list of
files to you. Can you cd into a file? No! Then why the hell
should pressing 'cd <tab>' display files? It shouldn't!
How about recursive filename globbing?
19:36(0) ~% echo public_html/**/*.html
public_html/index.html public_html/lush/2.4.17-jl15-ll/index.html
public_html/lush/2.4.17-ll-mki/index.html public_html/lush/2.4.18-jl1-ll-mki/index.html
Have you ever done ...
% chmod 600 *
and then thought "Oh crap, that just took away executable
permission on up all my directories!" No problem!
% chmod 700 *(/)
I can't count the number of times I've wanted to make all the
directories below the current one group writable and setgid:
% chmod g+ws **/*(/)
Or maybe you want to just delete all the symlinked files in the
current directory:
% rm *(@)
How many times have you started typing a command, only to forget
what what the command-line options were?
% xhost []
No problem; <M-q> clears the line, lets you type in a command,
and recalls it afterward:
% sudo apt-get install []
(You think: oh, what was that package name I wanted? Press
<M-q>)
% sudo apt-get install []<M-q>
(The line clears, and you type in a command):
% head -1 garnome_packages
libpng-dev libjpeg62-dev libtiff3g-dev
(Ah, that's right! I wanted libpng-dev. Your previous
commandline now reappears):
% sudo apt-get install []
Seriously, switch to zsh today, take the 30 minutes to learn some
of its more useful features, and you'll save yourself
god-knows-how-many key strokes in the end. Trust me, at first
you'll think 'apt-get install gnome<Tab>' is kinda cool, but not
really that useful. After you've used it for a week, you'll just
shake your head when you see people have to type out full package
names like 'gnome-users-guide'.
You're firing me up to do a zsh talk again :).
If people are keen, I'll do a "zsh top ten most useful features"
list or something.
1. Which you can shorten by doing:
% pwd
/home/andrep
% hash -d k=/usr/local/src/linux-kernels/linux-2.4.17-ll-mki/kernel/
% cd ~k
% pwd
/usr/local/src/linux-kernels/linux-2.4.17-ll-mki/kernel/
--
#ozone/algorithm <[EMAIL PROTECTED]> - trust.in.love.to.save
--
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug