1 / 25

Z Shell – the last shell you’ll ever need

Z Shell – the last shell you’ll ever need. changlp. Introduction - Shell. 殼 Fetch → Analyze → Execute Fork Type. Introduction – ZSH (1/2). Originally by Paul Falstad in 1990 A shell designed for interactive use Powerful user experience Use sh as underlying syntax

Download Presentation

Z Shell – the last shell you’ll ever need

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Z Shell – the last shell you’ll ever need changlp

  2. Introduction - Shell • 殼 • Fetch → Analyze → Execute • Fork • Type

  3. Introduction – ZSH (1/2) • Originally by Paul Falstad in 1990 • A shell designed for interactive use • Powerful user experience • Use sh as underlying syntax • Easy for using / migrating • Completion & correction • Available in ports: shells/zsh

  4. Introduction – ZSH (2/2) • % rsync -<TAB> • % cd /usr/lica<TAB>

  5. Startup Files (1/2) • For all ZSH • /etc/zshenv • ~/.zshenv • If [ login shell ] • /etc/zprofile • ~/.zprofile • If [ interactive ] • /etc/zshrc • ~/.zshrc • If [ login shell ] • /etc/(z)login • ~/.(z)login

  6. Startup Files (2/2) • zshenv • Settings for ALL types of ZSH • zprofile • Settings for each login session (path … etc) • zshrc • Some interactive settings (prompt … etc) • zlogin (zlogout) • Execute some program on login / logout

  7. IO Redirection - Multios • % date >file1 >file2 … >fileN • % date >file1 | prog1 • % cat -n < /var/log/**/*log(R.) • All files under /var/log and its subdir with 0004 permission • % cat bar | sort <foo • % cat bar foo | sort # note the order

  8. IO Redirection - Null Redirection • % < file • more or $READNULLCMD • % > file • cat or $NULLCMD

  9. Filename Gerneration – Extended Globbing • Common shells support simple globbing • ls –lh * • ls –lh *.[co] • ls –lh *.[^oh] • ZSH supports extended globbing • ls –lh ^*.c • ls –lh ^Makefile • Option: EXTENDEDGLOB (default on)

  10. Filename Generation – Globbing • Recursive globbing • **/ • All dirs and subdirs • ***/ • Also follow symbolic links • Ex. $ ls –lh **/foo • Searches foo under all dir & subdir • Form: (flags)pattern,operator …(qualifier) • Ex. $ ls –lh (#i)[[:digit:]]ggyy.[^oh](R.)

  11. Filename Generation – Globbing flags • Globbing flags • Affect to their right • Until end of enclosing group or end of the pattern • May interleave with operators • $ ls -lh (#i)Make(#I)file • #I/i: case sensitivity • #cM,N: {M,N} in regex • #a: Approximate • … $ ls 1ggyy.c MakeFile Makefile Mekefile Mikefile Mokefile Mukefile Nukefile makefile $ ls (#i)Make(#I)file Makefile makefile

  12. Filename Generation – Globbing operator • Globbing operator • Cooperate with patterns • Like regex • * • This is self explanatory • [] • Match enclosed characters • Named class • [:alpha:], [:digit:]… • Use “^” or “!” for negation • () • Grouping • …

  13. Filename Generation – Globbing qualifier • Globbing qualifier • Specify which filenames should be argument list • /: directories • .: plain files • @: links • +cmd: filename will be included if cmd returns a zero status • …

  14. Filename Generation – Reference • For further glob information • http://zsh.sourceforge.net/Doc/Release/Expansion.html#Filename-Generatio • Have a look on other types of expansion find(1) 是什麼小朋友? 可以吃嗎?Open! ZSH 愛用者

  15. Script • Bourne shell based • Globbing • Expansion • zshexpn(1) • Portability • Use zsh built-ins if possible • Module support

  16. Script – Type System • Data Types • Array • Slice • Scalar (string) • Float • Integer • Association (hash) • % typeset -A blah • % typeset -r agent • Constant • % typeset -U unique_set • Unique set • …

  17. Script - Module • zsh/curses • zsh/mathfunc • zsh/net/tcp • zsh/example • … • Example • http://zshwiki.org/home/code/scripts/zshttpd

  18. Completion • <TAB>, and shell tries to fill the rest • In (t)csh • More in: /usr/share/examples/tcsh/complete.tcsh • In bash • More in: shells/bash-completion • Completion distributed separately complete sudo 'p/1/c/' complete chown 'p/1/u/‘ complete cd ‘p/1/d/’ • complete -f -X '!*.@(Z|[gGd]z|t[ag]z)' gunzip zcat unpigz

  19. Completion in ZSH • Programmable completion • Context sensitive • % echo $OS<TAB> • % cd <TAB> • % ssh <TAB> • Completion function distributed with ZSH • [FreeBSD] See /usr/local/share/zsh/<version>/functions/Completion/

  20. Completion Context (1/2) • :completion:<func>:<completer>:<command>:<argument>:<tag> • Current context while completing • How completion arrived here so far • Func • Blank if called from standard completion system • Completer • Completer name (‘completer’ in standard completion case) • Correction… etc • Command • Argument • Tag • Things can be completed from this point

  21. Completion Context (2/2) • % cd • :completion::complete:cd:: • % git add • :completion::complete:git-add:: (+ more arguments) • :completion::complete:git:: (+ more subcommands) • Tag: modified-files other-files ignored-modified-files ignored-other-files untracked-files

  22. Completion Styles • Control the behavior of completers • zstyle ':completion:*' menu select • zstyle ':completion:*:kill:*' force-list always • zstyle ':completion:*' completer _complete _correct _approximate

  23. Summing Up • Pros • Powerful completion system • Good for interactive • Built-in completion support for most UNIX programs • Cons • Bad for • Slow • Completion system overhead • Complex configuration

  24. Live Demo • 如果有東西壞了請當作沒有看到

  25. Some Plugins & Resourse • https://github.com/zsh-users/zsh-syntax-highlighting • https://github.com/robbyrussell/oh-my-zsh • From Bash to Z Shell: Conquering the Command Line • ZSH manual

More Related