\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{JohnMalaperdas (JohnMalaperdas)} \pdfinfo{ /Title (zsh-primer-start-up-files-functions-globbing.pdf) /Creator (Cheatography) /Author (JohnMalaperdas (JohnMalaperdas)) /Subject (Zsh Primer(Start-Up files, Functions, Globbing) Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{39A355} \definecolor{LightBackground}{HTML}{F2F9F4} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Zsh Primer(Start-Up files, Functions, Globbing) Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{JohnMalaperdas (JohnMalaperdas)} via \textcolor{DarkBackground}{\uline{cheatography.com/179057/cs/37295/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}JohnMalaperdas (JohnMalaperdas) \\ \uline{cheatography.com/johnmalaperdas} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 14th March, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{1.24425 cm} x{3.73275 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Options}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{EXTENDEDGLOB} & Enables zsh extra features \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{PUSHDTOHOME} & `pushd` with no arguments redirects to \$HOME \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} NOEQUALS & prepending a command name with `=` replaces the command name with it's full path.\{\{nl\}\}(e.g. `echo =sudo` outputs `/usr/bin/sudo`) \{\{nl\}\}\{\{nl\}\}Can used with `ls -l =(command)` instead of `which command` \tn % Row Count 11 (+ 7) % Row 3 \SetRowColor{white} \seqsplit{NOBANGHISTORY} & Disable ! (exclamation mark) history substitution csh-style. \tn % Row Count 13 (+ 2) % Row 4 \SetRowColor{LightBackground} RECEXACT & TAB-completion allows exact matches to be accepted even though there could be other matches. \tn % Row Count 17 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.94563 cm} x{4.03137 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Globbing Qualifiers}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Example} & {\emph{pattern}}(qualifier) e.g. *(@) \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} / & directories \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} X & executable by others files \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} x & executable by owner \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} W & world writable files \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} w & user writable files \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} R & world readable files/readable by others \tn % Row Count 8 (+ 2) % Row 7 \SetRowColor{white} r & owner readable files \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} U & user-owned files \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} @ & symlinks \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} *(W\textasciicircum{}@) & world-writable but no symlinks \tn % Row Count 12 (+ 1) % Row 11 \SetRowColor{white} *(.) & find all plain files(e.g. no sym links) \tn % Row Count 14 (+ 2) % Row 12 \SetRowColor{LightBackground} *(s) & find setuid files(only user-set) \tn % Row Count 15 (+ 1) % Row 13 \SetRowColor{white} \textless{}-\textgreater{} & filename containing integers \tn % Row Count 16 (+ 1) % Row 14 \SetRowColor{LightBackground} \textless{}100-200\textgreater{} & integer range pattern \tn % Row Count 18 (+ 2) % Row 15 \SetRowColor{white} \seqsplit{*(u1001)} & search for files owned by uid 1001 \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{if echo is used and no results are available then the pattern is echo'ed.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.4839 cm} x{1.4931 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Expansions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{\{\{colspan=2\}\}\{\{ac\}\}{\bf{Arithmetic value Expansion}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{\{\{colspan=2\}\}\${[} ... {]} (e.g. \${[}RANDOM \% 5{]}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{Command Output File}} & =(command) \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{\{\{colspan=2\}\}\{\{ac\}\} Explanation} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{\{\{ac\}\}Outputs the file name holding the command's output. Can be used to edit command output on the spot. \{\{nl\}\}\{\{nl\}\} Different from `\textless{}(..)` which creates a named pipe(FIFO)} \tn % Row Count 8 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Command Line Editing (ZLE)}} \tn % Row 0 \SetRowColor{LightBackground} Zsh supports line edditing in either Emacs or vi mode & type `bindkey -v` for vi mode \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} ZLE negates the need for `fc` & In emacs mode CTRL+P shows previous command\{\{nl\}\}and multi-line commands can be handled. \tn % Row Count 8 (+ 5) % Row 2 \SetRowColor{LightBackground} In Emacs-mode CTRL+R & fwrd-search \tn % Row Count 9 (+ 1) % Row 3 \SetRowColor{white} Link to page & \{\{link="https://zsh.sourceforge.io/Intro/intro\_10.html"\}\}Command Line Editing\{\{/link\}\} \tn % Row Count 14 (+ 5) % Row 4 \SetRowColor{LightBackground} Enable hosts-name completion & hosts=( host\_one.uk host\_two.com ) \tn % Row Count 16 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.9954 cm} x{3.9816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Globbing Basics}} \tn % Row 0 \SetRowColor{LightBackground} \textasciicircum{} & (pattern) negation \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \textless{}x-y\textgreater{} & Integer range(x and/or y are ommitable) e.g. run\textless{}\textgreater{} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{(.c|.h|.m)} & grouping(or) \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} **/ & recursive subdirectory search \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} {\emph{/bar/}} & directory search with partial path \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} *.c\textasciitilde{}bar.c & exclude bar.c \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.9908 cm} x{2.9862 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Functions}} \tn % Row 0 \SetRowColor{LightBackground} Simplest Func def & func\_name () \{ ... \} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} One liners are allowed & func\_name () echo "one liner" \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{\{\{colspan=2\}\}aliases are parsed when function is parsed so...} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{\{\{colspan=2\}\}\textgreater{}func\_name () \{ \{\{nl\}\}\textgreater{} ~~ ypmatch \$1 passwd \{\{nl\}\} \textgreater{}\}\{\{nl\}\}\% alias other\_name=func\_name\{\{nl\}\}\% other\_name\{\{nl\}\}\% func\_output} \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} one liners are also a thing & func\_name () \{ for i; do echo \$i; done \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} Check argument count & if ((\$\# ==0)) \{\{nl\}\} ~~then echo "no args"; \{\{nl\}\} fi \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} Declare integer & integer j=3 \tn % Row Count 15 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Important Links}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{\{\{ac\}\}\{\{colspan=2\}\}\{\{popup="https://zsh.sourceforge.io/Intro/intro\_5.html"\}\}Prompts and Dirs \{\{/popup\}\}} \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Aliases}} \tn % Row 0 \SetRowColor{LightBackground} Define alias & alias mm='some command' \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Aliases can also inlcude pipes & alias m1='cat /etc/passwd | grep mike' \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{\{\{colspan=2\}\} Zsh defines global aliases which can be used in a number of ways.} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Username aliases & alias -g u1='johndoe' u2='mikepreston' u3='johnpreston' \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} Global aliases can contain strings in general & alias -g m2='| grep -f file' \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} Global alias process & \% alias -g PASS='\textless{}(ypcat passwd)'\{\{nl\}\}\% grep pfalstad PASS \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.74195 cm} x{3.23505 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Start-Up Files}} \tn % Row 0 \SetRowColor{LightBackground} ENV Var & ZDOTDIR(If not set HOME is used) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} They are read in order & With some exceptions \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} .zshenv & Won't be read if -f is provided. No output-producing commands. Only env vars and command paths. \tn % Row Count 8 (+ 4) % Row 3 \SetRowColor{white} .zprofile & For ksh fans. Should not be used with .zlogin. But it's up to you. \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} .zshrc & Sourced in interactive shells. Contains aliases, functions, options, key bindings etc. \tn % Row Count 15 (+ 4) % Row 5 \SetRowColor{white} .zlogin & Sourced in login shells. Should contain only relevant commands. Should not be used for aliases or to change the env at all. Should only set terminal type and run series of external commands. \tn % Row Count 23 (+ 8) % Row 6 \SetRowColor{LightBackground} .zlogout & Sourced during log out. Same as above. \tn % Row Count 25 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.74655 cm} x{4.23045 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operators and Vars}} \tn % Row 0 \SetRowColor{LightBackground} \% & Modulus (can be used in scripts). \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \seqsplit{\$RANDOM} & Random Number var (returns a random num each time it is called). \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \$TTY & Current TTY. \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.09034 cm} x{2.88666 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Build-Ins}} \tn % Row 0 \SetRowColor{LightBackground} View function definition & `functions` func\_name \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} View all function definition & `functions` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Autoload functions on startup & autoload func\_name\_1 func\_name\_2 \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{\{\{colspan=2\}\} \{\{ac\}\}Explanation} \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{\{\{colspan=2\}\} FPATH points to dir where files containing function definitions are stored. Each file must have 755 perms and be named afte the function with no extensions. Call `autoload` on .zshrc and then you can call the functions. \{\{nl\}\}\{\{nl\}\} {\bf{Bonus:}} Place \#! on top of function file and you can call the files as scripts too! \textless{}3 This a bit slower however since a separate process is created.} \tn % Row Count 15 (+ 8) % Row 5 \SetRowColor{white} `pushd` & If only two dirs exist in stack, swap their position. \tn % Row Count 18 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.64241 cm} x{3.33459 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{History}} \tn % Row 0 \SetRowColor{LightBackground} `fc` command & Calls default editor(vi by default) to edit history and all.\{\{nl\}\}-{}-It effectively "replays" the last recorded command. \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} `r` command & Re-does the last command replacing string with other strings \tn % Row Count 8 (+ 3) % Row 2 \SetRowColor{LightBackground} `r` command example & \% echo foo\{\{nl\}\}\% r foo=bar\{\{nl\}\}echo bar \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}