summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/shdoc
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2016-05-02 23:56:09 +0000
committerKarl Berry <karl@freefriends.org>2016-05-02 23:56:09 +0000
commit5feb9fd1afef1dc215799e36d9a96ef2f4ed47ac (patch)
tree25b3d1656a239bc6784ccea166f8c602c3775ac6 /Master/texmf-dist/source/latex/shdoc
parent18e1e0676806d75d5accc5104cc3ab13865bda21 (diff)
shdoc (29apr16)
git-svn-id: svn://tug.org/texlive/trunk@40848 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/shdoc')
-rw-r--r--Master/texmf-dist/source/latex/shdoc/shdoc.dtx1197
-rw-r--r--Master/texmf-dist/source/latex/shdoc/shdoc.ins1
2 files changed, 883 insertions, 315 deletions
diff --git a/Master/texmf-dist/source/latex/shdoc/shdoc.dtx b/Master/texmf-dist/source/latex/shdoc/shdoc.dtx
index 30b64fcaac8..a9809031517 100644
--- a/Master/texmf-dist/source/latex/shdoc/shdoc.dtx
+++ b/Master/texmf-dist/source/latex/shdoc/shdoc.dtx
@@ -18,12 +18,16 @@
%
%\iffalse
%<package>\NeedsTeXFormat{LaTeX2e}
-%<package>\ProvidesPackage{shdoc}[2015/05/24 v2.0 Package for documenting terminal operations]
+%<package>\ProvidesPackage{shdoc}[2015/05/24 v2.1 Package for documenting shell operations]
%<package>\RequirePackage[dvipsnames]{xcolor}
%<package>\RequirePackage{float}
%<package>\RequirePackage{caption}
%<package>\RequirePackage{mdframed}
%<package>\RequirePackage{kvoptions}
+%<package>\RequirePackage{relsize}
+%<package>\RequirePackage{stringstrings}
+%<package>\RequirePackage{ifthen}
+%<package>\makeatletter
%
%
%<*internal>
@@ -48,7 +52,7 @@
environment that can be used to document operations or command
executions of a terminal session on a shell.
- The current version of the package is v2.0.
+ The current version of the package is v2.1.
To create the package (*.sty) from source open a command line prompt,
change to the package directory and type
@@ -58,7 +62,29 @@
Afterwards you can generate the package documentation by typing
(pdf)latex shdoc.dtx
+
+ Be aware, that the shdoc package is using Unix/Linux specific shell
+ commands within the documentation. Thus, you may not be able to build
+ the documentation on your system. For security reasons, make sure that
+ you do not execute unknown shell scripts -- that are distributed with this
+ or other packages -- blindly. Further, you will need to enable `write18'
+ to build the documentation successfully.
%</readme>
+%This is an example file that is needed to compile the manual
+%The right file is generated by the docstrip utility
+%<*avr>
+
+avrdude: AVR device initialized and ready to accept instructions
+
+Reading | ################################################## | 100% 0.01s
+
+avrdude: Device signature = 0x1e910b
+
+avrdude: safemode: Fuses OK (H:FF, E:DF, L:E2)
+
+avrdude done. Thank you.
+
+%</avr>
%
%<*internal>
\fi
@@ -71,12 +97,12 @@
\usepackage{shdoc}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
-%\usepackage[DIV=9]{typearea}
\usepackage{graphicx}
+\usepackage{tikz}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
-\usepackage[colorlinks=true,linkcolor=black,urlcolor=blue]{hyperref}
+\usepackage[colorlinks=true,linkcolor=black,urlcolor=blue,bookmarks=true]{hyperref}
\begin{document}
\DocInput{shdoc.dtx}
\end{document}
@@ -89,12 +115,13 @@
% \changes{v1.1}{2015/04/06}{Formatting changes}
% \changes{v1.2}{2015/05/20}{Background color changed globally}
% \changes{v2.0}{2015/08/10}{Added package options as kv-list: colors and symbols}
+% \changes{v2.1}{2016/04/08}{Reworked the paragraph settings better typesetting of the output, font size is variable, added a whole bunch of new macros for automatic shell-command execution}
%
% \GetFileInfo{\jobname.sty}
%
% \DoNotIndex{}
%
-%
+%\def\dfcol#1{\raisebox{-5pt}{\tikz{\node[rectangle,draw=#1,fill=#1]{#1};}}}
%
%\title{The \textit{shdoc} package -- Manual for version~\fileversion, \filedate}
%\author{Simon Michael Laube \\ \texttt{simon.laube@gmx.at}}
@@ -117,164 +144,145 @@
% while offering a wide range of personalization options.
% \end{abstract}
%
-%\tableofcontents\newpage
+%\tableofcontents
%
% \section{Introduction}
%
% Many people who use \LaTeX\ and do a bit of coding in other languages have used
% \LaTeX's \textit{listings} package at least once. However, when me and my colleague
% wrote the documentation of our diploma project in 2015, we stumbled across a ``problem''\footnote{obviously it's not a
-% problem, but we wanted something more colourful} with
+% real problem, but we wanted something more shell-specific} with
% \textit{listings}. A lot of command line scripting had to be done for our project to configure a Raspberry Pi B+ and those
% actions needed to be documented. \textit{listings} seemed to be the wrong package to look for, so we wrote our own.
% At first there were few small macros that we referred to as \textit{bashdoc} -- this was
-% version 1.0. Later the macros got a bit more complex and we threw away the \textit{ba} part of \textit{bashdoc},
+% version 1.0. Later the macros got a bit more complex and we simply threw away the \textit{ba} part of \textit{bashdoc},
% that's how the \textit{shdoc} package was born. The basic idea somehow
-% stayed the same since the very first draft, but the package is much more applicable now, although there are still many
-% things missing that could make the package better.\par
+% stayed the same since the very first draft, but the package is much more applicable now.\par
%
% I hope that \textit{shdoc} fits your application as it fitted ours. If there are any serious problems, feel free to
-% send me an email\footnote{Please do not send spam mails of any kind. Plain text email format would be a great idea, too.}.
-% Moreover, I do not guarantee full compatibility with other packages. The package is distributed under the \LaTeX\ Project
+% send me an email\footnote{Please do not send spam mails of any kind. Plain text email format would be appreciated}.
+% Moreover, I do not guarantee full compatibility with other packages and different operating systems.
+% The package is distributed under the \LaTeX\ Project
% Public License version 1.3.\par
%
+% \section{Acknowledgement}
%
+% At this point I would like to thank \textit{Timm Severin} for his active feedback concerning problems and
+% ideas about the package.
+% He pointed out a major bug of version v2.0 and submitted the draft source for some of the new features in version v2.1.
+% Thank you very much!
+% \newpage
% \section{User commands}
% \textit{shdoc} implements user commands that allow one to typeset the content/commands
% of a command line session appropriately. Further there are macros to
-% create and modify styles and appearance of the final output.\par
+% create and modify styles and appearance of the final output, as well as automated functions
+% that let the user execute commands via \textit{shdoc} and typeset their output immediately.\par
+%
% \subsection{Package inclusion and options}
% Just like every \LaTeX\ package, \textit{shdoc} can be included using the standard
% \cmd{\usepackage} command:
% \begin{quote}
% \cmd{\usepackage\oarg{options}\{shdoc\}}
% \end{quote}
+%
% Since version 2.0 \textit{shdoc} supports several package options to make the environment more
% adjustable for users. The available options are described in detail in the following
% sections.
-% \subsubsection{Color options}\label{subsubsec:coloropts}
-% The shbox environment uses plenty of \textit{different} colors, which can be adjusted through
-% optional package arguments. Table~\ref{tab:color_var} shows the adjustable colors.
-% Every color is specified using a key-value element as an optional package argument.
-% If no argument is used for a specific color the default value is used.
-%
-% \DescribeMacro{backgroundcolor}
-% The background color specifies the color of the background of the ``shell'' in the
-% shbox environment -- see section~\ref{sec:examples}. The default value is set to
-% \begin{quote}
-% \verb|backgroundcolor=gray!70|
-% \end{quote}
-% to imitate the look of a shell and offer a not to dark, printable
-% background at the same time.\pagebreak[4]
%
-% \DescribeMacro{usernamecolor}
-% The username color specifies the color of the current user's name within
-% the shbox environment. The default value for this color is
-% \begin{quote}
-% \verb|usernamecolor=green!80!yellow|
-% \end{quote}
-%
-% \DescribeMacro{machinenamecolor}
-% The machine-name color specifies the color of the machine's name within
-% the shbox environment. The default value for this color is the
-% same as the username color.
-%
-% \DescribeMacro{indicatorcolor}
-% The indicator separates the displayed path, user and machine values from the user input.
-% It's default color is
-% \begin{quote}
-% \verb|indicatorcolor=RoyalBlue|
-% \end{quote}
-%
-% \DescribeMacro{separatorcolor}
-% The separator separates the username from the machine-name. Its default color is the
-% same as the username color, namely
-% \begin{quote}
-% \verb|separatorcolor=green!80!yellow|
-% \end{quote}
+%
+% \subsection{Color and style management}\label{subsec:style}
+% The shbox environment uses plenty of \textit{different} colors and symbols, which can be adjusted through
+% optional package arguments or macros within the document. Thus, you can either specify the color at the package
+% inclusion in the preamble or just before your session in the document.
+%
+% \DescribeMacro{\shchange}
+% To modify the appearance of shell sessions within your document one can use three different
+% commands. The essential macro is \cmd{\shchange\marg{<name>} \marg{<new value>}}, which lets you specify a new value for every
+% existing package option. Basically this command is all you need, but it is not recommended to use it for style changes.
+% As mentioned there are two more macros, namely \cmd{\shchangecolor} and
+% \cmd{\shchangesymbol}. The reason you should use these two for style changes is
+% simply because of enhanced readability of your code. Anyone who reads your source will be able to tell what
+% change you made at the first glimpse -- that is mainly important when defining presets,
+% see section~\ref{subsubsec:presets}. However, the commands all work the same as the latter
+% two are exact copies
+% of \cmd{\shchange}. Here are some examples of style changes:%
+% \begin{verbatim}
+% \usepackage[backgroundcolor=white,indicatorsymbol=$+$]{shdoc}
+% or
+% \shchangecolor{backgroundcolor}{white}
+% \shchangesymbol{indicatorsymbol}{$+$}
+%
+%
+% \usepackage[usernamecolor=blue!70]{shdoc}
+% or
+% \shchange{usernamecolor}{blue!70} % works, but isn't recommended
+% \end{verbatim}
+%
+% \noindent Be aware that specifying style settings as a package option always sets the style for the whole
+% document, unless the settings are changed again via \cmd{\shchange}.
+%
+%
+% \subsubsection{Colors}
+% Table~\ref{tab:color_var} shows the package-specific
+% names of all the colors, their default value and where they are used. Every color is specified using a key-value
+% element as an optional package argument. If no argument is given for a specific color the default value is used.
+%
%
-% \begin{table}[tbh!]
-% \centering
-% \begin{tabular}{ll}
-% Name & Description \\\hline
-% backgroundcolor & color of the environment background\\
-% usernamecolor & color of the username\\
-% machinenamecolor & color of the machine-name\\
-% indicatorcolor & color of the indicator symbol\\
-% separatorcolor & color of the user-machine separator symbol\\
-% pathcolor & the color of the current path\\
-% optioncolor & color of the little option box\\
-% textcolor & color of the rest of the text\\
-% \end{tabular}
-% \caption{Adjustable colors of the shbox environment and their description}
-% \label{tab:color_var}
-% \end{table}
-%
-% \DescribeMacro{pathcolor}
-% The pathcolor specifies the color of the current path and is by default
-% the same as the indicator color:
-% \begin{quote}
-% \verb|pathcolor=RoyalBlue|
-% \end{quote}
-%
-% \DescribeMacro{optioncolor}
-% The option color specifies the background color of the little optionbox
-% in the \cmd{\shoutput} command. The boxes' default color is
-% \begin{quote}
-% \verb|optioncolor=white!60!gray|
-% \end{quote}
-%
-% \DescribeMacro{textcolor}
-% The text color simply specifies the color of the whole rest of all
-% text inside the shbox environment. Its default value is \textit{black}.
-%
-% \subsubsection{Symbol options}
-% In total, only two symbols can be changed in the \textit{shdoc} package.
-% Table~\ref{tab:symbol_var} shows their name and description. Just as the
-% colors, every symbol is changed using a key-value element as an optional
-% package argument.
-%
-% \DescribeMacro{indicatorsymbol}
-% The indicator symbol separates the displayed username, machine-name and path values from
-% the user input. Its default value is
-%
-% \begin{quote}
-% \verb|indicatorsymbol=\$|
-% \end{quote}
-% \pagebreak[4]
-% \DescribeMacro{separatorsymbol}
-% The separator symbol separates the username from the machine-name. Its default value is
+% \begin{table}[tbh!]
+% \centering\small
+% \begin{tabular}{lll}
+% Name & Description & Default color \\\hline
+% backgroundcolor & color of the environment background & \dfcol{gray!70}\\
+% usernamecolor & color of the username&\dfcol{green!80!yellow}\\
+% machinenamecolor & color of the machine-name&\dfcol{green!80!yellow}\\
+% indicatorcolor & color of the indicator symbol&\dfcol{RoyalBlue}\\
+% separatorcolor & color of the user-machine separator symbol&\dfcol{green!80!yellow}\\
+% pathcolor & color of the current path& \dfcol{RoyalBlue}\\
+% optioncolor & color of the little option box&\dfcol{white!60!gray}\\
+% textcolor & color of the rest of the text& \dfcol{black}\\
+% \end{tabular}
+% \caption{Adjustable colors of the shbox environment}
+% \label{tab:color_var}
+% \end{table}
+%
+%
+% \subsubsection{Symbols}
+% In total, only two symbols can be changed in the \textit{shdoc} package.
+% Table~\ref{tab:symbol_var} shows their name, default value and description. Just as the
+% colors, every symbol is changed using a key-value element as an optional
+% package argument. If no arguments are given, the default values are used.
%
-% \begin{quote}
-% \verb|separatorsymbol=@|
-% \end{quote}
-% Please pay attention, that the @'s \textit{catcode} is changed to letter internally. Thus,
-% the @ needs to be specified without a \textbackslash.
%
% \begin{table}[tbh!]
-% \centering
-% \begin{tabular}{ll}
-% Name & Description \\\hline
-% indicatorsymbol & separates user input and displayed path\\
-% separatorsymbol & separates user- and machine-name\\
+% \centering\small
+% \begin{tabular}{llc}
+% Name & Description & Default symbol \\\hline
+% indicatorsymbol & separates user input and displayed path & \$\\
+% separatorsymbol & separates user- and machine-name& @\\
% \end{tabular}
-% \caption{Adjustable symbols of the shbox environment and their description}
+% \caption{Adjustable symbols of the shbox environment}
% \label{tab:symbol_var}
% \end{table}
+% \noindent Please pay attention, that the @'s \textit{catcode} is changed to letter internally. Thus,
+% you can use @ directly:
+% \begin{verbatim}
+% \shchangesymbol{separatorsymbol}{@}
+% \end{verbatim}
%
-% \subsubsection{Presets}
+%
+% \subsubsection{Appearance and presets}\label{subsubsec:presets}
% As described above, \textit{shdoc} has some settings that can be
% changed by the user. Some setting values have been tested and
% stored as a preset that a user can easily load. Further, users are able to
% create their own presets via built-in commands.\par
%
% \DescribeMacro{\shpreset}
-% One can easily load a preset with \cmd{\shpreset} by using the preset's name
+% One can easily load a preset with \cmd{\shpreset\marg{<name>}} by using the preset's name
% as an argument to that macro. When a preset has been loaded it is valid for every
-% new \textit{shbox} environment afterwards, until the \cmd{\shpreset} macro is called
+% new \textit{shbox} environment afterwards, until the \cmd{\shpreset} macro is invoked
% again.\par
% \DescribeMacro{\shpresetdef} Most of the time, users might want to create their own styles,
-% which can be achieved by defining a new preset via \cmd{\shpresetdef}. The command has two
+% which can be achieved by defining a new preset via \cmd{\shpresetdef\marg{<name>}\marg{<def>}}. The command has two
% mandatory arguments: The first one is the desired preset-name and the second one is the
% preset definition. For example one can use:
% \begin{quote}
@@ -285,17 +293,11 @@
% \verb|\shpreset{useless}|
% \end{quote}
% \par
-% To make creating presets easier there are two additional commands that simply
-% change the according value within the package.
-% \DescribeMacro{\shchangecolor}
-% If a user wants to change a specific color, he has to use \cmd{\shchangecolor}, where
-% the first argument is the colors name -- see section~\ref{subsubsec:coloropts} -- and the
-% second one is the desired color (according to the \textit{xcolor} syntax).\par
-%
-% \DescribeMacro{\shchangesymbol}
-% The same rules apply to the \cmd{\shchangesymbol} command that implements the same function
-% for the according symbols. For further information about preset definitions, please have a look
-% at section~\ref{subsec:presetdef}.\par
+% \noindent A preset definition basically exists of multiple style changes, as described at the beginning of
+% section~\ref{subsec:style}. For further information about preset definitions, please have a look
+% at all the examples in section~\ref{subsubsec:presetdef} and section~\ref{subsec:presetdef}.
+% Please also note that every new preset definition
+% is based on the default preset, as \cmd{\shpresetdef} invokes \cmd{\shpreset\{default\}} prior to the definition.\par
%
%
% Several presets have been defined by the author and are included in the \textit{shdoc} package.
@@ -321,14 +323,6 @@
% boxes, black text, darker gray user- and machine-name and a dark gray path value.
% \end{description}
%
-% \subsection{Name variables}
-% For international compatibility the \textit{shdoc} packages implements two commands to make the list and
-% caption name easily accessible. \par
-% \DescribeMacro{\shlistname} One can use \cmd{\shlistname} to change the title of the sessions listThe default
-% value is ``\cmd{\shlistname}\{List of Terminal Sessions\}''.\par
-%
-% \DescribeMacro{\shfloatname} In the same manner as described above, the float caption that's displayed below
-% each float could be changed. Its default value is ``\cmd{\shfloatname}\{Terminal Session\}''.
%
% \subsection{The environment}\label{subsec:environment}
% Basically a complete terminal session consists out of two environments that contain the
@@ -350,21 +344,198 @@
% \end{shbox}
% \end{sh}
% \end{verbatim}
+%
+% \subsubsection{Metadata}
% \DescribeMacro{\shuser} At least once before an occurrence of a \cmd{\shbox},
-% the user- and machine-name must be specified. \DescribeMacro{\shmachine}
+% the user- and machine-name should be specified. \DescribeMacro{\shmachine}
% They are set globally and thus are valid for
-% every \cmd{\shbox} that follows the macro call.\par
+% every \cmd{\shbox} that follows the macro call. If no user and machine values are
+% specified, the defaults user:\texttt{root} and machine:\texttt{linux} are used.\par
%
+% \subsubsection{Shell input \& path handling}\label{subsubsec:in_and_path}
% \DescribeMacro{\shline}
-% Within the \cmd{\shbox} there are only two valid commands, namely \cmd{\shline}, which
+% Within the \cmd{\shbox} there are only two valid commands^^A
+% \footnote{Actually that's not true, but as you will probably know from the \TeX book, authors need to lie from time to time, to make things a bit easier.}, namely \cmd{\shline}, which
+% is basically the users' input, the executed command or an arbitrary line; and \cmd{\shoutput},
+% which is ment to be the machine output.\cmd{\shline} has two mandatory arguments, where the first one is the path value
+% and the second one is the command that's
+% about to be run.\par
+% There are several possibilities to handle the path value. First of all, you can leave the first argument empty,
+% which will force \cmd{\shline} to print the \textit{default path}, namely \textasciitilde.
+% \DescribeMacro{defaultpath}
+% As one may want to
+% have a different default path, it can be changed by either passing a key-value element of the form
+% \verb|defaultpath=<value>| as an optional argument to the package; or using the already mentioned
+% \cmd{\shchange\marg{defaultpath}\marg{<value>}} command.
+% \DescribeMacro{\shpath} Second, one could use \cmd{\shpath} to automatically get the absolute path
+% of the current \verb|*.tex| file. Please note that this command does not affect the default path. If you
+% would like to set the default path to the current path of your file, use
+% \cmd{\shchange\{defaultpath\}\{\cmd{\shpath}\}}. At last, if you just want to use another path for one
+% line, just use the first argument of \cmd{\shline} to do so. For example:
+% \begin{verbatim}
+% \shline{/home/user/Desktop}{exit}
+% \end{verbatim}
+%
+% \subsubsection{Shell output}
% \DescribeMacro{\shoutput}
-% is basically the users' input, and \cmd{\shoutput}, which is ment to be the machine output.
-% \cmd{\shline} has two mandatory arguments, where the first one is the path value\footnote{a smarter solution
-% for the path value is currently in work as a draft.} and the second one is the command that's
-% about to be run.
-% \cmd{\shoutput} implements two mandatory macros, too. Here, the first argument is an arbitrary option, which
-% could also be left blank, when no option box is wanted. The second argument is for the commands' output.
+% \cmd{\shoutput} implements two mandatory macros, too. Here, the first argument is ment for the options of a shell command.
+% For example if you typeset the \verb|--help| output of a command, there may be one or more options like
+% \verb|-c|, \verb|-a| and \verb|-T|. These can be typeset within a fancy optionbox by using the first argument
+% of \cmd{\shoutput}. The second argument is ment for any text and is printed without any special formatting.
+% However, it is not mandatory and sometimes not even useful to use the optionbox. In this case you can leave the
+% first argument empty, which forces the macro to suppress the complete optionbox including the additional indent it
+% would otherwise cause.
%
+% \subsubsection{Name variables}
+% For international compatibility the \textit{shdoc} packages implements two commands to make the list and
+% caption name of the float easily accessible. \par
+% \DescribeMacro{\shlistname} One can use \cmd{\shlistname} to change the title of the sessions list. The default
+% value is ``\cmd{\shlistname}\{List of Terminal Sessions\}''.\par
+%
+% \DescribeMacro{\shfloatname} In the same manner as described above, the float caption that's displayed below
+% each float could be changed. Its default value is ``\cmd{\shfloatname}\{Terminal Session\}''.
+%
+%
+% \subsection{Automatic command execution and typesetting}
+% Starting with version v2.1, \textit{shdoc} includes macros that let the user execute shell commands
+% from within the \LaTeX{} file and typeset their output immediately. As the whole package is intended to
+% be used on a Linux/Unix shell it uses dedicated commands that will not work on other shells\footnote{The
+% manual mode, however, will always work the same.}.\par
+% Note that all the following macros in this subsection are valid within the \cmd{\sh} float environment,
+% but not within \cmd{\shbox}, as each of them produces its own, enclosed shbox. In other words, each
+% automatic inclusion macro produces a standalone shbox. The necessary float environment, caption and label
+% stay the same.
+%
+% \subsubsection{Warning}
+% Caution! In order to make the following features work, you need to allow \TeX{} to use the \cmd{\write18}
+% instruction. For \TeX Live this can be done by using the \verb|--shell-escape| option on the shell. It is
+% not recommended to use this option permanently, as you could unconciously execute harmful \LaTeX{} code.
+% Further, only execute \LaTeX{} and shell scripts that you trust, as nobody will take responsibility for
+% their effects.
+%
+% \subsubsection{Read saved command outputs from a file}
+% \DescribeMacro{\shread} The easiest way to include shell output into your \LaTeX{} file automatically
+% is by redirecting the output stream of the shell command to a file, which is then read by \textit{shdoc}.
+% For example:
+% \begin{verbatim}
+% root@linux ~ $ xsensors -help > xsensors-out.save
+% \end{verbatim}
+% The resulting file will look like this:
+% \begin{mdframed}[linecolor=black]
+% \begin{verbatim}
+%
+%Usage: xsensors [options]
+%
+%Options:
+%--------
+%
+%-f Display all temperatures in Fahrenheit.
+%-h Display this help text and exit.
+%-c filename Specify the libsensors configuration file.
+%-i filename Specify the image file to use as a theme.
+%-t time Specify the update time in number of seconds.
+% Set this to a negative number for no update.
+% Don't set this to 0.
+%-v Display version number.
+%
+% \end{verbatim}
+% \end{mdframed}
+% \hfill \raisebox{6pt}{\texttt{\scriptsize xsensors-out.save}}
+%
+%\noindent After saving the file, \cmd{\shread} is used to include it into your document.
+% The macro has two mandatory arguments: The first one is the initial command, as \textit{shdoc}
+% has no way to find out the matching input command to your output file, whereas the second one
+% is the path and name of the file you want to read. Thus, to include the example file from above
+% one would write:
+% \begin{verbatim}
+% \shread{xsensors -help}{xsensors-out.save}
+% \end{verbatim}
+%
+% While reading command output in that manner, the user still has to take care of at least two steps,
+% but it can be very useful if the output of a command is used elsewhere, too. Furthermore, this is still
+% the fastest way to include command output as all the other methods slow down the \LaTeX{} build of your document.
+%
+% \subsubsection{Run commands and typeset their output}
+% \DescribeMacro{\shrun} Nevertheless, two steps are still one too much. Thus, \cmd{\shrun} lets
+% the user run a shell command from within the document and typesets its output automatically. The macro has one
+% mandatory argument, namely the command that should be passed to the shell. Once again make sure to have \cmd{\write18}
+% enabled:
+% \begin{verbatim}
+% \shrun{xsensors -help}
+% \end{verbatim}
+%
+% \noindent The \cmd{\shrun} macro takes the shell command, passes it to the system shell and captures its
+% output in a file called \texttt{shrun.tmp}. This same file is used for every occuring \cmd{\shrun},
+% so its content is highly temporary. However, the file will not be deleted from your working directory,
+% unless you tell \textit{shdoc} to do so -- see section~\ref{subsubsec:clearfiles}.
+% Note that the macro will also automatically redirect the \texttt{stderr} stream to the output
+% stream, so errors should be visible within your document -- see session~\ref{sh:error} for an example.
+%
+%
+% \subsubsection{Autoread and typeset a file (experimental)}\label{subsubsec:autoread}
+% The results of \cmd{\shread} are normally nice, but the macro does not support
+% the optionbox of \cmd{\shoutput}. That's because files are read line by line, where
+% each line can be seen as a string that is directly passed to \cmd{\shoutput} as the second argument.
+% Further, it is very difficult to isolate the shell options (\verb|-c|, \verb|-U|,\dots) from the
+% line of text. That's mainly because every single program formats its output in a slightly different way.
+% Supporting every programs formatting would nearly be impossible, so another approach had to be taken by
+% the author; and that was string manipulation.\par
+% \DescribeMacro{\shautoread} The result of fooling around with various manipulation methods is a
+% macro called \cmd{\shautoread}, which is basically \cmd{\shread} except for a few additions that are
+% provided by the \textit{stringstrings} package.\par
+% Just as \cmd{\shread}, the \cmd{\shautoread} macro accepts two mandatory arguments that are treated in
+% the same way as before. The real magic happens when \TeX{} is reading the given file line by line.
+% Each line is stored in an internal macro, which is subsequently accessed by \textit{stringstrings}, extracting the first word of
+% the line. To find out if the first word is an option or not, \textit{stringstrings} then searches this word for the '-' character.
+% If the word contains the '-' exactly once\footnote{I know that there are hundrets of options like \texttt{-show-all} or options with two leading dashes, like \texttt{-\hbox{}-shell-escape}, but to differ between all these options would again be nearly impossible.},
+% the word is treated as \textit{the option} an is thus passed to
+% \cmd{\shoutput} as the first argument. The rest of the line gets printed as text i.e. the second argument.\par
+% To this day, the autoread feature is experimental. It may mess up with the output of some programs and you maybe
+% not liking it at all. That's fine, because the macro is simply ment to be worth a try, if you are looking for an opportunity
+% to enhance the appearance of your output once more.\par\medskip
+% \noindent\textcolor{red}{Warning:} Using the \cmd{\shautoread} function has a huge impact on your
+% \LaTeX{} build time, as \textit{stringstrings} somehow has a lot of things to do when manipulating
+% strings. Expect at least one minute per autoread, depending on the length of the output and your system performance.
+%
+%
+% \subsubsection{Run and autoread a command (experimental)}
+% \DescribeMacro{\shautorun} Just like \cmd{\shrun}, \cmd{\shautorun} lets the user
+% execute a shell command and typeset its output. The only difference is that \cmd{\shautorun}
+% reads the temporary file via \cmd{\shautoread} -- described in section~\ref{subsubsec:autoread}
+%
+% \subsubsection{Autopath \& autoformat (experimental)}
+% \paragraph{Autopath}\DescribeMacro{\shautopath} In section~\ref{subsubsec:in_and_path}
+% we learned that \cmd{\shpath} can be used to get the current
+% directory we are working in. To automate things even more both, \cmd{\shread} and \cmd{\shautoread} can
+% use the current path by invoking \cmd{\shpath} on their own. As this functionality is turned off by default, you
+% can enable it by typing:
+% \begin{verbatim}
+% \shautopath{true}
+% \end{verbatim}
+% \noindent You can also turn it off again by passing \texttt{'false'} to this macro. Passing any other text may not result
+% in a warning or error, but will be visible in the log file.\par
+%
+% \paragraph{Autoformat}\DescribeMacro{\shautopath} Another automation feature -- and
+% probably the most useful one -- is the autoformat script that
+% is distributed with the package. As is, the script uses the \texttt{'sed'} stream editor to modify the temporary
+% file \texttt{shrun.tmp} and stores the result in \texttt{shrun-formatted.tmp}. Thus, the script can be used by
+% both, \cmd{\shrun} and \cmd{\shautorun} to improve the visual quality of your document. This feature is
+% turned off by default. You can enable it by typing:
+% \begin{verbatim}
+% \shautoformat{true}
+% \end{verbatim}
+% \noindent However, \textcolor{red}{before doing so}, you should open the script \texttt{shreformat.sh}
+% with your favourite text
+% editor and double check that it won't \textit{harm your computer}\footnote{You shouldn't use unknown scripts blindly}!
+% You can also modify it according to your
+% needs in order to get even better results.
+%
+% \subsubsection{Clear temporary files}\label{subsubsec:clearfiles}
+% \DescribeMacro{\shclearfiles} Most of the time you may want to delete the three temporary files
+% \texttt{shrun.tmp}, \texttt{shpath.tmp} and \texttt{shrun-formatted.tmp}
+% at the end of your \LaTeX{} build, as they are not really useful for anything
+% but the \textit{shdoc} package. One can do so by using \cmd{\shclearfiles} at an
+% appropriate point within the document, e.g. before the end.\newpage
%
% \section{Examples}\label{sec:examples}
% \subsection{Various examples}
@@ -373,25 +544,24 @@
%\begin{sh}
% \begin{verbatim}
% \shpreset{blackwhite}
- \begin{sh}
- \shuser{simon}
- \shmachine{linuxmint}
- \begin{shbox}
- \shline{}{cd Desktop/}
- \shline{Desktop/}{xsensors -help}
- \shoutput{}{}
- \shoutput{}{\underline{Options:}}
- \shoutput{}{}
- \shoutput{-f} {Display all temperatures in Fahrenheit.}
- \shoutput{-h} {Display this help text and exit.}
- \shoutput{-c} {+filename Specify the libsensors configuration file.}
- \shoutput{-i} {+filename Specify the image file to use as a theme.}
- \shoutput{-t} {+time Specify the update time in number of seconds.}
- \shoutput{-v} {Display version number.}
- \end{shbox}
- \caption{The options of \textit{xsensors}}
- \label{sh:xsensor}
- \end{sh}
+% \begin{sh}
+% \shuser{simon}
+% \shmachine{linuxmint}
+% \begin{shbox}
+% \shline{}{cd Desktop/}
+% \shline{Desktop/}{xsensors -help}
+% \shoutput{}{}
+% \shoutput{}{\underline{Options:}}
+% \shoutput{}{}
+% \shoutput{-f}{Display all temperatures in Fahrenheit.}
+% \shoutput{-h}{Display this help text and exit.}
+% \shoutput{-c}{+filename Specify the libsensors configuration file.}
+% \shoutput{-t}{+time Specify the update time in number of seconds.}
+% \shoutput{-v}{Display version number.}
+% \end{shbox}
+% \caption{The options of \textit{xsensors}}
+% \label{sh:xsensor}
+% \end{sh}
% \end{verbatim}
% \shuser{simon}
% \shmachine{linuxmint}
@@ -443,8 +613,8 @@
% \caption{Hello World in \TeX{}}
% \label{sh:TeX}
%\end{sh}
-%
-% \subsubsection{Preset creation}
+%\newpage
+% \subsubsection{Preset creation}\label{subsubsec:presetdef}
%
% \shpresetdef{odd}{
% \shpreset{blackwhite}
@@ -634,6 +804,163 @@
% \caption{The options of \textit{xsensors} -- \textit{blackwhite} preset}
% \label{sh:bwtest}
%\end{sh}
+% \newpage
+% \subsection{Automated command execution and formatting}\shpreset{default}
+% \subsubsection{Basic examples}
+%
+% \begin{sh}
+% \begin{verbatim}
+% \begin{sh}
+% \scriptsize
+% \shread{avrdude -c usbasp -p attiny24}{avrdude-log.save}
+% \caption{\texttt{avrdude} session, read from a file via \cmd{\shread}}
+% \label{sh:avrdude_session}
+% \end{sh}
+% \end{verbatim}
+% \scriptsize
+% \shread{avrdude -c usbasp -p attiny24}{avrdude-log.save}
+% \caption{\texttt{avrdude} session, read from a file via \cmd{\shread}}
+% \label{sh:avrdude_session}
+% \end{sh}
+%
+% \begin{sh}
+% \begin{verbatim}
+% \begin{sh}
+% \shautoformat{false}
+% \shrun{ifup --help}
+% \caption{The help pages of \texttt{ifup}, standard \cmd{\shrun}}
+% \label{sh:ifup}
+% \end{sh}
+% \end{verbatim}
+% \shrun{ifup --help}
+% \caption{The help pages of \texttt{ifup}, standard \cmd{\shrun}}
+% \label{sh:ifup}
+% \end{sh}
+%
+%
+% \begin{sh}
+% \begin{verbatim}
+% \begin{sh}
+% \shrun{xsensor -help}
+% \caption{A typo resulting in an error}
+% \label{sh:error}
+% \end{sh}
+% \end{verbatim}
+% \shrun{xsensor -help}
+% \caption{A typo resulting in an error}
+% \label{sh:error}
+% \end{sh}
+%
+%
+% \noindent As you can see the automatic execution of commands works
+% fine\footnote{Note: In case you want to build this documentation on your own, you will need to run \texttt{tex shdoc.ins} to get the package file, as well as the file for the \texttt{avrdude} session-read example. Further, you may want to make sure to use a system where the given shell commands actually exist.}, although most of the tab characters in
+% session~\ref{sh:ifup} get
+% printed as dashes or other weird symbols. Thus, I recommend to at least use the autoformat script option permanently.
+% The redirection of the error stream in session~\ref{sh:error} also shows the expected result.
+%
+%
+% \subsubsection{Autoformat script before/after comparison}
+%
+% \begin{sh}
+% \begin{verbatim}
+% \begin{sh}
+% \shautoformat{false}
+% \shautorun{xsensors -help}
+% \caption{The options of xsensors before using the autoformat script}
+% \label{sh:xsensors_noautof}
+% \end{sh}
+% \end{verbatim}
+% \shautoformat{false}
+% \shautorun{xsensors -help}
+% \caption{The options of xsensors before using the autoformat script}
+% \label{sh:xsensors_noautof}
+% \end{sh}
+%
+% \begin{sh}
+% \begin{verbatim}
+% \begin{sh}
+% \shautoformat{true}
+% \shautorun{xsensors -help}
+% \caption{The options of xsensors after using the autoformat script}
+% \label{sh:xsensors_autof}
+% \end{sh}
+% \end{verbatim}
+% \shautoformat{true}
+% \shautorun{xsensors -help}
+% \caption{The options of xsensors after using the autoformat script}
+% \label{sh:xsensors_autof}
+% \end{sh}
+%
+% As you can see in session~\ref{sh:xsensors_noautof} and~\ref{sh:xsensors_autof} the autoformat script
+% can really improve your output. However, xsensors is still an easy job for \textit{shdoc} and sometimes
+% the \cmd{\shautorun} macro is not really the best way to run a command. At first, it's still experimental
+% and due to the \textit{stringstrings} manipulation it can take a massive amount of time to build your document.
+% The second reason you might not always use autorun is, when commands output a large number of lines and the
+% occuring options vary a lot in terms of length and style. In this case autorun is not likely to produce a nice output --
+% as seen in session~\ref{sh:gcc_noautof} and~\ref{sh:gcc_autof}.
+%
+% \begin{sh}
+% \begin{verbatim}
+% \begin{sh}
+% \tiny
+% \shautoformat{false}
+% \shrun{gcc --help}
+% \caption{Help pages of gcc before autoformat, standard \cmd{\shrun}}
+% \label{sh:gcc_noautof_noautorun}
+% \end{sh}
+% \end{verbatim}
+% \tiny
+% \shautoformat{false}
+% \shrun{gcc --help}
+% \caption{Help pages of gcc before autoformat, standard \cmd{\shrun}}
+% \label{sh:gcc_noautof_noautorun}
+% \end{sh}
+%
+% \vspace*{-5mm}
+% \begin{sh}
+% \begin{verbatim}
+% \begin{sh}
+% \tiny
+% \shautoformat{false}
+% \shautorun{gcc --help}
+% \caption{Help pages of gcc before using the autoformat script}
+% \label{sh:gcc_noautof}
+% \end{sh}
+% \end{verbatim}\vspace{-5mm}
+% \tiny
+% \shautoformat{false}
+% \shautorun{gcc --help}
+% \caption{Help pages of gcc before using the autoformat script}
+% \label{sh:gcc_noautof}
+% \end{sh}
+%
+% \vspace*{-5mm}
+% \begin{sh}
+% \begin{verbatim}
+% \begin{sh}
+% \tiny
+% \shautoformat{true}
+% \shautorun{gcc --help}
+% \caption{Help pages of gcc after using the autoformat script}
+% \label{sh:gcc_autof}
+% \end{sh}
+% \end{verbatim}\vspace{-5mm}
+% \tiny
+% \shautoformat{true}
+% \shautorun{gcc --help}
+% \caption{Help pages of gcc after using the autoformat script}
+% \label{sh:gcc_autof}
+% \end{sh}
+% \newpage
+% \addcontentsline{toc}{section}{List of Terminal Sessions}
+% \phantomsection
+% \listofsh\bigskip
+%
+% \noindent\DescribeMacro{\listofsh}As the float environment supports automatic lists, you can use them with
+% \textit{shdoc}, too. Just use \cmd{\listofsh} for that.
+%
+% \shclearfiles
+%
% ^^A Implementation from here
%\StopEventually{\PrintIndex}
%
@@ -661,13 +988,13 @@
\DeclareStringOption[white!60!gray]{optioncolor}
\DeclareStringOption[black]{textcolor}
\DeclareStringOption[\$]{indicatorsymbol}
-\DeclareStringOption[\~]{rootpathsymbol}
+\DeclareStringOption[\~]{defaultpath}
\DeclareStringOption[@]{separatorsymbol}
\ProcessKeyvalOptions*
% \end{macrocode}
%\end{macro}
%
-% \subsection{Presets}~\label{subsec:presetdef}
+% \subsection{Presets}\label{subsec:presetdef}
% Right after the option definitions the preset commands are defined.
% Every preset is stored in a macro with the generic name \cmd{\sh@preset@NAME}, where
% \texttt{NAME} stands for the preset name.
@@ -675,9 +1002,8 @@
% to simply execute the package internal preset macro:
%
%\begin{macro}{\shpreset}
-%
% \begin{macrocode}
-\def\shpreset#1{\csname sh@preset@#1\endcsname}
+\def\shpreset#1{\csname sh@preset@#1\endcsname}%
% \end{macrocode}
%\end{macro}
% To simplify the creation of new presets a few macros are needed. The main command
@@ -687,94 +1013,97 @@
%\begin{macro}{
% \shpresetdef}
% \begin{macrocode}
-\def\shpresetdef#1#2{
- \expandafter\gdef\csname sh@preset@#1\endcsname{\shpreset{default} #2}
-}
+\def\shpresetdef#1#2{%
+ \expandafter\gdef\csname sh@preset@#1\endcsname{\shpreset{default} #2}%
+}%
% \end{macrocode}
%\end{macro}
% Basically, every command can be used as the second argument of \cmd{\shpresetdef}, but
% most of them won't change any settings in \textit{shdoc}. The only useful macros in this
-% context are those, who explicitly change a color or symbol within the package, namely
-% \cmd{\shchangecolor} and \cmd{\shchangesymbol}.
+% context are those, who explicitly change a color, symbol or value within the package, namely
+% \cmd{\shchange}, \cmd{\shchangecolor} and \cmd{\shchangesymbol}.
%
-% \cmd{\shchangecolor} has two arguments, where the first is the name of the color that
+% \cmd{\shchange} has two arguments, where the first is the name of the parameter that
% should be changed and the second is the new value. Although there won't be an error,
-% colornames that aren't listed in table~\ref{tab:color_var} are not valid. The macro simply
-% redefines the according color.
-%\begin{macro}{\shchangecolor}
+% other names than those implemented by the package are not valid. The macro simply
+% redefines the according parameter.
+%\begin{macro}{\shchange}
% \begin{macrocode}
-\def\shchangecolor#1#2{\expandafter\gdef\csname shdoc@#1\endcsname{#2}}
+\def\shchange#1#2{\expandafter\gdef\csname shdoc@#1\endcsname{#2}}
% \end{macrocode}
%\end{macro}
%
%\begin{macro}{\shchangesymbol}
-% \cmd{\shchangesymbol} implements the same definition as \cmd{\shchangecolor}.
-% Thus, the command only exists for logical reasons. It simply redefines the
-% desired symbol.
+%\begin{macro}{\shchangecolor}
+% \cmd{\shchangesymbol} and \cmd{\shchangecolor} are two other commands, that implement the exact same
+% definition as \cmd{\shchange}.
+% Thus, these commands only exists for logical reasons. They simply redefine the
+% desired symbol or color.
% \begin{macrocode}
-\let\shchangesymbol\shchangecolor
+\let\shchangesymbol\shchange%
+\let\shchangecolor\shchange%
% \end{macrocode}
-%\end{macro}
+%\end{macro}\end{macro}
%
-% Since \cmd{\shpresetdef} calls \cmd{\shpreset\{default\}}, the default preset
-% needed to be defined manually via \cmd{\def}.
+% \noindent Since \cmd{\shpresetdef} calls \cmd{\shpreset\{default\}}, the default preset
+% had to be defined manually via \cmd{\def}.
%\begin{macro}{\sh@preset@default}
% \begin{macrocode}
-\def\sh@preset@default{
- \shchangecolor{backgroundcolor}{gray!70}
- \shchangecolor{usernamecolor}{green!80!yellow}
- \shchangecolor{machinenamecolor}{green!80!yellow}
- \shchangecolor{pathcolor}{RoyalBlue}
- \shchangecolor{indicatorcolor}{RoyalBlue}
- \shchangecolor{separatorcolor}{green!80!yellow}
- \shchangecolor{optioncolor}{white!60!gray}
- \shchangecolor{textcolor}{black}
- \shchangesymbol{indicatorsymbol}{\$}
- \shchangesymbol{rootpathsymbol}{\~}
- \shchangesymbol{separatorsymbol}{@}
-}
+\def\sh@preset@default{%
+ \shchangecolor{backgroundcolor}{gray!70}%
+ \shchangecolor{usernamecolor}{green!80!yellow}%
+ \shchangecolor{machinenamecolor}{green!80!yellow}%
+ \shchangecolor{pathcolor}{RoyalBlue}%
+ \shchangecolor{indicatorcolor}{RoyalBlue}%
+ \shchangecolor{separatorcolor}{green!80!yellow}%
+ \shchangecolor{optioncolor}{white!60!gray}%
+ \shchangecolor{textcolor}{black}%
+ \shchangesymbol{indicatorsymbol}{\$}%
+ \shchangesymbol{defaultpath}{\~}%
+ \shchangesymbol{separatorsymbol}{@}%
+}%
% \end{macrocode}
%\end{macro}
% As the \textit{shdoc} package was initally ment to imitate the Linux Mint bash, the
% default preset is equal to the \textit{mint} style, which is defined right after the default preset:
%\begin{macro}{\sh@preset@mint}
% \begin{macrocode}
-\shpresetdef{mint}{\shpreset{default}}
+\shpresetdef{mint}{\shpreset{default}}%
% \end{macrocode}
%\end{macro}
%
-% The second preset style is the ``arrows'' style, which is a dark color scheme with
+% \noindent The second preset style is the ``arrows'' style, which is a dark color scheme with
% two arrows as the indicator symbol.
%\begin{macro}{\sh@preset@arrows}
% \begin{macrocode}
-\shpresetdef{arrows}{
- \shchangecolor{usernamecolor}{red}
- \shchangecolor{machinenamecolor}{green!80!yellow}
- \shchangecolor{separatorcolor}{white}
- \shchangecolor{indicatorsymbol}{$\gg$}
- \shchangecolor{indicatorcolor}{green!80!yellow}
- \shchangecolor{backgroundcolor}{black}
- \shchangecolor{textcolor}{white}
- \shchangecolor{optioncolor}{gray}
-}
+\shpresetdef{arrows}{%
+ \shchangecolor{usernamecolor}{red}%
+ \shchangecolor{machinenamecolor}{green!80!yellow}%
+ \shchangecolor{separatorcolor}{white}%
+ \shchangecolor{indicatorsymbol}{$\gg$}%
+ \shchangecolor{indicatorcolor}{green!80!yellow}%
+ \shchangecolor{backgroundcolor}{black}%
+ \shchangecolor{textcolor}{white}%
+ \shchangecolor{optioncolor}{gray}%
+}%
% \end{macrocode}
%\end{macro}
%
-% Another dark scheme is the ``darkblue'' preset, which defines a dark blue background color
+% \noindent Another dark scheme is the ``darkblue'' preset, which defines a dark blue background color
% and more or less appropriate other colors. The definition of this preset is furthermore a
% nice example, how macros of other packages could also make sense within the \cmd{\shpresetdef}
% command.
%\begin{macro}{\sh@preset@darkblue}
% \begin{macrocode}
-\shpresetdef{darkblue}{
- \definecolor{shdarkblue}{RGB}{7,75,138}
- \shchangecolor{backgroundcolor}{shdarkblue}
- \shchangecolor{textcolor}{white}
- \shchangecolor{separatorcolor}{white}
- \shchangecolor{usernamecolor}{orange}
- \shchangecolor{machinenamecolor}{orange}
- \shchangecolor{pathcolor}{green!60!black}
- \shchangecolor{optioncolor}{SkyBlue!80!black}
+\shpresetdef{darkblue}{%
+ \definecolor{shdarkblue}{RGB}{7,75,138}% xcolor syntax
+ \shchangecolor{backgroundcolor}{shdarkblue}%
+ \shchangecolor{textcolor}{white}%
+ \shchangecolor{separatorcolor}{white}%
+ \shchangecolor{usernamecolor}{orange}%
+ \shchangecolor{machinenamecolor}{orange}%
+ \shchangecolor{pathcolor}{green!60!black}%
+ \shchangecolor{optioncolor}{SkyBlue!80!black}%
}
% \end{macrocode}
%\end{macro}
@@ -784,15 +1113,15 @@
% different versions of gray, black and white -- see the examples in section~\ref{sec:examples}.
%\begin{macro}{\sh@preset@blackwhite}
% \begin{macrocode}
-\shpresetdef{blackwhite}{
- \shchangecolor{backgroundcolor}{gray!30}
- \shchangecolor{textcolor}{black}
- \shchangecolor{separatorcolor}{black}
- \shchangecolor{usernamecolor}{gray}
- \shchangecolor{machinenamecolor}{gray}
- \shchangecolor{pathcolor}{gray!50!black}
- \shchangecolor{optioncolor}{white}
- \shchangecolor{indicatorcolor}{white}
+\shpresetdef{blackwhite}{%
+ \shchangecolor{backgroundcolor}{gray!30}%
+ \shchangecolor{textcolor}{black}%
+ \shchangecolor{separatorcolor}{black}%
+ \shchangecolor{usernamecolor}{gray}%
+ \shchangecolor{machinenamecolor}{gray}%
+ \shchangecolor{pathcolor}{gray!50!black}%
+ \shchangecolor{optioncolor}{white}%
+ \shchangecolor{indicatorcolor}{white}%
}
% \end{macrocode}
%\end{macro}
@@ -800,14 +1129,14 @@
% The last and probably lightest preset is the ``airy'' preset with light blue and green elements.\par
%\begin{macro}{\sh@preset@airy}
% \begin{macrocode}
-\shpresetdef{airy}{
- \shchangecolor{backgroundcolor}{SkyBlue!15}
- \shchangecolor{usernamecolor}{Emerald}
- \shchangecolor{machinenamecolor}{Emerald}
- \shchangecolor{pathcolor}{orange!70}
- \shchangecolor{indicatorcolor}{orange!70}
- \shchangecolor{separatorcolor}{Emerald}
- \shchangecolor{optioncolor}{Emerald!30}
+\shpresetdef{airy}{%
+ \shchangecolor{backgroundcolor}{SkyBlue!15}%
+ \shchangecolor{usernamecolor}{Emerald}%
+ \shchangecolor{machinenamecolor}{Emerald}%
+ \shchangecolor{pathcolor}{orange!70}%
+ \shchangecolor{indicatorcolor}{orange!70}%
+ \shchangecolor{separatorcolor}{Emerald}%
+ \shchangecolor{optioncolor}{Emerald!30}%
}
% \end{macrocode}
%\end{macro}
@@ -821,13 +1150,13 @@
% standard \LaTeX\ counter and is initially set to 0.
%\begin{macro}{\shlinenumber}
% \begin{macrocode}
-\newcounter{shlinenumber}
-\setcounter{shlinenumber}{0}
+\newcounter{shlinenumber}% def new counter
+\setcounter{shlinenumber}{0}% set counter to 0
% \end{macrocode}
%\end{macro}
%
-% Since the outer environment is a float, a list name variable is
-% needed to make the name adjustable. There are two macros that
+% \noindent Since the outer environment is a float, a list name variable is
+% needed to make the name user-adjustable. There are two macros that
% implement this functionality: \cmd{\@shlistname} is the
% name variable that holds the current value of the list name.
% \cmd{\shlistname} is a user command, that redefines the
@@ -835,9 +1164,9 @@
% standard value is set.
%\begin{macro}{\shlistname}
% \begin{macrocode}
-\let\@shlistname\relax
-\gdef\shlistname#1{\gdef\@shlistname{#1}}
-\shlistname{List of Terminal Sessions}
+\let\@shlistname\relax%
+\gdef\shlistname#1{\gdef\@shlistname{#1}}%
+\shlistname{List of Terminal Sessions}% set default value
% \end{macrocode}
%\end{macro}
%
@@ -850,109 +1179,347 @@
% is defined.
%\begin{macro}{\sh}
% \begin{macrocode}
-\newfloat{sh}{tbph}{lsh}
-\restylefloat*{sh}
-\floatstyle{plain}
-\let\@shfloatname\relax
-\gdef\shfloatname#1{\gdef\@shfloatname{#1}}
-\shfloatname{Terminal~Session}
-\floatname{sh}{\@shfloatname}
-\captionsetup[sh]{position=bottom}
-\def\listofsh{\listof{sh}{\@shlistname}}
+\newfloat{sh}{tbph}{lsh}% define new float
+\restylefloat*{sh}%
+\floatstyle{plain}% set style
+
+\let\@shfloatname\relax%
+\gdef\shfloatname#1{\gdef\@shfloatname{#1}}%
+\shfloatname{Terminal~Session}% default float name
+\floatname{sh}{\@shfloatname}%
+
+\captionsetup[sh]{position=bottom}%
+\def\listofsh{\listof{sh}{\@shlistname}}%
% \end{macrocode}
%\end{macro}
%
% \subsubsection{Framebox}
% For each session the user and machine values can and must be set, but they could also be
% set at the beginning of a document to be valid for every terminal session. In the same manner
-% as before, two name variables and their setup commands are defined. There is no default value.
+% as before, two name variables and their setup commands are defined. The default value for the username is \texttt{root},
+% whereas the default for the machine is \texttt{linux}.
%\begin{macro}{
% \shuser,
% \shmachine}
% \begin{macrocode}
-\makeatletter
-\let\@shuser\relax
-\let\@shmachine\relax
-\def\shuser#1{\gdef\@shuser{#1}}
-\def\shmachine#1{\gdef\@shmachine{#1}}
+\let\@shuser\relax%
+\let\@shmachine\relax%
+\def\shuser#1{\gdef\@shuser{#1}}%
+\def\shmachine#1{\gdef\@shmachine{#1}}%
+\def\@default@shuser{root}%
+\def\@default@shmachine{linux}%
+\shuser{\@default@shuser}%
+\shmachine{\@default@shmachine}%
% \end{macrocode}
%\end{macro}
%
-%
+%
+%\begin{macro}{\sh@lnscale}
+%\begin{macro}{\sh@fontcheck}
% Within the framebox \cmd{\shbox} -- which is defined at the very end of the source code --
% there are two commands: \cmd{\shline} for user inputs and \cmd{\shoutput} for shell outputs.
-% When \cmd{\shline} is executed it prints the line number onto the left side of the box first.
-%
+% Each of these macros prints the line number onto the left side of the box first.
+% The number is relatively scaled down by a factor of $0.7$, which is stored in \cmd{\sh@lnscale}.
+% However, if the overall font size gets too small (i.e. when using \cmd{\scriptsize}, \cmd{\tiny}, \dots)
+% this factor is increased to prevent warnings from the \textit{relscale} package, which does the line
+% number scaling. The macro that acomplishes this automatic scaling is \cmd{\sh@fontcheck}.
+%
+% \begin{macrocode}
+\def\sh@lnscale{.7}% default number scaling
+\def\sh@fontcheck{% if fontsize < 6pt
+ \ifthenelse{\f@size<6}{%
+ \gdef\sh@lnscale{1}% factor = 1
+ }{% elif fontsize < 8pt
+ \ifthenelse{\f@size<8}{%
+ \gdef\sh@lnscale{.84}% factor = 0.84
+ }{% else: nothing
+ }%
+ }%
+}%
+% \end{macrocode}
+%\end{macro}\end{macro}
+%
%\begin{macro}{\shline}
+%
+% In order to keep the text from mixing up with the line numbers a hangindent is required.
+% The indent is set according to the width of the linenumbers, so at the beginning of the
+% \cmd{\shline} definition \cmd{\sh@linenumberwidth} is defined.\par
+% Within a \cmd{\shline} the font is set to typewriter style, the font size gets checked and
+% the scaling factor for the line numbers is adjusted. Starting without any indent, \cmd{\shline}
+% determines if a leading 0 for the line number is needed. If so, the 0 is added, the number gets typeset
+% and the width of the line number is stored. After the number a small horizontal space creates the
+% distance, that's needed between the number and the following username and machine values. They are
+% typeset in their dedicated colors right after the appropriate hangindent is set. A small if-else construct
+% checks if the first argument of the macro is empty and acts accordingly -- see section~\ref{subsubsec:in_and_path}.
+% At the end, the line number is incremented to be ready for the next line.
% \begin{macrocode}
+\newlength{\sh@linenumberwidth}%
\long\def\shline#1#2{
- \ttfamily\noindent\scriptsize
+ \ttfamily\sh@fontcheck\noindent%
+ \ifnum\value{shlinenumber}<10%
+ \textcolor{\shdoc@textcolor}{\relscale{\sh@lnscale}0\theshlinenumber}%
+ \settowidth{\sh@linenumberwidth}{%
+ \relscale{\sh@lnscale}0\theshlinenumber%
+ }%
+ \else%
+ \textcolor{\shdoc@textcolor}{\relscale{\sh@lnscale}\theshlinenumber}%
+ \settowidth{\sh@linenumberwidth}{%
+ \relscale{\sh@lnscale}\theshlinenumber%
+ }%
+ \fi\hspace{\sh@linenumberwidth}%
+ \hangindent=2\sh@linenumberwidth%
+ \textcolor{\shdoc@usernamecolor}{\@shuser}%
+ \textcolor{\shdoc@separatorcolor}{\shdoc@separatorsymbol}%
+ \textcolor{\shdoc@machinenamecolor}{\@shmachine}%
+ \ \ifx&#1&%
+ \textcolor{\shdoc@pathcolor}{\shdoc@defaultpath\ }%
+ \textcolor{\shdoc@indicatorcolor}{\shdoc@indicatorsymbol}
+ \else%
+ \textcolor{\shdoc@pathcolor}{#1\ }%
+ \textcolor{\shdoc@indicatorcolor}{\shdoc@indicatorsymbol}%
+ \fi\ \textcolor{\shdoc@textcolor}{#2}%
+ \stepcounter{shlinenumber}\par
+}
% \end{macrocode}
-% If the counter is less equal then $10$, a leading zero is added; otherwise the line number
-% is directly printed.
+%\end{macro}
+%-----------------------------------------------------------------
+%
+%\begin{macro}{\shoutput}
+%
+% The \cmd{\shoutput} command is very similar to its pendant, but has other requirements, too.
+% As there may be optionboxes within an output line, the hangindent handling needs to be adjusted.
+% Thus, a new length \cmd{\sh@optionboxwidth} is added.\par
+% Just as before, the font is set to typewriter style and the size is checked. The line number gets
+% typeset, the horizontal space is added and the hangindent is set. Again a small if-else construct checks
+% the first argument. If the argument is empty, the width of the optionbox is set to zero and the box is
+% suppressed. Otherwise, a framed colorbox is used to create the optionbox and the width of
+% the whole box is stored. The stored value is then used to increase the hangindent appropriately.
% \begin{macrocode}
- \ifnum\value{shlinenumber}<10
- \textcolor{\shdoc@textcolor}{0\theshlinenumber}
- \else
- \textcolor{\shdoc@textcolor}{\theshlinenumber}
- \fi
+\newlength{\sh@optionboxwidth}
+\long\def\shoutput#1#2{
+ \ttfamily\sh@fontcheck\noindent%
+ \ifnum\value{shlinenumber}<10%
+ \textcolor{\shdoc@textcolor}{\relscale{\sh@lnscale}0\theshlinenumber}%
+ \settowidth{\sh@linenumberwidth}{%
+ \relscale{\sh@lnscale}0\theshlinenumber%
+ }%
+ \else%
+ \textcolor{\shdoc@textcolor}{\relscale{\sh@lnscale}\theshlinenumber}%
+ \settowidth{\sh@linenumberwidth}{%
+ \relscale{\sh@lnscale}\theshlinenumber%
+ }%
+ \fi\hspace{\sh@linenumberwidth}%
+ \hangindent=2\sh@linenumberwidth%
+ \ifx&#1&%
+ \textcolor{\shdoc@textcolor}{#2}\stepcounter{shlinenumber}%
+ \settowidth{\sh@optionboxwidth}{0cm}%
+ \else%
+ \fcolorbox{\shdoc@optioncolor}%
+ {\shdoc@optioncolor}{\textcolor{\shdoc@textcolor}{[#1]}}\ %
+ \settowidth{\sh@optionboxwidth}{%
+ \fcolorbox{\shdoc@optioncolor}%
+ {\shdoc@optioncolor}{\textcolor{\shdoc@textcolor}{[#1]}}\ }%
+ \addtolength{\hangindent}{\sh@optionboxwidth}%
+ \textcolor{\shdoc@textcolor}{#2}\stepcounter{shlinenumber}%
+ \fi\par%
+}
% \end{macrocode}
-% After some white spaces the username is printed in the username color.
-% It is followed by the separator and the machine name in their appropriate colors.
+%\end{macro}
+%
+%\begin{macro}{\shautoformat, \shautopath}
+% The autoformat and autopath macros that enable or disable the corresponding functionality
+% are defined as a macro that holds whatever text the user passes as an argument. If the
+% given text is valid is decided later through an if-else statement.
% \begin{macrocode}
- \normalsize\ \ \textcolor{\shdoc@usernamecolor}{\@shuser}\ignorespaces
- \textcolor{\shdoc@separatorcolor}{\shdoc@separatorsymbol}\ignorespaces
- \textcolor{\shdoc@machinenamecolor}{\@shmachine}\ignorespaces
+\let\sh@autoformat\relax%
+\def\shautoformat#1{\gdef\sh@autoformat{#1}}%
+\shautoformat{false}%
+
+\let\sh@autopath\relax%
+\def\shautopath#1{\gdef\sh@autopath{#1}}%
+\shautopath{false}%
% \end{macrocode}
-% Furthermore, the path argument is checked. If it's empty, the root path symbol is automatically
-% printed, if not the given path is used. The last element that's not a command is the indicator
-% symbol, which is set after a white space. The rest of one \cmd{\shline} contains the commands
-% that the user has passed through the second argument.
+%\end{macro}
+%
+%\begin{macro}{\shpath}
+% Sometimes it's desired to get the path of the actual working directory. \cmd{\shpath}
+% prints the current path by capturing the output of the Linux-specific \textit{print working
+% directory} '\texttt{pwd}' command. The output is further stored in the temporary file \texttt{shpath.tmp}.
% \begin{macrocode}
- \ \ifx&#1&\ignorespaces
- \textcolor{\shdoc@pathcolor}{\shdoc@rootpathsymbol\ }\ignorespaces
- \textcolor{\shdoc@indicatorcolor}{\shdoc@indicatorsymbol}
- \else\ignorespaces
- \textcolor{\shdoc@pathcolor}{#1\ }\ignorespaces
- \textcolor{\shdoc@indicatorcolor}{\shdoc@indicatorsymbol}\ignorespaces
- \fi\ \textcolor{\shdoc@textcolor}{#2}
- \stepcounter{shlinenumber}\par
+\def\shpath{%
+ \immediate\write18{pwd >shpath.tmp 2>&1}%
+ \newread\sh@pathfile%
+ \openin\sh@pathfile=shpath.tmp%
+ \endlinechar=-1%
+ \readline\sh@pathfile to \sh@path%
+ \sh@path%
+ \closein\sh@pathfile
}
% \end{macrocode}
%\end{macro}
%
-% Just as before the \cmd{\shoutput} prints the line number first and checks
-% if the value is under 10.
-%\begin{macro}{\shoutput}
+%\begin{macro}{\shread}
+% \textit{shdoc} is able to read text files, that contain the output of a shell command, via
+% the \cmd{\shread} macro. At first a new readfile needs to be opened. The endlinechar is set
+% to $-1$, so it won't appear in the document. After that a new \cmd{\shbox} is started and a
+% loop reads the lines from the text file. A few ifs are used to check if the first argument
+% of \cmd{\shread} is empty and to check if autopath is enabled.
+%
% \begin{macrocode}
-\long\def\shoutput#1#2{
- \ttfamily\noindent\scriptsize
- \ifnum\value{shlinenumber}<10
- \textcolor{\shdoc@textcolor}{0\theshlinenumber}
- \else
- \textcolor{\shdoc@textcolor}{\theshlinenumber}
- \fi
+\def\shread#1#2{%
+ \newread\sh@inputfile%
+ \openin\sh@inputfile=#2%
+
+ \endlinechar=-1% hide the endlinechar (-1 is invalid, thus not printed)
+ \begin{shbox}%
+ \ifthenelse{\equal{#1}{}}{}% empty: do not print
+ {%
+ \ifthenelse{\equal{\sh@autopath}{true}}{%
+ \shline{\shpath}{#1}%
+ }{%
+ \ifthenelse{\equal{\sh@autopath}{false}}{}%
+ {\typeout{-----------------------------------------------}%
+ \typeout{ Package shdoc info: I don't know what you}%
+ \typeout{ mean when passing '\sh@autopath' to autopath}%
+ \typeout{ and I'm going to ignore it and restore the}%
+ \typeout{default 'false'} %
+ \typeout{-----------------------------------------------}%
+ \shautopath{false}}%
+ \shline{}{#1}%
+ }%
+ }
+ \loop\unless\ifeof\sh@inputfile%
+ \readline\sh@inputfile to \sh@fileline%
+ \ifeof\sh@inputfile% again check of eof prevents last blank line
+ \else%
+ \shoutput{}{\sh@fileline}%
+ \fi%
+ \repeat%
+\end{shbox}%
+\closein\sh@inputfile%
+}
+% \end{macrocode}
+%\end{macro}
+%
+%
+%\begin{macro}{\shrun}
+% \cmd{\shrun} lets the user specify a command that is passed to the
+% system shell. Its output is stored in a file -- and possibly preformatted by
+% the reformat script -- and is then read by \cmd{\shread}. An if statement checks
+% if autoformat is enabled.
+%
+% \begin{macrocode}
+\def\shrun#1{%
+ \ifthenelse{\equal{\sh@autoformat}{true}}{%
+ \immediate\write18{#1 >shrun.tmp 2>&1}%
+ \immediate\write18{./shreformat.sh}%
+ \shread{#1}{shrun-formatted.tmp}%
+ }{%
+ \ifthenelse{\equal{\sh@autoformat}{false}}{}%
+ {\typeout{-----------------------------------------------}%
+ \typeout{ Package shdoc info: I don't know what you}%
+ \typeout{ mean when passing '\sh@autoformat' to autoformat}%
+ \typeout{ and I'm going to ignore it and restore the}%
+ \typeout{default 'false'}%
+ \typeout{-----------------------------------------------}%
+ \shautoformat{false}}%
+ \immediate\write18{#1 >shrun.tmp 2>&1}%
+ \shread{#1}{shrun.tmp}%
+}%
+}%
+% \end{macrocode}
+%\end{macro}
+%
+%
+%\begin{macro}{\shautoread}
+% Autoread is an experimental feature of \textit{shdoc} that lets the package detect possible
+% shell options and typeset them within an optionbox. The read functionality is the same as
+% in \cmd{\shread}, however \textit{stringstrings} is used to modify the read file lines.
+% At first the first word is extracted from the line via \cmd{\getnextword}. After that,
+% the word is searched for the '-' character. If exactly one is found, the word is typeset
+% within an optionbox. The amount of chars that the word consists of is then removed from the
+% complete line and the rest of the line gets typeset as text.
+%
+% \begin{macrocode}
+\def\shautoread#1#2{%
+ \newread\sh@inputfile%
+ \openin\sh@inputfile=#2%
+ \endlinechar=-1%
+ \begin{shbox}
+ \ifthenelse{\equal{#1}{}}{%
+ }{%
+ \ifthenelse{\equal{\sh@autopath}{true}}{%
+ \shline{\shpath}{#1}%
+ }{%
+ \ifthenelse{\equal{\sh@autopath}{false}}{}%
+ {\typeout{-----------------------------------------------}%
+ \typeout{ Package shdoc info: I don't know what you}%
+ \typeout{ mean when passing '\sh@autopath' to autopath}%
+ \typeout{ and I'm going to ignore it and restore the}%
+ \typeout{default 'false'}%
+ \typeout{-----------------------------------------------}%
+ \shautopath{false}}%
+ \shline{}{#1}%
+ }%
+}%
+\loop\unless\ifeof\sh@inputfile%
+ \readline\sh@inputfile to \sh@fileline%
+ \ifeof\sh@inputfile%
+\else%
+ \getnextword[e]{\sh@fileline}%
+ \findchars[q]{\thestring}{-}%
+ \ifthenelse{\equal{\theresult}{1}}{%
+ \shoutput{\thestring}%
+ {\stringlength[e]{\thestring}\gobblechars[v]{\sh@fileline}{\theresult}}%
+}{%
+ \shoutput{}{\sh@fileline}%
+}%
+\fi%
+\repeat%
+\end{shbox}%
+\closein\sh@inputfile%
+}%
% \end{macrocode}
-% After that, the first argument is checked. If it's empty, the second argument is directly printed.
-% In this case the user is able to use \cmd{\newline} to insert a linebreak.
-% If the first argument isn't empty a tabular with two columns is generated, the first
-% column contains a colorbox that contains the value of argument one. The second column
-% contains the value of argument two. In this case no linebreak can be inserted.
+%\end{macro}
+%
+%
+%\begin{macro}{\shautorun}
+% \cmd{\shautorun} implements the same functionality as \cmd{\shrun}, but invokes
+% autoread to read the file.
+%
+% \begin{macrocode}
+\def\shautorun#1{
+ \ifthenelse{\equal{\sh@autoformat}{true}}{%
+ \immediate\write18{#1 >shrun.tmp 2>&1}%
+ \immediate\write18{./shreformat.sh}%
+ \shautoread{#1}{shrun-formatted.tmp}%
+ }{%
+ \ifthenelse{\equal{\sh@autoformat}{false}}{}%
+ {\typeout{-----------------------------------------------}%
+ \typeout{ Package shdoc info: I don't know what you}%
+ \typeout{ mean when passing '\sh@autoformat' to autoformat}%
+ \typeout{ and I'm going to ignore it and restore the}%
+ \typeout{default 'false'}%
+ \typeout{-----------------------------------------------}%
+ \shautoformat{false}}%
+ \immediate\write18{#1 >shrun.tmp 2>&1}%
+ \shautoread{#1}{shrun.tmp}%
+}%
+}
+% \end{macrocode}
+%\end{macro}
+%
+%
+%\begin{macro}{\shclearfiles}
+% \cmd{\shclearfiles} removes all the temporary files by calling the shell command '\texttt{rm}'.
% \begin{macrocode}
- \normalsize
- \ifx&#1&
- \textcolor{\shdoc@textcolor}{#2}\stepcounter{shlinenumber}
- \else
- \fcolorbox{\shdoc@optioncolor}{\shdoc@optioncolor}{\textcolor{\shdoc@textcolor}{[#1]}}
- \begin{tabular}{l l}
- & \textcolor{\shdoc@textcolor}{#2}\stepcounter{shlinenumber}
- \end{tabular}
- \fi\par
+\def\shclearfiles{
+ \immediate\write18{rm shrun.tmp; rm shrun-formatted.tmp; rm shpath.tmp}
}
% \end{macrocode}
%\end{macro}
%
-% Finally, the mdframed box is defined through the environment definition command of the
+% \noindent Finally, the mdframed box is defined through the environment definition command of the
% \textit{mdframed} package. The frameline color is white and the default backgroundcolor
% is set. Further, the linecounter is set to 1, when the \cmd{\shbox} environment is started.
%\begin{macro}{\shbox}
diff --git a/Master/texmf-dist/source/latex/shdoc/shdoc.ins b/Master/texmf-dist/source/latex/shdoc/shdoc.ins
index 25201fba63c..ed185c36054 100644
--- a/Master/texmf-dist/source/latex/shdoc/shdoc.ins
+++ b/Master/texmf-dist/source/latex/shdoc/shdoc.ins
@@ -43,6 +43,7 @@ The Current Maintainer of this work is S. M. Laube
\nopreamble\nopostamble
\generate{\file{README.txt}{\from{shdoc.dtx}{readme}}}
+\generate{\file{avrdude-log.save}{\from{shdoc.dtx}{avr}}}