\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{myounkin} \pdfinfo{ /Title (fish-shell.pdf) /Creator (Cheatography) /Author (myounkin) /Subject (fish shell 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}{0F420F} \definecolor{LightBackground}{HTML}{F7F9F7} \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{fish shell Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{myounkin} via \textcolor{DarkBackground}{\uline{cheatography.com/20952/cs/3807/}}} \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}myounkin \\ \uline{cheatography.com/myounkin} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 1st April, 2015.\\ Updated 1st June, 2016.\\ 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} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Nicely Formatted Latex Version}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{You can find a better cheat sheet here: \seqsplit{https://github.com/michael-younkin/fish\_shell\_cheatsheet}% Row Count 2 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Fish Syntax}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Variables}} \newline % Row Count 1 (+ 1) Three kinds: universal, global, and local. Universal variables are shared btw. all sessions on the computer per user. Global variables are specific to the current fish session, but they are outside of any block scope. Local variables are specific to a particular block scope and are automatically erased. \newline % Row Count 8 (+ 7) Set a variable as universal with `-U`, as global with `-g`, or local with `-l`. Scoping rules are as follows: \newline % Row Count 11 (+ 3) 1. If a variable is explicitly set to either universal, global or local, that setting will be honored. If a variable of the same name exists in a different scope, that variable will not be changed. \newline % Row Count 15 (+ 4) 2. If a variable is not explicitly set to be either universal, global or local, but has been previously defined, the variable scope is not changed. \newline % Row Count 18 (+ 3) 3. If a variable is not explicitly set to be either universal, global or local and has never before been defined, the variable will be local to the currently executing function. Note that this is different from using the -l or –local flag. If one of those flags is used, the variable will be local to the most inner currently executing block, while without these the variable will be local to the function. If no function is executing, the variable will be global. \newline % Row Count 28 (+ 10) {\bf{Exporting Variables}} \newline % Row Count 29 (+ 1) Export a variable with `-x`. \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Fish Syntax (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Arrays}} \newline % Row Count 1 (+ 1) Store multiple strings in one variable with an array. Access an index: \newline % Row Count 3 (+ 2) `echo \$PATH{[}3{]}` \newline % Row Count 4 (+ 1) Iterate: \newline % Row Count 5 (+ 1) `for i in \$PATH; echo \$i is in the path; end` \newline % Row Count 6 (+ 1) Definition: \newline % Row Count 7 (+ 1) `set smurf blue small` makes an array called smurf containing "blue" and "small". \newline % Row Count 9 (+ 2) Delete an element: \newline % Row Count 10 (+ 1) `set -e smurf{[}1{]}` \newline % Row Count 11 (+ 1) {\bf{Functions}} \newline % Row Count 12 (+ 1) Define a function like so: \newline % Row Count 13 (+ 1) `function ll` \newline % Row Count 14 (+ 1) `ls -l \$argv` \newline % Row Count 15 (+ 1) `end` \newline % Row Count 16 (+ 1) Access arguments using `\$argv`, call the function using `ll`. \newline % Row Count 18 (+ 2) {\bf{Jobs}} \newline % Row Count 19 (+ 1) When you execute a command, it starts a job. You can put a job in the background by adding the `\&` suffix. You can suspend a currently running job using `Ctrl-Z`. You can put the suspended job in the background with `bg`. Finally, you can list all running jobs with `jobs`. \newline % Row Count 25 (+ 6) {\bf{Chaining Commands}} \newline % Row Count 26 (+ 1) Each command ends in either a newline or a semicolon. Chain commands using `command; and command2` or `command; or command2`. `and` and `or` check the previous command's exit status and act accordingly. \newline % Row Count 31 (+ 5) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Fish Syntax (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Aliases}} \newline % Row Count 1 (+ 1) To define an alias, either make a function: \newline % Row Count 2 (+ 1) `function ls` \newline % Row Count 3 (+ 1) ` command ls -{}-color=auto \$argv` \newline % Row Count 4 (+ 1) `end` \newline % Row Count 5 (+ 1) ...or use use `alias NAME DEFINITION` which does this for you.% Row Count 7 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.84149 cm} x{3.13551 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{IO Redirection and Piping}} \tn % Row 0 \SetRowColor{LightBackground} Redirect stdin & `N\textless{}SOURCE\_FILE` (N is optional, default is 0) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Redirect stdout & `N\textgreater{}DESTINATION` (N is optional; default is 1) \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Redirect stderr & `N\textasciicircum{}DESTINATION` (N is optional; default is 2) \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Redirect with appending & `\textgreater{}\textgreater{}` or `\textasciicircum{}\textasciicircum{}` + `DESTINATION\_FILE` \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} Close FD & use `-` as `SOURCE\_FILE` or `DESTINATION` \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} Pipe stdout & `command1 | command2` \tn % Row Count 11 (+ 1) % Row 6 \SetRowColor{LightBackground} Pipe a different FD & `command1 N\textgreater{}| command2` \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Recipes}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{How do I glob for all but one specific file?} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`find -mindepth 1 -maxdepth 1 -type f -a -name "*.jpg"`} \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Expansion}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Quotes and expansion}} \newline % Row Count 1 (+ 1) Without quotes, variables are expanded and characters are escaped. In double quotes, variables are expanded, but no characters are escaped (except for \textbackslash{}", \textbackslash{}\$, and \textbackslash{}\textbackslash{}); in single quotes, everything is literal (except for \textbackslash{}' and \textbackslash{}\textbackslash{}). \newline % Row Count 6 (+ 5) {\bf{Command Expansion}} \newline % Row Count 7 (+ 1) Surround the command in parentheses. If it returns multiple lines, they'll be concatenated with spaces. \newline % Row Count 10 (+ 3) {\bf{Parameter Expansion}} \newline % Row Count 11 (+ 1) Use find for most globbing. Fish supports `?` for any single character (except /), `{\emph{` for any string of characters (except /) (including empty string), and `}}*` for any string of characters, including the empty string and /. \newline % Row Count 16 (+ 5) Files beginning with . are ignored unless a . is the first character of the glob. \newline % Row Count 18 (+ 2) {\bf{Brace Expansion}} \newline % Row Count 19 (+ 1) A comma separated list of characters enclosed in curly braces is expanded to each element of the list is a new parameter: \newline % Row Count 22 (+ 3) `echo input.\{c,h,txt\}` \newline % Row Count 23 (+ 1) `\textgreater{}\textgreater{} input.c input.h input.txt` \newline % Row Count 24 (+ 1) {\bf{Variable Expansion}} \newline % Row Count 25 (+ 1) A `\$` followed by a string of characters is expanded to the value of the environmental variable with that name. Surround the variable with braces to separate it from text. \newline % Row Count 29 (+ 4) {\bf{Process Expansion}} \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Expansion (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`\%` followed by a string is expanded into a PID according to the following rules: \newline % Row Count 2 (+ 2) 1. If the string is `self`, insert the shell's PID \newline % Row Count 4 (+ 2) 2. If the string is the ID of a job, insert the process group ID of the job \newline % Row Count 6 (+ 2) 3. If any child processes match the string, insert their PIDs \newline % Row Count 8 (+ 2) 4. If any processes owned by the user match the string, insert their PIDs \newline % Row Count 10 (+ 2) 5. If none of the above matches, then produce an error \newline % Row Count 12 (+ 2) {\bf{Index Range Expansion}} \newline % Row Count 13 (+ 1) Select a range of values from an array using `..`: \newline % Row Count 15 (+ 2) `echo (seq 10){[}2..5 1..3{]}` \newline % Row Count 16 (+ 1) `\textgreater{}\textgreater{} 2 3 4 5 1 2 3`% Row Count 17 (+ 1) } \tn \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}{Variables}} \tn % Row 0 \SetRowColor{LightBackground} argv & array of arguments to a shell function; only defined in a function call or when fish is invoked to run a script \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \seqsplit{history} & array containing the last commands that were entered \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} HOME & the user's home directory \tn % Row Count 7 (+ 1) % Row 3 \SetRowColor{white} PWD & the current working directory \tn % Row Count 8 (+ 1) % Row 4 \SetRowColor{LightBackground} \seqsplit{status} & the exist status of the last foreground job to exit \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} USER & the current username \tn % Row Count 11 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Command line editor}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Complete current token} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Tab`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Accept autosuggestion} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`at end of line: End/Ctrl-E/Right/Ctrl-F`} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Move to beginning of line} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Home/Ctrl-A`} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Move to end of line} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`End/Ctrl-E`} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Move character-wise} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Left/Ctrl-B or Right/Ctrl-F`} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Move word-wise} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Alt-Left or Alt-Right`} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Move through directory history} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`on empty cmd line: Alt-Left or Alt-Right`} \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Search history for prefix in cmd line} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Up or Down`} \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Search history for token containing token under cursor} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Alt-Up or Alt-Down`} \tn % Row Count 19 (+ 3) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Delete characterwise} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Delete/Ctrl-D (forwards) or Backspace (backwards)`} \tn % Row Count 22 (+ 3) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Delete entire line} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Ctrl-C`} \tn % Row Count 24 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Move contents from cursor to EOL to killring} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Ctrl-K`} \tn % Row Count 26 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Move contents from beginning of line to cursor to killring} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Ctrl-U`} \tn % Row Count 29 (+ 3) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Repaint screen} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Ctrl-L`} \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Command line editor (cont)}} \tn % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Move preview word to killring} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Ctrl-W`} \tn % Row Count 2 (+ 2) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Move next word to killring} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Alt-D`} \tn % Row Count 4 (+ 2) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Print description of cmd under cursor} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Alt-W`} \tn % Row Count 6 (+ 2) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{List contents of current directory or directory under cursor} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Alt-L`} \tn % Row Count 9 (+ 3) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Add '|less;' to end of job under cursor} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Alt-P`} \tn % Row Count 11 (+ 2) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Capitalize current word} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Alt-C`} \tn % Row Count 13 (+ 2) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Make current word uppercase} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Alt-U`} \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{These shortcuts can be changed using the `bind` built-in command.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}