From 7cf03a1555d46117b5f1a3d0db7c28c02498fcee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sun, 7 Oct 2018 20:03:35 +0200 Subject: Add presentation from LinuxDays 2018 --- 2018-linuxdays/examples/.bashrc | 1 + 2018-linuxdays/examples/.zshrc | 1 + 2018-linuxdays/examples/bash/function | 4 + 2018-linuxdays/examples/bash/mupdf-pdf | 1 + 2018-linuxdays/examples/bash/real | 23 ++ 2018-linuxdays/examples/bash/simple | 1 + 2018-linuxdays/examples/bash/switch | 16 ++ 2018-linuxdays/examples/gitbmerge/_gitbmerge | 23 ++ 2018-linuxdays/examples/gitbmerge/gitbmerge | 20 ++ 2018-linuxdays/examples/zsh/dev | 4 + 2018-linuxdays/examples/zsh/path | 4 + 2018-linuxdays/examples/zsh/real | 38 +++ 2018-linuxdays/examples/zsh/simple | 4 + 2018-linuxdays/examples/zsh/switch | 15 ++ 2018-linuxdays/makefile | 10 + .../naborovy-letak-projekce-rgb-1920x1080.png | Bin 0 -> 8468 bytes 2018-linuxdays/pres.pdf | Bin 0 -> 192992 bytes 2018-linuxdays/pres.tex | 270 +++++++++++++++++++++ 18 files changed, 435 insertions(+) create mode 100644 2018-linuxdays/examples/.bashrc create mode 100644 2018-linuxdays/examples/.zshrc create mode 100644 2018-linuxdays/examples/bash/function create mode 100644 2018-linuxdays/examples/bash/mupdf-pdf create mode 100644 2018-linuxdays/examples/bash/real create mode 100644 2018-linuxdays/examples/bash/simple create mode 100644 2018-linuxdays/examples/bash/switch create mode 100644 2018-linuxdays/examples/gitbmerge/_gitbmerge create mode 100644 2018-linuxdays/examples/gitbmerge/gitbmerge create mode 100644 2018-linuxdays/examples/zsh/dev create mode 100644 2018-linuxdays/examples/zsh/path create mode 100644 2018-linuxdays/examples/zsh/real create mode 100644 2018-linuxdays/examples/zsh/simple create mode 100644 2018-linuxdays/examples/zsh/switch create mode 100644 2018-linuxdays/makefile create mode 100644 2018-linuxdays/naborovy-letak-projekce-rgb-1920x1080.png create mode 100644 2018-linuxdays/pres.pdf create mode 100644 2018-linuxdays/pres.tex (limited to '2018-linuxdays') diff --git a/2018-linuxdays/examples/.bashrc b/2018-linuxdays/examples/.bashrc new file mode 100644 index 0000000..79ff768 --- /dev/null +++ b/2018-linuxdays/examples/.bashrc @@ -0,0 +1 @@ +PS1="\[\e[1;32m\]bash\$\[\e[0m\] " diff --git a/2018-linuxdays/examples/.zshrc b/2018-linuxdays/examples/.zshrc new file mode 100644 index 0000000..c006157 --- /dev/null +++ b/2018-linuxdays/examples/.zshrc @@ -0,0 +1 @@ +PROMPT="%{$fg_bold[green]%}zsh%(!.#.$)%{$reset_color%} " diff --git a/2018-linuxdays/examples/bash/function b/2018-linuxdays/examples/bash/function new file mode 100644 index 0000000..ab6e5da --- /dev/null +++ b/2018-linuxdays/examples/bash/function @@ -0,0 +1,4 @@ +_sterm() { + COMPREPLY+=($(compgen -W "9600 19200 38400 57600 115200" -- "${COMP_WORDS[COMP_CWORD]}")) +} +complete -F _sterm sterm diff --git a/2018-linuxdays/examples/bash/mupdf-pdf b/2018-linuxdays/examples/bash/mupdf-pdf new file mode 100644 index 0000000..3f5c250 --- /dev/null +++ b/2018-linuxdays/examples/bash/mupdf-pdf @@ -0,0 +1 @@ +complete -G \*.pdf mupdf diff --git a/2018-linuxdays/examples/bash/real b/2018-linuxdays/examples/bash/real new file mode 100644 index 0000000..2dd3f36 --- /dev/null +++ b/2018-linuxdays/examples/bash/real @@ -0,0 +1,23 @@ +# Bash completion file for sterm +# vim: ft=sh + +_sterm() { + local cur prev words cword + _init_completion || return + local ops="-h --help -c -d -e -n -r -s -v" + case "$prev" in + -b|-d|-r) + # No completion for these + ;; + -s) + local speeds="0 50 75 110 134 150 200 300 600 1200 1800 2400 4800 9600 19200 38400 57600 115200 230400" + COMPREPLY+=($(compgen -W "${speeds}" -- ${cur})) + ;; + *) + COMPREPLY+=($(compgen -W "${ops}" -- ${cur})) + COMPREPLY+=($(compgen -G "/dev/tty*" -- ${cur})) + ;; + esac +} + +complete -o default -F _sterm sterm diff --git a/2018-linuxdays/examples/bash/simple b/2018-linuxdays/examples/bash/simple new file mode 100644 index 0000000..76b8813 --- /dev/null +++ b/2018-linuxdays/examples/bash/simple @@ -0,0 +1 @@ +complete -W "9600 19200 38400 57600 115200" sterm diff --git a/2018-linuxdays/examples/bash/switch b/2018-linuxdays/examples/bash/switch new file mode 100644 index 0000000..db55dd7 --- /dev/null +++ b/2018-linuxdays/examples/bash/switch @@ -0,0 +1,16 @@ +_sterm() { + local cur prev words cword + _init_completion || return + case "$prev" in + -b|-d|-r) + # No completion for these + ;; + -s) + COMPREPLY=($(compgen -W "9600 19200 38400 57600 115200" -- ${cur})) + ;; + *) + COMPREPLY=($(compgen -W "-s -b -d -r" -- ${cur})) + ;; + esac +} +complete -o default -F _sterm sterm diff --git a/2018-linuxdays/examples/gitbmerge/_gitbmerge b/2018-linuxdays/examples/gitbmerge/_gitbmerge new file mode 100644 index 0000000..49977dc --- /dev/null +++ b/2018-linuxdays/examples/gitbmerge/_gitbmerge @@ -0,0 +1,23 @@ +#compdef gitbmerge +#autoload + +_gitbmerge() { + ((CURRENT > 2)) && return # Complete only single dependency + local GDIR="$(pwd)" + while [ ! -d "$GDIR/.git" ]; do + [ -z "$GDIR" ] && return + GDIR="${GDIR%/*}" + done + GDIR="$GDIR/.git" + [ -f "$GDIR" ] && GDIR="$(cat "$GDIR")" # This just points to some other directory + [ -d "$GDIR/refs/heads" ] || return # No completion if there is no local branch + local branches=() + for B in "$GDIR"/refs/heads/*; do + # TODO skip branch on HEAD + branches+=("${B#$GDIR/refs/heads/}") + done + _describe -t branches 'gitbmerge' branches +} + +_gitbmerge +# vim: ft=zsh diff --git a/2018-linuxdays/examples/gitbmerge/gitbmerge b/2018-linuxdays/examples/gitbmerge/gitbmerge new file mode 100644 index 0000000..bd892b6 --- /dev/null +++ b/2018-linuxdays/examples/gitbmerge/gitbmerge @@ -0,0 +1,20 @@ +_gitbmerge() { + [ $COMP_CWORD -gt 1 ] && return # Complete only single dependency + local cur prev words cword + _init_completion || return + local GDIR="$(pwd)" + while [ ! -d "$GDIR/.git" ]; do + [ -z "$GDIR" ] && return + GDIR="${GDIR%/*}" + done + GDIR="$GDIR/.git" + [ -f "$GDIR" ] && GDIR="$(cat "$GDIR")" # This just points to some other directory + [ -d "$GDIR/refs/heads" ] || return # No completion if there is no local branch + local ops="" + for B in "$GDIR"/refs/heads/*; do + # TODO skip branch on HEAD + ops="$ops ${B#$GDIR/refs/heads/}" + done + COMPREPLY=($(compgen -W "${ops}" -- ${cur})) +} +complete -F _gitbmerge gitbmerge diff --git a/2018-linuxdays/examples/zsh/dev b/2018-linuxdays/examples/zsh/dev new file mode 100644 index 0000000..25de542 --- /dev/null +++ b/2018-linuxdays/examples/zsh/dev @@ -0,0 +1,4 @@ +_sterm() { + _values "tty" /dev/tty* +} +compdef _sterm sterm diff --git a/2018-linuxdays/examples/zsh/path b/2018-linuxdays/examples/zsh/path new file mode 100644 index 0000000..617d47e --- /dev/null +++ b/2018-linuxdays/examples/zsh/path @@ -0,0 +1,4 @@ +_sterm() { + _files +} +compdef _sterm sterm diff --git a/2018-linuxdays/examples/zsh/real b/2018-linuxdays/examples/zsh/real new file mode 100644 index 0000000..7b2dce6 --- /dev/null +++ b/2018-linuxdays/examples/zsh/real @@ -0,0 +1,38 @@ +# vim: ft=zsh +_sterm_baudrate() { + _values "Baudrate" \ + "0" \ + "50" \ + "75" \ + "110" \ + "134" \ + "150" \ + "200" \ + "300" \ + "600" \ + "1200" \ + "1800" \ + "2400" \ + "4800" \ + "9600" \ + "19200" \ + "38400" \ + "57600" \ + "115200" \ + "230400" +} +_sterm() { + _arguments \ + "--help[Output help message]" \ + "-h[Print help text]" \ + "-s[Set baudrate]:baudrate:_sterm_baudrate" \ + "-b[Send break]:break:->ignore" \ + "-c[Enter command mode]" \ + "-d[Make pulse on DTR]:pulse:->ignore" \ + "-r[Make pulse on RTS]:pulse:->ignore" \ + "-e[Ignore '~.' escape sequence]" \ + "-n[Do not switch the device to raw mode]" \ + "-v[Verbose mode]" + [ "$state" = "ignore" ] || _values "tty" /dev/tty* +} +compdef _sterm sterm diff --git a/2018-linuxdays/examples/zsh/simple b/2018-linuxdays/examples/zsh/simple new file mode 100644 index 0000000..b269db3 --- /dev/null +++ b/2018-linuxdays/examples/zsh/simple @@ -0,0 +1,4 @@ +_sterm() { + _values "Baudrate" "9600" "19200" "115200" +} +compdef _sterm sterm diff --git a/2018-linuxdays/examples/zsh/switch b/2018-linuxdays/examples/zsh/switch new file mode 100644 index 0000000..09c9b29 --- /dev/null +++ b/2018-linuxdays/examples/zsh/switch @@ -0,0 +1,15 @@ +_sterm_baudrate() { + _values "Baudrate" "9600" "19200" "115200" +} +_sterm() { + _arguments \ + "-s[Set baudrate]:baudrate:_sterm_baudrate" \ + "-b[Send break]" \ + "-c[Enter command mode]" \ + "-d[Make pulse on DTR]" \ + "-r[Make pulse on RTS]" \ + "-e[Ignore '~.' escape sequence]" \ + "-n[Do not switch the device to raw mode]" \ + "-v[Verbose mode]" +} +compdef _sterm sterm diff --git a/2018-linuxdays/makefile b/2018-linuxdays/makefile new file mode 100644 index 0000000..9ab8f60 --- /dev/null +++ b/2018-linuxdays/makefile @@ -0,0 +1,10 @@ +FILE=pres + +$(FILE).pdf: $(FILE).tex $(patsubst %.svg,%.pdf,$(wildcard *.svg)) + pdflatex -shell-escape $< + +%.pdf: %.svg + inkscape -D -z --file=$< --export-pdf=$@ --export-latex + +clean: + ls | grep -v -E "($(FILE).tex|makefile|scheme|svg|png|eps)$$" | xargs rm -rf diff --git a/2018-linuxdays/naborovy-letak-projekce-rgb-1920x1080.png b/2018-linuxdays/naborovy-letak-projekce-rgb-1920x1080.png new file mode 100644 index 0000000..5c995d9 Binary files /dev/null and b/2018-linuxdays/naborovy-letak-projekce-rgb-1920x1080.png differ diff --git a/2018-linuxdays/pres.pdf b/2018-linuxdays/pres.pdf new file mode 100644 index 0000000..1b792fc Binary files /dev/null and b/2018-linuxdays/pres.pdf differ diff --git a/2018-linuxdays/pres.tex b/2018-linuxdays/pres.tex new file mode 100644 index 0000000..71739f1 --- /dev/null +++ b/2018-linuxdays/pres.tex @@ -0,0 +1,270 @@ +\documentclass[aspectratio=169]{beamer} +\usetheme{metropolis} +\usepackage{lmodern} +\usepackage[czech]{babel} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{graphicx} +\usepackage{wrapfig} +\usepackage{color} +\usepackage{mathtools} +\usepackage{hyperref} +\usepackage{epstopdf} +\usepackage{amsmath} +\usepackage{minted} +\hypersetup{ + colorlinks, + citecolor=black, + filecolor=black, + linkcolor=black, + urlcolor=black +} +\usepackage{pdflscape} + +\title{Jak se píše doplňování v shellu?!} +\author{Kar(t)el Kočí} +\date{7.10.2018} + +\begin{document} + +\frame{\titlepage} + +% nejaky uvodni slide! + +\begin{frame}[fragile] + \frametitle{Příkladový program} + \begin{verbatim} +$ sterm -h +sterm: invalid option -- 'h' +Usage: sterm [options] +Options: + -b send break signal + -c enter command mode + -d[PULSE] make pulse on DTR + -e ignore '~.' escape sequence + -n do not switch the device to raw mode + -r[PULSE] make pulse on RTS + -s + -v verbose mode + +\end{verbatim} +\end{frame} + +\begin{frame}[fragile] + \frametitle{bash: příkaz complete a doplňování} + \begin{verbatim} +complete [-abcdefgjksuv] [-o comp-option] [-DE] [-A action] [-G globpat] + [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] + [-S suffix] name [name …] +complete -pr [-DE] [name …] +\end{verbatim} + \begin{minted}[frame=lines]{shell} +complete -G \*.pdf mupdf +\end{minted} + \begin{minted}[frame=lines]{shell} +complete -W "9600 19200 38400 57600 115200" sterm +\end{minted} +\end{frame} + +\begin{frame}[fragile] + \frametitle{bash: doplňovcí funkce, proměnné a compgen} + \begin{verbatim} +compgen [option] [word] +\end{verbatim} + + \begin{minted}[frame=lines]{shell} +_sterm() { + COMPREPLY+=($(compgen -W "9600 19200 38400 57600 115200" \ + -- "${COMP_WORDS[COMP_CWORD]}")) +} +complete -F _sterm sterm +\end{minted} + + \begin{itemize} + \item COMPREPLY: výsledek doplňování + \item COMP\_LINE: celý dosavadní vstup + \item COMP\_WORDS: pole jednotlivých slov ze vstupu + \item COMP\_CWORD: poslední index do COMP\_WORDS = slovo které doplňujeme + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{bash: \_init\_completion} + \begin{minted}[frame=lines]{shell} +_sterm() { + _init_completion || return + COMPREPLY+=($(compgen -W "9600 19200 38400 57600 115200" \ + -- "$cur")) +} +complete -F _sterm sterm +\end{minted} + + Definuje + \begin{itemize} + \item cur: Aktuálně doplňované slovo + \item prev: Předchozí argument + \item words: Jako COMP\_WORDS z COMP\_LINE + \item cword: To samé jako COMP\_CWORD ale pro words + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{bash: doplňování voleb} + \begin{minted}[frame=lines]{shell} +_sterm() { + local cur prev words cword + _init_completion || return + case "$prev" in + -b|-d|-r) ;; # No completion for these + -s) COMPREPLY=($(compgen -W "9600 19200 38400 57600 115200" \ + -- ${cur})) ;; + *) COMPREPLY=($(compgen -W "-s -b -d -r" -- ${cur})) ;; + esac +} +complete -o default -F _sterm sterm +\end{minted} +\end{frame} + +\begin{frame}[fragile] + \frametitle{bash: doplňování cesty} + \begin{minted}[frame=lines]{shell} +_sterm() { + local cur prev words cword + _init_completion || return + case "$prev" in + -b|-d|-r) ;; # No completion for these + -s) COMPREPLY=($(compgen -W "9600 19200 38400 57600 115200" \ + -- ${cur})) ;; + *) COMPREPLY+=($(compgen -W "-s -b -d -r" -- ${cur})) + COMPREPLY+=($(compgen -G "/dev/tty*" -- ${cur})) ;; + esac +} +complete -o default -F _sterm sterm +\end{minted} +\end{frame} + +\begin{frame}[fragile] + \frametitle{zsh: compdef a \#compdef} + \begin{minted}[frame=lines]{shell} +_sterm() { + _values "Baudrate" "9600" "19200" "115200" +} +compdef _sterm sterm +\end{minted} + + \begin{minted}[frame=lines]{shell} +#compdef foobar +_sterm() { + _values "Baudrate" "9600" "19200" "115200" +} +_sterm +\end{minted} + +\begin{verbatim} +fpath=($(pwd) $fpath) +\end{verbatim} +\end{frame} + +\begin{frame}[fragile] + \frametitle{zsh: doplňování cest} + \begin{minted}[frame=lines]{shell} +_sterm() { + _files +} +compdef _sterm sterm +\end{minted} + + \begin{minted}[frame=lines]{shell} +_sterm() { + _values "tty" /dev/tty* +} +compdef _sterm sterm +\end{minted} +\end{frame} + +\begin{frame}[fragile] + \frametitle{zsh: doplňování voleb} + \begin{minted}[frame=lines]{shell} +_sterm_baudrate() { + _values "Baudrate" "9600" "19200" "115200" +} +_sterm() { + _arguments \ + "-s[Set baudrate]:baudrate:_sterm_baudrate" \ + "-b[Send break]" \ + "-c[Enter command mode]" \ + "-d[Make pulse on DTR]" \ + "-e[Ignore '~.' escape sequence]" +} +compdef _sterm sterm +\end{minted} +\end{frame} + +\begin{frame}[fragile] + \frametitle{zsh: poziční argumenty} + \begin{minted}[frame=lines]{shell} +_sterm_baudrate() { + _values "Baudrate" "9600" "19200" "115200" +} +_sterm() { + _arguments \ + "-s[Set baudrate]:baudrate:_sterm_baudrate" \ + "-b[Send break]" \ + "-c[Enter command mode]" \ + "-d[Make pulse on DTR]" \ + "-e[Ignore '~.' escape sequence]" \ + "1:device:_files" +} +compdef _sterm sterm +\end{minted} +\end{frame} + +\begin{frame}[fragile] + \frametitle{zsh: argumenty a stavy} + \begin{minted}[frame=lines]{shell} +_sterm_baudrate() { + _values "Baudrate" "9600" "19200" "115200" +} +_sterm() { + _arguments \ + "-s[Set baudrate]:baudrate:_sterm_baudrate" \ + "-b[Send break]:break:->ignore" \ + "-c[Enter command mode]" \ + "-d[Make pulse on DTR]:pulse:->ignore" \ + "-e[Ignore '~.' escape sequence]" + [ "$state" = "ignore" ] || _values "tty" /dev/tty* +} +compdef _sterm sterm +\end{minted} +\end{frame} + +\begin{frame}[fragile] + \frametitle{zsh: doplňování bez námahy} + \begin{minted}[frame=lines]{shell} +compdef _gnu_generic ct-ng +\end{minted} +\end{frame} + +\section[Příklady]{} + +\begin{frame} + \frametitle{Zdroje} + \begin{itemize} + \item Bash: man complete (BASH\_BUILTINS) + \item Bash: \url{https://www.gnu.org/software/bash/manual/html\_node/Programmable-Completion.html} + \item Zsh lidsky: \url{http://zsh.sourceforge.net/Doc/Release/Completion-System.html\#Completion-System} + \item Zsh dokumentace: \url{http://zsh.sourceforge.net/Doc/Release/Completion-System.html\#Completion-System} + \end{itemize} +\end{frame} + +\begin{frame} + \includegraphics[width=\textwidth]{naborovy-letak-projekce-rgb-1920x1080.png} +\end{frame} + +\begin{frame} + \Large Děkuji za pozornost. + + \url{git.cynerd.cz} +\end{frame} + +\end{document} -- cgit v1.2.3