Z Shell – the last shell you‟ll ever need
changlp
after login after
login - Script
Non
Shellexecuted
Shell
- ? Login User‟s shell User‟s
- Fork
Non • Type
殼 → Execute → Analyze Fetch
interactive Interactive Introduction
Computer Center, CS, NCTU 2
use
in 1990 in
zsh
Falstad ZSH (1/2) ZSH
– by Paul as underlying syntax as underlying
sh Powerful user experience user Powerful / migrating using forEasy
shell designed for interactive designed shell • • Completion & correction & Completion shells/ ports:in Available Use Originally A
Introduction
Computer Center, CS, NCTU 3
ZSH (2/2) ZSH
–
usr cd / cd rsync
%
%
Introduction
Computer Center, CS, NCTU 4
after after login
login - Script Non Shell executed
? Login User‟s shell User‟s
- Non interactive Interactive
zshrc zshenv zprofile / /(z)login / / zshrc zshenv zprofile etc etc etc etc ~/.(z)login / ~/. / / ~/. / ~/.
• • • • • • • •
If [ login shell ] shell login If [ If [ interactive ] If [ interactive If [ login shell ] shell If [ login For all ZSH For all
Startup Startup Files (1/2)
Computer Center, CS, NCTU 5
)
)
etc etc
)
zlogout
(
Execute some program on login / logout/ login on program some Execute Settings for ALL types of ZSH of ALL types for Settings … (path session login each for Settings … (prompt settings interactive Some
profile • • • • zlogin z zshrc zshenv
Startup Startup Files (2/2)
Computer Center, CS, NCTU 6
with 0004 permission 0004 with
subdir fileN Multios
# note the order the # note - /log and its andits /log foo var sort sort /log/**/*log(R.) var / n < - < sort| bar All files under / under files All | foo bar cat %
• • % cat % cat % date >file1 >file2 … > >file2 >file1 % date prog1 | >file1 % date
IO RedirectionIO
Computer Center, CS, NCTU 7
Null RedirectionNull
- NULLCMD
more or$READNULLCMD more or$ cat
• • % > file % > % < file % <
IO RedirectionIO
Computer Center, CS, NCTU 8
Globbing
Extended globbing
–
globbing
Gerneration
Makefile ^ * *.[co] *.[^oh] ^*.c
lh lh lh lh lh – – – – –
ls on) EXTENDEDGLOB (default Option: ls ls ls ls
• • • • • • ZSH ZSH supports extended Common simple support shells Common
Filename
Computer Center, CS, NCTU 9
.)
Globbing …(qualifier)
subdir .[^oh](R –
&
ggyy dir
subdirs )[[:digit:]] i (# **/foo pattern,operator
and
lh lh globbing – –
dirs ls ls
Searches foo under allfoo Searches All symboliclinksAlso follow
Ex. $ Ex. **/ ***/ $ Ex.
• • Form: (flags)Form: Recursive
Filename Generation
Computer Center, CS, NCTU 10
Makefile
makefile
Mokefile
flags
Nukefile makefile Mikefile MakeFile pattern
)Make(#I)file i (#
of theof ls ls Mukefile $ Makefile $ 1ggyy.c Mekefile end Globbing
–
group or group
enclosing
right
)Make(#I)file of i (#
their lh flags -
: {M,N} in regex {M,N} : ls Untilend $ Approximate : case sensitivity case : i
: cM,N # #a … Affect to Affect operators with interleave May #I/
• • • • Globbing
Filename Generation
Computer Center, CS, NCTU 11
operator
Globbing
–
:]… characters
digit
:], :], [:
is self explanatory [:alpha operator
– Matchenclosed Named class Use or “^” “!” for negation Grouping This
… () Cooperate with patterns with Cooperate regex Like * []
• • • • Globbing
Filename Generation
Computer Center, CS, NCTU 12
status qualifier
a zero returns
cmd if Globbing
– should be argument list argument be should
which filenames filenames which qualifier
: filename will be included be included will filename :
cmd … Specify Specify directories /: files plain .: links @: +
• • • • • Globbing
Filename Generation
Computer Center, CS, NCTU 13 -
?
?Open! 是什麼小朋友 Reference
者
– 愛用 ind(1) ind(1) f 可以吃嗎 ZSH
zsh.sourceforge.net/Doc/Release/Expansion.html#Filename :// http Generatio expansion of types other on look a Have
• • For further glob information For further glob
Filename Generation
Computer Center, CS, NCTU 14
ins if possible if ins -
built (1)
zsh
shexpn Module support Module z Use
• • • Portability Expansion Bourne shell based Bourne shell Globbing
Script
Computer Center, CS, NCTU 15
blah
A - unique_set agent
U
r -
-
Type System
% typeset% Slice – Types Unique set Unique Association (hash) Association Constant Array (string) Scalar Float Integer
• • • • • • • % typeset …
% typeset Data
Script Script
Computer Center, CS, NCTU 16
Module zshwiki.org/home/code/scripts/zshttpd tcp
- mathfunc / /net/ /example /curses http://
• Example … zsh zsh zsh zsh
Script Script
Computer Center, CS, NCTU 17
unpigz
zcat
gunzip complete.tcsh / ]z)'
ag tcsh [ z|t ]
gGd /‘
completion -
'p/1/u
'p/1/c/'
/share/examples/
‘p/1/d/’ X '!*.@(Z|[ X - f usr - sudo chown
csh omplete omplete More in: shells/bash in: More / in: More complete complete complete complete c cd complete
• • separately distributed Completion
In bash
Completion
Computer Center, CS, NCTU 18
/
/local/share/
usr
echo $OS
[FreeBSD] See / See [FreeBSD] Context sensitive Context %
• • • •
Completion function distributed with ZSH distributedfunction Completion Programmable completion Programmable
Completion ZSH in
Computer Center, CS, NCTU 19
>
>: >: Things can be completed from this point this from be completed can Things Completer name („completer‟ in standard completion case) completion standard in („completer‟ name Completer Correction… Current context whilecompletingCurrent context farso here arrived completion How system completion standard from called if Blank • • • • • • completion Tag Command Argument Completer Func : Completion Context(1/2) Computer Center, CS, NCTU 20 files files - modified - ) files - :: (+ more arguments) more (+ :: (2/2 files ignored files add - - subcommands) more (+ :: :: other files files files untracked files complete:cd complete:git complete:git - - other - add :completion:: :completion:: :completion:: git cd • • • Tag: modified Tag: ignored % % Completion Context Computer Center, CS, NCTU 21 correct _ always list complete complete - select ':completion:*' menu menu ':completion:*' force ':completion:*:kill:*' _ completer ':completion:*' _approximate zstyle zstyle Control the behavior of of completers behavior the Control zstyle Completion Styles Computer Center, CS, NCTU 22 interactive completion system completion in completion support for most UNIX programs for most UNIX completion support in - for Completion system overheadsystemCompletion Good for Built Bad Bad Slow configuration Complex Powerful • • • • Cons Pros Summing Summing Up Computer Center, CS, NCTU 23 如果有東西壞了請當作沒有看到 Live Demo Computer Center, CS, NCTU 24 Line highlighting - zsh - my - syntax - users/zsh - Resourse github.com/robbyrussell/oh github.com/zsh :// From Bash to Z Shell: Conquering the Command Command the Conquering Shell: to Z Bash From ZSH manual https https:// Some Some Plugins & Computer Center, CS, NCTU 25