A User's Guide to the Z-Shell
Total Page:16
File Type:pdf, Size:1020Kb
A User’s Guide to the Z-Shell Peter Stephenson 2003/03/23 2 Contents 1 A short introduction 11 1.1 Other shells and other guides . 12 1.2 Versions of zsh . 13 1.3 Conventions . 14 1.4 Acknowledgments . 15 2 What to put in your startup files 17 2.1 Types of shell: interactive and login shells . 17 2.1.1 What is a login shell? Simple tests . 18 2.2 All the startup files . 19 2.3 Options . 21 2.4 Parameters . 21 2.4.1 Arrays . 23 2.5 What to put in your startup files . 24 2.5.1 Compatibility options: SH_WORD_SPLIT and others . 24 2.5.2 Options for csh junkies . 32 2.5.3 The history mechanism: types of history . 34 2.5.4 Setting up history . 36 2.5.5 History options . 37 2.5.6 Prompts . 39 2.5.7 Named directories . 42 2.5.8 ‘Go faster’ options for power users . 43 2.5.9 aliases . 45 2.5.10 Environment variables . 46 3 4 CONTENTS 2.5.11 Path . 47 2.5.12 Mail . 48 2.5.13 Other path-like things . 49 2.5.14 Version-specific things . 50 2.5.15 Everything else . 50 3 Dealing with basic shell syntax 51 3.1 External commands . 51 3.2 Builtin commands . 53 3.2.1 Builtins for printing . 53 3.2.2 Other builtins just for speed . 56 3.2.3 Builtins which change the shell’s state . 57 3.2.4 cd and friends . 59 3.2.5 Command control and information commands . 65 3.2.6 Parameter control . 68 3.2.7 History control commands . 80 3.2.8 Job control and process control . 80 3.2.9 Terminals, users, etc. 89 3.2.10 Syntactic oddments . 89 3.2.11 More precommand modifiers: exec, noglob . 92 3.2.12 Testing things . 93 3.2.13 Handling options to functions and scripts . 96 3.2.14 Random file control things . 98 3.2.15 Don’t watch this space, watch some other . 99 3.2.16 And also . 100 3.3 Functions . 100 3.3.1 Loading functions . 100 3.3.2 Function parameters . 102 3.3.3 Compiling functions . 108 3.4 Aliases . 113 3.5 Command summary . 115 3.6 Expansions and quotes . 116 CONTENTS 5 3.6.1 History expansion . 116 3.6.2 Alias expansion . 117 3.6.3 Process, parameter, command, arithmetic and brace expansion . 117 3.6.4 Filename Expansion . 123 3.6.5 Filename Generation . 126 3.7 Redirection: greater-thans and less-thans . 128 3.7.1 Clobber . 129 3.7.2 File descriptors . 129 3.7.3 Appending, here documents, here strings, read write . 131 3.7.4 Clever tricks: exec and other file descriptors . 132 3.7.5 Multios . 133 3.8 Shell syntax: loops, (sub)shells and so on . 134 3.8.1 Logical command connectors . 134 3.8.2 Structures . 136 3.8.3 Subshells and current shell constructs . 139 3.8.4 Subshells and current shells . 140 3.9 Emulation and portability . 142 3.9.1 Differences in detail . 142 3.9.2 Making your own scripts and functions portable . 144 3.10 Running scripts . 145 4 The Z-Shell Line Editor 149 4.1 Introducing zle . 149 4.1.1 The simple facts . 150 4.1.2 Vi mode . 151 4.2 Basic editing . 152 4.2.1 Moving . 152 4.2.2 Deleting . 152 4.2.3 More deletion . 154 4.3 Fancier editing . 154 4.3.1 Options controlling zle . 154 4.3.2 The minibuffer and extended commands . 155 6 CONTENTS 4.3.3 Prefix (digit) arguments . 156 4.3.4 Words, regions and marks . 156 4.3.5 Regions and marks . 157 4.4 History and searching . 158 4.4.1 Moving through the history . 158 4.4.2 Searching through the history . 159 4.4.3 Extracting words from the history . 161 4.5 Binding keys and handling keymaps . 161 4.5.1 Simple key bindings . 161 4.5.2 Removing key bindings . 162 4.5.3 Function keys and so on . 163 4.5.4 Binding strings instead of commands . 164 4.5.5 Keymaps . 165 4.6 Advanced editing . 166 4.6.1 Multi-line editing . 166 4.6.2 The builtin vared and the function zed . 168 4.6.3 The buffer stack . 169 4.7 Extending zle . 170 4.7.1 Widgets . 170 4.7.2 Executing other widgets . 171 4.7.3 Some special builtin widgets and their uses . ..