60
why Z shell (zsh) is cooler than your shell Brendon Rapp - Cave Lunch #1

Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

  • Upload
    others

  • View
    9

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

whyZ shell (zsh)is cooler thanyour shell

Brendon Rapp - Cave Lunch #1

Page 2: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

whyZ shell (zsh)is cooler thanyour shell(unless your shell is zsh)

Brendon Rapp - Cave Lunch #1

Page 3: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

(alternate title)

she sellsZ shellsby thesea shore

Page 4: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

Professor Emeritus of Computer Science at Stanford

Author of The Art of Computer Programming

"Father of algorithmic analysis"

Creator of TeX

Donald Knuth

Page 5: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

In 1986, Knuth was asked to write a guest feature for the "Programming Pearls" column in the Communications of the ACM journal.

The task was to write a program that would:read a file of text, determine the n most frequently used words, and print out a sorted list of those words along with their frequencies.

Page 6: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

Knuth produced a solution in Pascal that, when printed, was about 10 pages in length. It was well designed, thoroughly commented, and used a novel data structure for managing the word count list.

Page 7: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

In response, Doug McIlroy wrote a shell script that produced the same output.

Page 8: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

In response, Doug McIlroy wrote a shell script that produced the same output.

McIlroy's script was six lines long.

Page 9: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

Doug McIlroy's Shell Script

tr -cs A-Za-z '\n' |

tr A-Z a-z |

sort |

uniq -c |

sort -rn |

sed ${1}q

Page 10: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

1971: Thompson shell● Ken Thompson, Bell Labs, first Unix shell● interactive interpreter, not scripting environment

1977: Bourne shell● scripting language● Version 7 Unix, PDP-11● 1984: The UNIX Programming Environment, Kernighan & Pike● The shell of commercial Unixes

○ System V, AIX, HP-UX, SCO, Solaris, SunOS○ Still the default on some of these (that are still alive)

● /bin/sh○ compatibility mode in modern shells○ symlink or hard link to compatible shells in modern Unixes

A brief history of shells

Page 11: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

1978: C shell● BSD Unix● More "C-like" scripting syntax (kinda)● Command history● Aliasing● tcsh - newer C shell, default on FreeBSD, and OS X systems

10.0-10.2

1983: Korn shell● Bell Labs (AT&T)● Proprietary until 2000● vi and emacs editing modes● Lots of C shell features● "middle road" between Bourne and C shell● pdksh - default on OpenBSD

A brief history of shells

Page 12: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

1989: Bourne Again shell (bash)● GNU, GPL● first legitimate Free shell (/bin/sh compatible)

○ shells like ksh and csh became Free only much later on● standard shell for Linux distros, Mac OS X 10.3+● TAB completion● extended scripting syntax

1990: Z shell● most closely resembles Korn shell● /bin/bash compatibility, drop-in replacement for Bash● "new" (despite being over 20 years old)● awesome stuff I'll talk about next

A brief history of shells

Page 13: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

Why use zsh?

Page 14: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

First, a reason that'skind of lame...

Page 15: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

If you're using Mac OS X...

Page 16: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

... your Bash is old!

(OS X 10.8.2... and many earlier OS X versions too)

Page 17: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

● no GPLv3 on OS X

● OS X bash: final version released as GPLv2

● Homebrew has latest Bash (but many use situation as an excuse to try zsh instead)

OS X: GPL Wasteland

Page 18: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

Examples of Actual Zsh Awesomeness

Page 19: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: cd completion

Page 20: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: cd completion

Page 21: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: cd completion

Page 22: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

bash: cd completion

Page 23: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

bash: cd completion

Page 24: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

bash: cd completion

Page 25: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: git completion

Page 26: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: git completion

Page 27: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

bash: git completion

Page 28: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

bash: git completion

It's possible to get completion for git (and many other commands) in Bash by installing bash-completion package, but the completion is still rudimentary compared to zsh:● no cycling through options with repeated tabs● no accompanying info with commands, just a list● breaks to new prompt line on each tab instead of updating in-place

There may be ways to improve that situation and bring it more in line with zsh, but with zsh, you get it basically out-of-the-box, with a single command in your .zshrc to enable completions.

Page 29: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: path expansion

(hit TAB, and then...)

Page 30: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: path expansion

(... the path is expanded in place, provided there is only one path matching that pattern)

Page 31: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: path expansion

(If there isn't only one distinct match for the pattern...)

Page 32: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: path expansion

(... the first TAB will expand up until it hits an ambiguity... )

Page 33: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: path expansion

(... the next TAB lists the possible matches... )

Page 34: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: path expansion

(... then TAB begins cycling through the possibilities... )

Page 35: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: path expansion

(... until you get to the one you want, and hit the Right arrow to "select" it ... )

Page 36: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: path expansion

(... and then TAB resumes matching through the rest of the path)

Page 37: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

bash: path expansion?

(hit TAB ... nothing)

Page 38: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: path replacement

(Whoops. I meant /usr/local/share)

Page 39: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: path replacement

Page 40: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: path replacement

(no more "cd ../../../")

Page 41: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

bash: path replacement?

Page 42: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: right prompt

PROMPT (or PS1): left prompt (like bash)

RPROMPT (or RPS1): right prompt!

Page 43: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: right prompt

Page 44: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: spelling correction

Page 45: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: spelling correction

Page 46: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: spelling correction

Page 47: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: aliases

Normal aliases:

alias ls='ls --color=auto'

Page 48: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: aliases

Global aliases - appear anywhere in command string

alias -g gp='| grep -i'

% ps ax gp ruby

=> ps ax | grep -i ruby

Page 49: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: aliases

Suffix aliases - "Open With..."

alias -s rb=vim

alias -s log="less -MN"

alias -s html=chromium

% user.rb

=> vim user.rb

% development.log

=> less -MN development.log

% index.html

=> chromium index.html

Page 50: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: extended globbing

Normal globbed search

Page 51: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: extended globbing

Extended globbed search: **/ = recursive

Page 52: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: environment variable editing

Page 53: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh: programmable file renaming

Page 54: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh-history-substring-search

Down arrow = cycle through command history

Page 55: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh-history-substring-search

Type part of command and hit up arrow, cycle through only commands that begin with that string

Page 56: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

zsh-syntax-highlighting

Highlights valid commands in green, invalid commands in red

Supports shell commands as well as executables in $PATH

Page 57: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

oh-my-zsh

Page 58: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in
Page 59: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

Other zsh bullet points

● Simple configuration style● Shared history

○ simple & fast, requires some monkeying to replicate in bash

● Lots of additions for shell scripting● Output redirection to multiple destinations

And, apparently, plenty of other stuff deeper than I've gotten so far.

Page 60: Z shell (zsh) is cooler thanBrendon Rapp - Cave Lunch #1 shellquack1.me/upload/zsh.pdf · bash: git completion It's possible to get completion for git (and many other commands) in

The End

Go 49ers