Zsh
topic kurze Beschreibung
Beschreibung
Installation
Anwendungen
Fehlerbehebung
Syntax
Optionen
Parameter
Umgebungsvariablen
Exit-Status
Konfiguration
Dateien
Sicherheit
Dokumentation
RFC
Man-Pages
Info-Pages
Siehe auch
Links
Projekt-Homepage
Weblinks
- Wikipedia:Zsh
- An Introduction to the Z Shell
- A User's Guide to ZSH
- The Z Shell Manual (different format available here)
- Zsh FAQ
- Vorlage:Man (available as Vorlage:Pkg package)
- Gentoo: Zsh/Guide
- Bash2Zsh Reference Card
Testfragen
Testfrage 1
Testfrage 2
Testfrage 3
Testfrage 4
Testfrage 5
Wikipedia
Die Z shell (zsh) ist eine Unix-Shell, die sowohl als interaktive Login-Shell, als auch als ein mächtiger Kommandozeileninterpreter für Shellskripte verwendet werden kann. Die zsh wird oft als erweiterte Bourne-Shell angesehen, welche viele Verbesserungen und Eigenschaften von bash, ksh und tcsh vereint.
Die Z shell ist in Apples Betriebssystem MacOS seit MacOS Catalina und bei Kali Linux seit Version 2020.4 die voreingestellte Shell.
- Beschreibung = Beispiel einer Z-Shell-Sitzung
- Hersteller = Peter Stephenson und andere
- Betriebssystem = verschiedene
- Programmiersprache = C
- Kategorie = Unix-Shell
- Lizenz = BSD-artige Lizenz
- Website = zsh.org
Ursprung
Die erste Version wurde 1990 von Paul Falstad, zu der Zeit Student der Princeton University, geschrieben.
Namensherkunft
Der Name zsh leitet sich von Zhong Shao, Professor an der Yale University, ab, der damals Assistent an der Princeton University war. Paul Falstad dachte, dass Shaos Login-Name „zsh“ ein guter Name für eine Shell sei.
Eigenschaften
- Programmierbare Befehlszeilenergänzung für sowohl Optionen als auch Argumente der meistgenutzten Programme inklusive einer nativen Unterstützung von mehreren hundert Programmen
- Benutzung derselben Befehlshistorie aller laufenden Shells
- Erweitertes Dateiglobbing ermöglicht es, ohne externen Programmaufruf Dateien näher zu spezifizieren
- Erweiterte Variablen-/Array-Handhabung
- Editierbarkeit von Befehlen mit mehreren Zeilen
- Rechtschreibkorrektur
- Kompatibilitätsmodi für andere Shells, kann sich bspw. als Bourne-Shell ausgeben wenn ausgeführt als
/bin/sh
- Individualisierbarer Prompt mit der Möglichkeit, Informationen am rechten Bildschirmrand anzuzeigen und diese zu entfernen, falls der Befehl zu lang wird
- Nachträglich ladbare Module, unter anderem vollständige TCP- und IPC-Socket-Bedienbarkeit, ein FTP-Client und erweiterte mathematische Funktionen
- Viele Anpassungsmöglichkeiten
Weblinks
Einzelnachweise
ubuntuusers
{{{#!vorlage Wissen [:Pakete_installieren: Installation von Programmen] [:Terminal: Ein Terminal öffnen] }}} Inhaltsverzeichnis()
Bild(Wiki/Icons/terminal.png, 48, left) Die Zsh {en} ist neben der [:Bash/] eine weitere sehr mächtige [:Shell:] und Skriptsprache, die viele Möglichkeiten bietet. Die Zsh ist von diversen anderen Shells beeinflusst, wie beispielsweise der Korn-Shell (ksh), der C-Shell (csh) oder der TENEX C-Shell (tcsh). Der größte Vorteil der Z-Shell ist wohl der sehr ausgereifte Command-Editor.
Installation
Folgendes Paket muss installiert werden [1]:
{{{#!vorlage Paketinstallation zsh }}} Möchte man zsh als seine Standard-Shell einrichten, reicht ein Aufruf von [:chsh:] und der Eingabe von /usr/bin/zsh: {{{#!vorlage Befehl chsh Passwort: Login-Shell für Mustermann wird geändert. Geben Sie einen neuen Wert an oder drücken Sie ENTER für den Standardwert
Login-Shell [/usr/bin/bash]: /usr/bin/zsh
}}}
Von nun an ist Zsh die Standardshell.
Mit derselben Methode kann auch wieder zu [:Bash/] oder [:Dash:] gewechselt werden. Wird die Shell einer laufenden Sitzung verändert, so muss sich der Nutzer erst neu anmelden, bevor er seine neue Shell nutzen kann.
Konfiguration
Die Konfiguration wird in verschiedenen Dateien festgelegt, die beim Start der Z-Shell eingelesen werden. Die folgende Tabelle gibt Aufschluss über den Geltungsbereich der Einstellungen und die Reihenfolge, in der die so genannten start-up-files verarbeitet werden.
||<rowclass="kopf">Geltungsbereich||Systemweit||Benutzerspezifisch||Kommentar|| ||1. Allgemein||/etc/zsh/zshenv||~/.zshenv||[:Umgebungsvariablen:] die in jeder Sitzung gelten|| ||2. Login-Shell||/etc/zsh/zprofile||~/.zprofile||Benutzerprofil; Befehle die während der Sitzung zur Verfügung stehen|| ||3. Interaktive Shell||/etc/zsh/zshrc||~/.zshrc||Befehle, die beim Start einer interaktiven Shell ausgeführt werden|| ||4. Login-Shell||/etc/zsh/zlogin||~/.zlogin||Befehle, die beim Start jeder Shell ausgeführt werden|| ||5. Logout||/etc/zsh/zlogout||~/.zlogout||Befehle, die beim Beenden ausgeführt werden||
Konfiguration von Grml
Die Linuxdistribution Grml {en} bringt die Zsh von Haus aus mit und hat diese über die .zshrc sehr gut vorkonfiguriert. Um diese bei sich nutzen zu können installiert man sie sich mit dem Befehl:
{{{#!vorlage Befehl wget -O ~/.zshrc https://raw.githubusercontent.com/grml/grml-etc-core/master/etc/zsh/zshrc }}} {{{#!vorlage Hinweis Die bestehende Konfiguration wird dabei überschrieben. }}}
Prompt in Farbe
Die Globale Variable heisst nicht PS sondern PROMPT, wobei es auch einen RPROMT gibt, der am rechten Rand Informationen definiert.
{{{#!vorlage Tabelle <rowclass="titel" -2>Variablen sind: +++ <rowclass="kopf" -2>Login +++ %M Hostname +++ %n Nutzername +++ <rowclass=""-2> `Weitere: %l TTY / %m Hostname bis ersten Punkt / %y TTL ungekürzt` +++ <rowclass="kopf">Shell Status +++ %d aktuelles Verzeichnis +++ %~ aktuelles Verzeichnis, Heimatverzeichnis abgekürzt +++ <rowclass=""-2> `Weitere: %? Statuscode vorheriges Prg. / %h Bef.-Verlauf-Nummer / %C schleppendes Verzeichnis` +++ <rowclass="kopf"-2> Datum und Zeit +++ %D Datum als JJ-MM-TT +++ %T Uhrzeit (SS:MM) +++ %t Uhrzeit 12Std-Format (SS:MM) with AM/PM ; Alternative: %@ +++ %* Uhrzeit mit Sekunden +++ %w Datum mit Wochentag +++ %W Datum dezimal MM/TT/JJ +++ %D{string} Datum/Uhrzeit als strftime Format }}}
{{{#!vorlage Tabelle <rowclass="kopf">Effekt-Parameter sind: +++ Start Stop Effekt +++ %B %b Bold / Fettschrift +++ %U %u Underline +++ %S %s Highlighted +++ %F{color} %f Vordergrundfarbe +++ %K{color} %k Hintergrundfarbe }}} Die Farben entsprechen der 16 und 256 Bit Farbtabelle {en} für XTerm.
Eine dem Suse-Shell ähnlichem aber farblichen Code sähe dann so aus:
Bild(farbiger-zsh-prompt.png )
und könnte so {{{#!vorlage Befehl PROMPT='%F{184}%n%f@%F{013}%m%f:%~/ > ' }}} zB. in die ~/.zshrc eingetragen werden.
Module
Durch Module kann die Zsh erweitert werden. Module werden mit dem Befehl:
{{{#!vorlage Befehl autoload -U <modulname> }}} geladen und durch den Aufruf von <modulname> gestartet.
zftp
Das Modul der Z-Shell für das [wikipedia:File Transfer Protocol:] kann einzeln geladen oder fest eingebunden werden. Im Artikel zu [:Zsh/zftp:zftp] ist ein Mittelweg beschrieben: die Einbindung für einen einzelnen Benutzer. Zudem werden einfache Befehle für die Sitzungsverwaltung und den Dateitransfer erklärt.
Prompt Themes
Das Modul promptinit bietet einige voreingestellte Prompt-Themes, mit denen man das (etwas langweilige) Standard-Prompt verschönern kann. Zuerst wird das Modul geladen und gestartet:
{{{#!vorlage Befehl autoload -U promptinit && promptinit }}} Jetzt hat man das Kommando prompt zur Verfügung, mit dem man die Prompt-Themes laden kann:
{{{#!vorlage Befehl prompt -c # zeigt den derzeit gewählten Theme prompt -l # zeigt alle verfügbaren Themes prompt -p <name> # zeigt ein Preview des Themes prompt -s <name> # ändert die Shell zum Theme <name> und speichert diesen prompt <name> # ändert die Shell zu <name>, speichert aber nicht }}}
Erweitertes Alias
In der zsh gibt es neben der bekannten Möglichkeit, ein [:alias:] zu setzen, noch 2 weitere Möglichkeiten.
Globales Alias
Globale Ersetzungen arbeiten grundsätzlich wie ein normales [:alias:], mit dem einzigen Unterschied, dass globale Ersetzungen in jedem Teil des Befehls auftauchen dürfen und können. So lassen sich (zum Beispiel) häufig genutzte Pipes geschickt abkürzen. Ein [:alias:] für eine Pipe mit [:less:] sieht so aus:
less'
Weitere Beispiele dazu gibt es im Zsh-Wiki {en}.
Suffix Alias
Mit zsh besteht die Möglichkeit, Dateiendungen (Suffixe) mit einer bestimmten Anwendung zu verknüpfen. Dann reicht es, den Namen der Datei im [:Terminal:] einzugeben, diese wird dann mit der definierten Anwendung geöffnet. So werden im folgenden Beispiel Dateien mit dem Suffix "wav" mit play abgespielt:
{{{#!vorlage Befehl alias -s wav='play -q' }}} Auch hier bietet das Zsh-Wiki {en} weitere Beispiele.
command-not-found
Das nützliche Werkzeug [:command-not-found:], das einem in der [:Bash/] anzeigt, mit welchem Paket sich das eben aufgerufene aber nicht vorhandene Programm installieren lässt, ist in der zsh leider nicht standardmäßig aktiv. Zur Aktivierung muss die Datei /etc/zsh_command_not_found entweder am Ende der Datei /etc/zsh/zshrc (systemweit) oder in der Datei ~/.zshrc (benutzerspezifisch) eingebunden werden.
Aus {{{#!code bash ...
- If you don't want compinit called here, place the line
- skip_global_compinit=1
- in your $ZDOTDIR/.zshenv or $ZDOTDIR/.zprofice
if -z "$skip_global_compinit" ; then
autoload -U compinit compinit
fi }}} wird (Zeilen 9-13 sind hinzugefügt worden) {{{#!code bash ...
- If you don't want compinit called here, place the line
- skip_global_compinit=1
- in your $ZDOTDIR/.zshenv or $ZDOTDIR/.zprofice
if -z "$skip_global_compinit" ; then
autoload -U compinit compinit
fi if -x /usr/lib/command-not-found ; then
function command_not_found_handler() { /usr/lib/command-not-found --no-failure-msg -- $1 }
fi }}} Beipielausgabe ohne command not found {{{#!vorlage Befehl % gps-correlate zsh: command not found: gps-correlate }}} Beipielausgabe mit command not found {{{#!vorlage Befehl % gps-correlate zsh: command not found: gps-correlate No command 'gps-correlate' found, did you mean:
Command 'gpscorrelate' from package 'gpscorrelate' (universe)
gps-correlate: command not found }}}
Links
* [iawm::]Die Z-Shell (zsh) – Eine mächtige Alternative zur Bash {de} - Blogbeitrag, 02/2010 (archivierte Version von Archive.org) * Zsh-Wiki {en} * Zsh-Lovers {en} * Tipps&Tricks {en} * strcat.de/zsh {en} Gute Einführung in die Zsh mit vielen Beispielen * Die Zsh-Liebhaber-Seite nur noch im Archiv {de}, neue einzelne Artikel im Blog * [github:robbyrussell/oh-my-zsh:] {en} - Framework zum einfachen Einstieg, bei dem man "Oh meine Zsh" ruft * [wikipedia:Unix-Shell:Unix-Shell] Unix-Shells in der Wikipedia
archlinux
de:Zsh es:Zsh fa:Zsh ja:Zsh pt:Zsh ru:Zsh zh-hans:Zsh Zsh is a powerful shell that operates as both an interactive shell and as a scripting language interpreter. While being compatible with the POSIX sh (not by default, only if issuing Vorlage:Ic), it offers advantages such as improved tab completion and globbing.
The Zsh FAQ offers more reasons to use Zsh.
Installation
Before starting, users may want to see what shell is currently being used:
$ echo $SHELL
Install the Vorlage:Pkg package. For additional completion definitions, install the Vorlage:Pkg package as well.
Initial configuration
Make sure that Zsh has been installed correctly by running the following in a terminal:
$ zsh
You should now see zsh-newuser-install, which will walk you through some basic configuration. If you want to skip this, press Vorlage:Ic. If you did not see it, you can invoke it manually with:
$ autoload -Uz zsh-newuser-install $ zsh-newuser-install -f
Making Zsh your default shell
Change your shell to Vorlage:Ic. See Command-line shell#Changing your default shell.
Startup/Shutdown files
When starting, Zsh will read commands from the following files in this order by default, provided they exist.
- Vorlage:Ic Used for setting environment variables for all users; it should not contain commands that produce output or assume the shell is attached to a TTY. When this file exists it will always be read, this cannot be overridden.
- Vorlage:Ic Used for setting user's environment variables; it should not contain commands that produce output or assume the shell is attached to a TTY. When this file exists it will always be read.
- Vorlage:Ic Used for executing commands at start for all users, will be read when starting as a login shell. Please note that on Arch Linux, by default it contains one line which sources Vorlage:Ic. See warning below before wanting to remove that!
- Vorlage:Ic This file should be sourced by all POSIX sh-compatible shells upon login: it sets up Vorlage:Ic and other environment variables and application-specific (Vorlage:Ic) settings upon login.
- Vorlage:Ic Used for executing user's commands at start, will be read when starting as a login shell. Typically used to autostart graphical sessions and to set session-wide environment variables.
- Vorlage:Ic Used for setting interactive shell configuration and executing commands for all users, will be read when starting as an interactive shell.
- Vorlage:Ic Used for setting user's interactive shell configuration and executing commands, will be read when starting as an interactive shell.
- Vorlage:Ic Used for executing commands for all users at ending of initial progress, will be read when starting as a login shell.
- Vorlage:Ic Used for executing user's commands at ending of initial progress, will be read when starting as a login shell. Typically used to autostart command line utilities. Should not be used to autostart graphical sessions, as at this point the session might contain configuration meant only for an interactive shell.
- Vorlage:Ic Used for executing commands when a login shell exits.
- Vorlage:Ic Used for executing commands for all users when a login shell exits.
See the graphic representation.
Configure Zsh
Although Zsh is usable out of the box, it is almost certainly not set up the way most users would like to use it. But due to the sheer amount of customization available in Zsh, configuring Zsh can be a daunting and time-consuming experience. For automatic configuration, see #Third-party extensions.
Simple .zshrc
Included below is a sample configuration file. It provides a decent set of default options as well as giving examples of many ways that Zsh can be customized. In order to use this configuration save it as a file named Vorlage:Ic.
Here is a simple Vorlage:Ic:
See #Prompt themes for more details about the prompt theme system.
Configuring $PATH
Zsh ties the Vorlage:Ic variable to a Vorlage:Ic array. This allows you to manipulate Vorlage:Ic by simply modifying the Vorlage:Ic array. See A User's Guide to the Z-Shell for details.
To add Vorlage:Ic to the Vorlage:Ic:
Command completion
Perhaps the most compelling feature of Zsh is its advanced autocompletion abilities. At the very least, enable autocompletion in Vorlage:Ic. To enable autocompletion, add the following to your Vorlage:Ic:
The above configuration includes ssh/scp/sftp hostnames completion but in order for this feature to work, users must not enable ssh's hostname hashing (i.e. option Vorlage:Ic in ssh client configuration).
For autocompletion with an arrow-key driven interface, add the following to:
To activate the menu, press Vorlage:Ic twice.
For enabling autocompletion of privileged environments in privileged commands (e.g. if you complete a command starting with sudo, completion scripts will also try to determine your completions with sudo), include:
Key bindings
Zsh does not use readline, instead it uses its own and more powerful Zsh Line Editor (ZLE). It does not read Vorlage:Ic or Vorlage:Ic. Read A closer look at the zsh line editor and creating custom widgets for an introduction to ZLE configuration.
ZLE has an Emacs mode and a vi mode. If one of the Vorlage:Ic or Vorlage:Ic environment variables contain the string Vorlage:Ic then vi mode will be used; otherwise, it will default to Emacs mode. Set the mode explicitly with Vorlage:Ic or Vorlage:Ic respectively for Emacs mode or vi mode.
Key bindings are assigned by mapping an escape sequence matching a keypress to a ZLE widget. The available widgets, with descriptions of their actions and their default keybindings, are listed in Vorlage:Man and Vorlage:Man.
The recommended way to set key bindings in Zsh is by using string capabilities from Vorlage:Man. For example[1][2]:
History search
You need to set up the Vorlage:Ic array and make sure that ZLE enters application mode to use the following instructions; see #Key bindings.
To enable history search add these lines to Vorlage:Ic file:
By doing this, only the past commands matching the current line up to the current cursor position will be shown when Vorlage:Ic or Vorlage:Ic keys are pressed.
Shift, Alt, Ctrl and Meta modifiers
xterm-compatible terminals can use extended key-definitions from Vorlage:Man. Those are combinations of Vorlage:Ic, Vorlage:Ic, Vorlage:Ic and Vorlage:Ic together with Vorlage:Ic, Vorlage:Ic, Vorlage:Ic, Vorlage:Ic, Vorlage:Ic, Vorlage:Ic, Vorlage:Ic, Vorlage:Ic or Vorlage:Ic. Refer to the zkbd source for a list of recommended names for the modifier keys and key combinations.
For example, for Vorlage:Ic to move to the beginning of the previous word and Vorlage:Ic to move to the beginning of the next word:
Prompts
Zsh offers the options of using a prompt theme or, for users who are dissatisfied with the themes (or want to expand their usefulness), the possibility to build a custom prompt.
Prompt themes
Prompt themes are a quick and easy way to set up a colored prompt in Zsh. See Vorlage:Man for information about prompt themes and how to write your own theme.
To use a theme, make sure that prompt theme system is set to autoload in Vorlage:Ic. This can be done by adding these lines to:
Available prompt themes are listed by running the command:
$ prompt -l
For example, to use the Vorlage:Ic theme, enter:
$ prompt walters
To preview all available themes, use this command:
$ prompt -p
Manually installing prompt themes
It is possible to install themes manually, without external configuration manager tools. For a local installation, first create a folder and add it to the Vorlage:Ic array, eg:
$ mkdir ~/.zprompts $ fpath=("$HOME/.zprompts" "$fpath[@]")
Now create a symbolic link of your theme file in this folder:
$ ln -s mytheme.zsh ~/.zprompts/prompt_mytheme_setup
If instead you wish to install a theme globally, do:
# ln -s mytheme.zsh /usr/share/zsh/functions/Prompts/prompt_mytheme_setup
Now you should be able to activate it using:
$ prompt mytheme
If everything works, you can edit your Vorlage:Ic accordingly.
Adding prompt themes without a separate file for each one
In addition to adding a prompt theme through its own file, it is possible to add themes from within another file (like your Vorlage:Ic), eg:
Customized prompt
Additionally to a primary left-sided prompt Vorlage:Ic (Vorlage:Ic, Vorlage:Ic) that is common to all shells, Zsh also supports a right-sided prompt Vorlage:Ic (Vorlage:Ic). These two variables are the ones you will want to set to a custom value.
Other special purpose prompts, such as Vorlage:Ic (Vorlage:Ic), Vorlage:Ic (Vorlage:Ic), Vorlage:Ic (Vorlage:Ic), Vorlage:Ic (Vorlage:Ic), Vorlage:Ic (Vorlage:Ic) and Vorlage:Ic, are explained in Vorlage:Man.
All prompts can be customized with prompt escapes. The available prompt escapes are listed in Vorlage:Man.
Colors
Zsh sets colors differently than Bash; You do not need to use profuse ANSI escape sequences or terminal capabilities from Vorlage:Man. Zsh provides convenient prompt escapes to set the foreground color, background color and other visual effects; see Vorlage:Man for a list of them and their descriptions.
Colors can be specified using a decimal integer, the name of one of the eight most widely-supported colors or as a # followed by an RGB triplet in hexadecimal format. See the description of fg=colour in Vorlage:Man for more details.
Most terminals support the following colors by name:
Name | Number |
---|---|
Vorlage:Ic | Vorlage:Ic |
Vorlage:Ic | Vorlage:Ic |
Vorlage:Ic | Vorlage:Ic |
Vorlage:Ic | Vorlage:Ic |
Vorlage:Ic | Vorlage:Ic |
Vorlage:Ic | Vorlage:Ic |
Vorlage:Ic | Vorlage:Ic |
Vorlage:Ic | Vorlage:Ic |
Color numbers 0–255 for terminal emulators compatible with xterm 256 colors can be found in the xterm-256color chart.
With a correctly set TERM environment variable, the terminal's supported maximum number of colors can be found from the Vorlage:Man database using Vorlage:Ic. In the case of 24-bit colors, also check the COLORTERM environment variable with Vorlage:Ic. If it returns Vorlage:Ic or Vorlage:Ic then your terminal supports 16777216 (224) colors even if terminfo shows a smaller number.
Example
An example of a simple colorless prompt:
PROMPT='%n@%m %~ %# '
How it will be displayed:
This is an example of a two-sided prompt with color:
PROMPT='%F{green}%n%f@%F{magenta}%m%f %F{blue}%B%~%b%f %# ' RPROMPT='[%F{yellow}%?%f]'
And here is how it will be displayed:
To use colors from the 16-255 range and 24-bit true color, you can use the number from 0 to 255 assigned to the wanted color and its hexadecimal color code, respectively:
PROMPT='%F{2}%n%f@%F{5}%m%f %F{4}%B%~%b%f %# ' RPROMPT='[%F{3}%?%f]'
PROMPT='%F{#c0c0c0}%n%f@%F{#008000}%m%f %F{#800080}%B%~%b%f %# ' RPROMPT='[%F{#0000ff}%?%f]'
Sample .zshrc files
- To get the same setup as the monthly ISO releases (which use Zsh by default), install Vorlage:Pkg. It includes the many tweaks and advanced optimizations from grml.
- https://github.com/MrElendig/dotfiles-alice/blob/master/.zshrc - basic setup, with dynamic prompt and window title/hardinfo.
- https://github.com/slashbeast/conf-mgmt/blob/master/roles/home_files/files/DOTzshrc - zshrc with multiple features, be sure to check out comments into it. Notable features: confirm function to ensure that user want to run poweroff, reboot or hibernate, support for GIT in prompt (done without vcsinfo), tab completion with menu, printing current executed command into window's title bar and more.
See dotfiles#User repositories for more.
Tips and tricks
Autostart X at login
See xinit#Autostart X at login.
Restore terminal settings after a program exits abnormally
Many programs change the terminal state, and often do not restore terminal settings on exiting abnormally (e.g. when crashing or encountering SIGINT).
This can typically be solved by executing Vorlage:Man:
$ reset
The following sections describe ways to avoid the need to manually reset the terminal.
The ttyctl command
The ttyctl command can be used to "freeze/unfreeze" the terminal. To freeze the interactive shell on launch, use the following:
Resetting the terminal with escape sequences
Alternate linedrawing character set can screw up the terminal in a way which ttyctl cannot prevent.
A simple solution is to output the escape sequences that reset the terminal from the Vorlage:Ic hook function, so that they are executed every time before the prompt is drawn. For example, using the escape sequence Vorlage:Ic:
To test if it works, run:
$ print '\e(0\e)B'
Remembering recent directories
Dirstack
Zsh can be configured to remember the DIRSTACKSIZE last visited folders. This can then be used to cd them very quickly. You need to add some lines to your configuration file:
Now use
$ dirs -v
to print the dirstack. Use Vorlage:Ic to go back to a visited folder. Use autocompletion after the dash. This proves very handy if using the autocompletion menu.
cdr
cdr allows you to change the working directory to a previous working directory from a list maintained automatically. It stores all entries in files that are maintained across sessions and (by default) between terminal emulators in the current session.
See Vorlage:Man for setup instructions.
zoxide
Vorlage:Pkg is a smarter cd command that lets you navigate anywhere in just a few keystrokes. It remembers your frequently used directories and uses a scoring mechanism to guess where you want to go.
Help command
Unlike Bash, Zsh does not enable a built in Vorlage:Ic command, instead it provides Vorlage:Ic. By default Vorlage:Ic is an alias to Vorlage:Ic, it can be either executed manually by prepending it to a command or it can be invoked for the currently typed command with the keyboard shortcuts Vorlage:Ic or Vorlage:Ic Vorlage:Ic.
Since by default it is just an alias to man, it will only work on external commands. To improve its functionality, so that it works on shell builtins and other shell features, you need to use the Vorlage:Ic function. See Vorlage:Man for more information on the Vorlage:Ic and its assistant functions.
First load the Vorlage:Ic function and then remove the existing Vorlage:Ic alias. For convenience Vorlage:Ic can be aliased to Vorlage:Ic. For example, add following to your Vorlage:Ic:
autoload -Uz run-help (( ${+aliases[run-help]} )) && unalias run-help alias help=run-help
Assistant functions have to be enabled separately:
autoload -Uz run-help-git run-help-ip run-help-openssl run-help-p4 run-help-sudo run-help-svk run-help-svn
For example, Vorlage:Ic command will now open the man page Vorlage:Man instead of Vorlage:Man.
Persistent rehash
Typically, compinit will not automatically find new executables in the Vorlage:Ic. For example, after you install a new package, the files in Vorlage:Ic would not be immediately or automatically included in the completion. Thus, to have these new executables included, one would run:
$ rehash
This 'rehash' can be set to happen automatically.[3] Simply include the following in your Vorlage:Ic:
On-demand rehash
As above, however pacman can be configured with hooks to automatically request a Vorlage:Ic, which does not incur the performance penalty of constant rehashing as above. To enable this, create the Vorlage:Ic directory, and a Vorlage:Ic directory, then create a hook file:
This keeps the modification date of the file Vorlage:Ic consistent with the last time a package was installed, upgraded or removed. Then, Vorlage:Ic must be coaxed into rehashing its own command cache when it goes out of date, by adding to your Vorlage:Ic:
If the Vorlage:Ic hook is triggered before Vorlage:Ic is updated, completion may not work until a new prompt is initiated. Running an empty command, e.g. pressing Vorlage:Ic, should be sufficient.
Alternative on-demand rehash using SIGUSR1
As above, however the hook file looks like this:
The function trap above can be replaced with a list trap Vorlage:Ic. See Vorlage:Man for differences between types of traps.
This method will instantly Vorlage:Ic all Vorlage:Ic instances, removing the need to press enter to trigger Vorlage:Ic.
Bind key to ncurses application
Bind a ncurses application to a keystroke, but it will not accept interaction. Use Vorlage:Ic variable to make it work. The following example lets users open ncmpcpp using Vorlage:Ic:
An alternate method, that will keep everything you entered in the line before calling application:
File manager key binds
Key binds like those used in graphic file managers may come handy. The first comes back in directory history (Vorlage:Ic), the second let the user go to the parent directory (Vorlage:Ic). They also display the directory content.
xterm title
If your terminal emulator supports it, you can set its title from Zsh. This allows dynamically changing the title to display relevant information about the shell state, for example showing the user name and current directory or the currently executing command.
The xterm title is set with the xterm escape sequence Vorlage:IcVorlage:Ic. For example:
$ print -n '\e]2;My xterm title\a'
will set the title to
My xterm title
A simple way to have a dynamic title is to set the title in the Vorlage:Ic and Vorlage:Ic hook functions. See Vorlage:Man for a list of available hook functions and their descriptions.
By using Vorlage:Ic you can additionally take advantage of Zsh's prompt escapes.
Terminal emulator tab title
Some terminal emulators and multiplexers support setting the title of the tab. The escape sequences depend on the terminal:
Terminal | Escape sequences | Description |
---|---|---|
GNU Screen | Vorlage:IcVorlage:Ic | Screen's window title (Vorlage:Ic). |
Konsole | Vorlage:IcVorlage:Ic | Konsole's tab title. |
Shell environment detection
See a repository about shell environment detection for tests to detect the shell environment. This includes login/interactive shell, Xorg session, TTY and SSH session.
/dev/tcp equivalent: ztcp
Use the Vorlage:Ic module:
$ zmodload zsh/net/tcp
You can now establish TCP connections:
$ ztcp example.com 80
More details are available in Vorlage:Man and Vorlage:Man.
Shortcut to exit shell on partial command line
By default, Vorlage:Ic will not close your shell if the command line is filled, this fixes it:
pacman -F "command not found" handler
pacman includes functionality to search for packages containing a file. The following command-not-found handler will use pacman directly to search for matching packages when an unknown command is executed.
For an alternative using pkgfile, see #pkgfile "command not found" handler.
Clear the backbuffer using a key binding
By default, the clear screen keybinding will not clear the backbuffer (the part you need to scroll up for to see it) on most terminal emulators. A possible solution to this problem is the following.
Third-party extensions
Configuration frameworks
Plugin managers
Fish-like syntax highlighting and autosuggestions
Fish provides very powerful shell syntax highlighting and autosuggestions. To use both in Zsh, you can install Vorlage:Pkg, Vorlage:Pkg, and finally source one or both of the provided scripts from your zshrc:
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
pkgfile "command not found" handler
pkgfile includes a Zsh script file that provides a Vorlage:Ic function that will automatically search the pkgfile database when entering an unrecognized command.
You need to source the script to enable it. For example:
For an alternative using pacman's native functionality, see #pacman -F "command not found" handler.
TMP
Die Z-shell (zsh) ist eine mächtige Shell / KommandoZeile, die viele der Features von Bash, ksh und tcsh vereint und durch weitere ergänzt.
Homepage: http://www.zsh.org/ und http://zsh.sunsite.dk/
Lizenz: ZSH-Lizenz
Eine Tabelle mit den Unterschieden der div. Shells findet sich hier.
Tipps & Tricks
Vergleichend zur Bash gibt es einige Interessante Vorteile:
prog1 2>&1 | prog2
kann als
prog1 &| prog2
abgekürzt werden.
Das Patternmatching ist weit aus mächtiger (z.B. {foo,bar}* ergibt alle Dateien, die mit foo oder bar anfangen). Dies kann in der umfangreichen manpage Sammlung nachgelesen werden.
Automatische Korrektur falscher Eingaben
alias -s erweiterung=programm
kann benutzt werden um eine Defaultanwendung zum Öffnen einer Datei mit der entsprechenden Erweiterung festzulegen. Man könnte z.B. alle .c Dateien mit $EDITOR öffnen:
alias -s "c=$EDITOR"
Mini-Howto
Links
ZSH-Wiki: http://zshwiki.org/home/start
"Die Zsh-Liebhaber-Seite"
Why ZSH is cooler than your shell