parsed.org

Tips by tag: extras

File Globbing by cygnus on Jan 19, 2005 04:14 PM

Some examples of useful file globbing supported by Zsh (if setopt extendedglob has been run):

$ ls foo<1-100>
  (Lists files 'foo1', 'foo2', ..., 'foo100')
$ ls foo<-50>
  (Lists files up to 'foo50')
$ ls *.c~foo.c
  (Lists all *.c files except foo.c)
$ ls *.php~foo*(.)
  (Lists all plain *.php files except those starting with 'foo')
extrasglobzsh
Man Page Completion by cygnus on Dec 31, 2005 04:13 PM

You can complete man page names as well as file names. Put these lines in your ~/.zshrc:

setopt SH_WORD_SPLIT
function man_var () {
   man_pages=( /usr/share/man*/*(N:t:r:r) )
   compctl -k man_pages man
   reply=( $man_pages )
}
compctl -K man_var man; man_pages=()

Now type man foo and the hit TAB to get a list of all man pages beginning with foo.

(Note: this tip taken essentially verbatim [after testing and fixing] from http://www.unixtips.org/index.php3?catList=30.)

autocompleteextrasmanpageszsh
Pipe Read by xinu on Jan 25, 2005 02:01 PM

If you want the time, and only the time:

$ date | (read u v w x y z; echo $x)
14:05:52
commandsdateextrasparsingshell

If you use pushd and popd to maintain your directory stack, then ~N (where ~0 is the top of the stack) will expand to the appropriate directory in the stack. For example:

cygnus:~$ pushd usr
~/usr ~
cygnus:~/usr$ pushd /etc
/etc ~/usr ~
cygnus:/etc$ pushd /usr/lib
/usr/lib /etc ~/usr ~
cygnus:/usr/lib$ cd ~2
cygnus:~/usr$

Furthermore, you can make cd use pushd and popd functionality implicitly:

~> DIRSTACKSIZE=8
~> setopt autopushd pushdminus pushdsilent pushdtohome
~> alias dh='dirs -v'
~> cd /tmp
/tmp> cd /usr
/usr> cd bin
/usr/bin> cd ../pub
/usr/pub> dh
0       /usr/pub
1       /usr/bin
2       /usr
3       /tmp
4       ~
/usr/pub> cd -3
/tmp> dh
0       /tmp
1       /usr/pub
2       /usr/bin
3       /usr
4       ~
/tmp> ls =2/df
/usr/bin/df
/tmp> cd -4
~>

(Note: The text above is taken essentially verbatim from http://www.b2pi.com/zsh/Intro/intro_6.html.)

directoryextrasstackzsh
Ranged Curl by xinu on Jan 15, 2005 02:29 PM

If you have a URL that you need to crawl and you know the range of numbers in the image, you can do something like this:

$ curl -O http://www.example.com/img/samples[00-99].jpg

That should (at least attempt to) fetch the images samples00.jpg through samples99.jpg. Enjoy!

If you're using more than one range, you'll want to build your filename or a path with the --create-dirs option. For example:

$ curl http://www.example.com/imgs[00-99]/samples[00-27].jpg --create-dirs -o "#1/#2.jpg"

Alternatively, you can just be ghetto and name the files like dirname_filename.jpg:

$ curl http://www.example.com/images[00-99]/samples[00-27].jpg -o "#1_#2.jpg"
commandscurlextrasimageshellurl
RSS