4 ms·
The killer feature of zsh is not the tab completion but the globbing. Really. More or less, you never need the 'find' tool when using zsh. For example, if I wa
by dima55 14y ago
The killer feature of zsh is not the tab completion but the globbing. Really.
More or less, you never need the 'find' tool when using zsh. For example, if I want to find all the Makefiles in this or child directories that have the string 'abc' and have been modified less than 1 hour ago, I can do
$ grep -l abc **/Makefile(mh-1)
If I want to look at the most-recently-modified file, I can
$ less *(om[1])
If I have a symlink 'dir' that points to a directory and I want to cd to the pointed-to directory, I can
$ cd dir(:A)
Clearly, there are lots of codes, but you don't need to remember them, since the tab-completion gives you online help. I can type the '(' then press 'tab', and it'll give me a list of the various codes that can follow and what they mean. There are tons of others. If I want all
*
EXCEPT
*.h
I can use
'*~*.h'
Or for instance, say I have a directory of photos. I want to pick DSC00095.jpg through DSC00107.jpg. In bash, you cry; in zsh I say
DSC<95-107>.jpg.
After I've typed in the glob, I can press 'tab', and it'll expand the glob in-place, letting me know if the code worked without executing. I can then undo to get the code back and have it live in my history.
This feature alone is enough to make a switch worthwhile. It did take me an hour to set up my .zshrc to work like bash, but this has easily paid for itself.
- lutusp 14y ago> Or for instance, say I have a directory of photos. I want to pick DSC00095.jpg through DSC00107.jpg. In bash, you cry; in zsh I say DSC<95-107>.jpg. No need to cry -- Bash does it this way: DSC{95..107}.jpg.
- dima55 14y agoUgh... Did you actually try this? dima@fatty:/media/usb/DCIM/100RICOH$ ls R<22399-22402>* R0022399.JPG R0022400.JPG R0022401.JPG R0022402.JPG dima@fatty:/media/usb/DCIM/100RICOH$ bash -c 'ls R {22392..22402}*' ls: cannot access R22399*: No such file or directory ls: cannot access R22400*: No such file or directory ls: cannot access R22401*: No such file or directory ls: cannot access R22402*: No such file or directory Bash seems to treat these as strings, not like numbers. So in this specific case, I could have manually counted the number of 0s that are required. In some other case where the field width wasn't constant, I wouldn't be able to do that. What if I have files file.1, file.2, file.3, ..., file.9, file.10, file.11, ... How do I pick 9-11 in bash? The point is zsh has features that are a real productivity boost. It's certainly arguable whether a switch is worthwhile, but claiming that these features are just "cosmetic" is wrong.
- aw3c2 14y agoHow old is your Bash? GNU bash, version 4.2.37(2)-release produces $ ls R1004.jpg R1006.jpg R1008.jpg R1010.jpg R1012.jpg R1005.jpg R1007.jpg R1009.jpg R1011.jpg R1013.jpg $ ls R{1005..1009}* R1005.jpg R1006.jpg R1007.jpg R1008.jpg R1009.jpg
- pyre 14y ago> How do I pick 9-11 in bash? Like so: file.{9..11} I think that you mean for the files to be numbered like: file.009 file.010 file.011 Bash would try to expand: file.{9..11} => file.9 file.10. file.11 file.0{9..11} => file.09 file.010 file.011 file.00{9..11} => file.009 file.0010 file.0011 Neither would match all files.
- lutusp 14y ago> Neither would match all files. True, but this works: file.*{9..11} It globs on the LHS, and requires the RHS to be literally consistent with the generated index. I had the same problem with my earlier example, and the above is how I worked it out.
- dredmorbius 14y agoecho file.0{09..11} file.009 file.010 file.011
- aw3c2 14y agofile.{009..011}
- 0x3e 14y agozero padding brace expansion has been available since bash version 4 20/02/2009 $ echo {000..10} 000 001 002 003 004 005 006 007 008 009 010