1 / 21

Zsh

Zsh. - Larry P. Schrof. Purpose. Spark your interest in zsh To learn more about zsh’s capabilities Expand your productivity. Configuration Files Prompt Tricks Monitoring Logins Aliases The Directory Stack Brace Expansion History: Using fc History Expansion

luke
Download Presentation

Zsh

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. Zsh - Larry P. Schrof

  2. Purpose • Spark your interest in zsh • To learn more about zsh’s capabilities • Expand your productivity

  3. Configuration Files Prompt Tricks Monitoring Logins Aliases The Directory Stack Brace Expansion History: Using fc History Expansion Parameters: Arrays and Subscripting Parameters: Subscript Flags Parameters: Expansion Filename Generation Filename Generation: Qualifiers Programmable Completion Completion Items Restricted Mode ZLE (Zsh Command Line Editor) Where to get more information. Topics Covered

  4. Configuration Files • Order: • /etc/zshenv, then ~/.zshenv • /etc/zprofile, then ~/.zprofile (L) • /etc/zshrc, then ~/.zshrc (I) • /etc/zlogin, then ~/.zlogin (L) • /etc/zlogout then~/.zlogout (logout) • (I) = Only if interactive. (L) = Only if login

  5. Prompt Tricks • Arithmetic, command, and parameter expansion available. • Escape sequences start with a % (Over 40) • Conditional Expressions • %(X.true-text.false-text) • RPROMPT for right-hand side prompt • Formatting and truncating available

  6. Monitoring Logins • Event format: username@host%line • root%console • schrof@procmail.org • Put events in watch parameter • watch=(event1 event2 … eventN) • Set the LOGCHECK parameter • Formatting available

  7. Aliases • name=value syntax • Global aliases! Define with alias -g • Functions are usually preferred

  8. The Directory Stack • Used for managing large lists of directories • dirs -v to examine stack • popd removes a directory from stack, and cd’s to that directory • pushd cd’s to a new directory, and places $OLDPWD on top of the stack • Can use ~ expansion to reference stack entries

  9. Brace Expansion • Alows you to quickly generate lists in two ways • ls -l array{5d,MYd,BIG} • touch logfile.9908{01..31}.tmp • zsh is smart about zero padding

  10. History: Using fc • fc loads past commands into editor, then executes them • fc -l lists previous commands • fc [ -e EDITOR ] [OPTIONS] [old=new …] [first [last ] ] • Options: n l d D r t E i m • fc is not as direct as history expansion, but a bit easier to use

  11. History Expansion • Allows you to reference complete or partial past commands • All expansions start with • Use UP/DOWN arrows in emacs mode • CTRL-R in emacs mode is your friend. • ^old^new trick • designator[:word][:mod1:mod2...]

  12. Parameters: Arrays and Subscripting • Assign: name=(value1 … valueN) • Subscripts: name[expr] • negative expr counts from end • Range: name[expr1,expr2] • Replacement: name[expr]=value • value can be an array • Subscripts work on strings, too!

  13. Parameters: Subscript Flags • $name[(X)expr,(Y)expr2] • w splits by words • s splits on specified characters • f splits on a per-line basis • r treats expr as a pattern; returns first item matching expr • i returns index of first match • R and I just like r and i, but return last match • n used with r, R, i, or I. Returns nth match.

  14. Parameters: Expansion • Standard ksh expansions • ${+var} ${var:-word} ${var:=word} ${var:?} • Adds more expansions • ${name#pattern} ${name%pattern} ${name:#pattern} • Any of above can be preceded by a # for length of result.

  15. Filename Generation • Set EXTENDED_GLOB variable • Operators include *, ?, [], [!], #, ##, <->, |, ^, x~y • **/ does recursive search • print -l /usr/local/src/**/*.[cho]

  16. Filename Generation: Qualifiers • Surpasses most other shells • Limits wildcard matches • After wildcard, enclose list in ()’s • Over 40 qualifiers available, including negation

  17. Programmable Completion • Set with compctl command • Fully programmable. If zsh doesn’t do what you want, you can write it yourself. • Customizable. (menu? Cycle through list? Auto-insert?) • zsh can complete ANYTHING!

  18. Filenames Built-in commands External commands aliases global aliases functions Shell variables Environment variables reserved words Zsh options key bindings Named directories usernames (files, NIS, etc) hosts running jobs suspended jobs Anything else you can imagine. Completion Items

  19. Restricted Mode • Serves well for a guest account • http://www.acm.uiuc.edu/workshops/zsh/restricted.html

  20. Command-line editor • Emacs, vi-insert, and vi-command modes provided • Build your own keymaps from scratch • 160+ pre-defined widgets • Write your own widgets • Rebind any or all portions of keymaps • bindkey used to select and modify keymaps • man zshmodules for details

  21. More Information • Workshop • http://www.acm.uiuc.edu/workshops/zsh • Homepage • http://www.zsh.org • FAQ: • http://sunsite.auc.dk/zsh/FAQ/

More Related