1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
|
% \iffalse meta-comment
%
% Copyright 2016 Simon M. Laube
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `author maintained'.
%
% The Current Maintainer of this work is S. M. Laube
%
% \fi
%
%\iffalse
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{shdoc}[2016/09/04 v2.1b 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>
\iffalse
%</internal>
%<*readme>
Copyright 2016 Simon M. Laube
This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either version 1.3
of this license or (at your option) any later version.
The latest version of this license is in
http://www.latex-project.org/lppl.txt
and version 1.3 or later is part of all distributions of LaTeX
version 2005/12/01 or later.
This work has the LPPL maintenance status `author maintained'.
The Current Maintainer of this work is S. M. Laube
The shdoc package provides a simple, though fancy, float
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.1b.
To create the package (*.sty) from source open a command line prompt,
change to the package directory and type
tex shdoc.ins
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
%</internal>
%<*driver>
\documentclass[a4paper, 10pt]{ltxdoc}
\usepackage{shdoc}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{tikz}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\usepackage[colorlinks=true,linkcolor=black,urlcolor=blue,bookmarks=true]{hyperref}
\begin{document}
\DocInput{shdoc.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \changes{v1.0}{2015/03/10}{Initial version}
% \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}
% \changes{v2.1a}{2016/08/27}{Small changes in the documentation}
% \changes{v2.1b}{2016/09/04}{Changes in the documentation yet again}
%
% \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}}
%\date{}
%
%\maketitle
%
%\shuser{simon}
%\shmachine{linuxmint}
% \begin{shbox}
% \shline{}{tex}
% \shoutput{}{This is TeX, Version 3.14159265 (TeX Live 2015)}
% \shoutput{}{**\cmd{\relax}}
% \shoutput{}{*Hello World!}
% \shoutput{}{*\cmd{\bye}}
% \end{shbox}
% \begin{abstract}
% \noindent The \textit{shdoc} packages helps documenting commandline actions in
% a fancy way. It tries to imitate the look and feel of the original shell prompt
% while offering a wide range of personalization options.
% \end{abstract}
%
%\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
% 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 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.\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 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, 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.
%
%
% \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\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{table}[tbh!]
% \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}
% \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{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\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 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\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}
% \verb|\shpresetdef{useless}{\relax}|
% \end{quote}
% and is then able to apply the preset by calling:
% \begin{quote}
% \verb|\shpreset{useless}|
% \end{quote}
% \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.
% One can use them by calling the \cmd{\shpreset\marg{name}} command with the name of the desired
% preset. The following list shows the appearance and name of the predefined presets -- for visuals
% see section~\ref{sec:examples}:
%
% \begin{description}
% \item[default/mint] The default preset. It implements a gray background theme
% with light gray option boxes, light green user- and machine-name and a blue path value.
%
% \item[arrows] Not recommended for printed documents. Implements a black background theme
% with gray option boxes, red username, white separator, light green machine-name, blue path
% and two arrows as an indicator symbol. The rest of the text is white, too.
%
% \item[darkblue] Implements a dark blue background theme with white text, light blue option
% boxes, orange user- and machine-name and a green path value.
%
% \item[airy] A light colored style. Implements a light blue background theme with cyan option
% boxes and user- \& machine-name, as well as light orange path value and black text.
%
% \item[blackwhite] Best for non-color prints. Implements a light gray background theme with white option
% boxes, black text, darker gray user- and machine-name and a dark gray path value.
% \end{description}
%
%
% \subsection{The environment}\label{subsec:environment}
% Basically a complete terminal session consists out of two environments that contain the
% necessary information that is used to typeset the session.
% \DescribeMacro{\sh} The outer environment is named \cmd{\sh} and basically acts as the
% float environment that could contain one or more so called \cmd{\shbox}es.
% \DescribeMacro{\shbox} Every \cmd{\shbox} contains in- and output lines of the terminal,
% with information provided by the user. The following code shows a brief overview of the
% possible and necessary commands:\par
% \begin{verbatim}
% \shpreset{mint}
% \begin{sh}
% \shuser{simon}
% \shmachine{linuxmint}
% \begin{shbox}
% \shline{}{cd Desktop/}
% \shline{Desktop/}{whoami}
% \shoutput{}{simon}
% \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 should be specified. \DescribeMacro{\shmachine}
% They are set globally and thus are valid for
% 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^^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}
% \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}
% \subsubsection{Basic Sessions}
%\shpreset{blackwhite}
%\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{-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}
% \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}
%
%
%\shpreset{default}
%\begin{sh}
% \begin{verbatim}
% \shpreset{default}
% \begin{sh}
% \shuser{simon}
% \shmachine{linuxmint}
% \begin{shbox}
% \shline{}{tex}
% \shoutput{}{This is TeX, Version 3.14159265 (TeX Live 2015)}
% \shoutput{}{**\cmd{\relax}}
% \shoutput{}{*Hello World!}
% \shoutput{}{*\cmd{\bye}}
% \end{shbox}
% \caption{Hello World in \TeX{}}
% \label{sh:TeX}
% \end{sh}
% \end{verbatim}
% \shuser{simon}
% \shmachine{linuxmint}
% \begin{shbox}
% \shline{}{tex}
% \shoutput{}{This is TeX, Version 3.14159265 (TeX Live 2015)}
% \shoutput{}{**\cmd{\relax}}
% \shoutput{}{*Hello World!}
% \shoutput{}{*\cmd{\bye}}
% \end{shbox}
% \caption{Hello World in \TeX{}}
% \label{sh:TeX}
%\end{sh}
%\newpage
% \subsubsection{Preset creation}\label{subsubsec:presetdef}
%
% \shpresetdef{odd}{
% \shpreset{blackwhite}
% \shchangecolor{usernamecolor}{orange}
% \shchangecolor{machinenamecolor}{orange}
% }
% \shpreset{odd}
% \begin{sh}[th!]
% \begin{verbatim}
% \shpresetdef{odd}{
% \shpreset{blackwhite}
% \shchangecolor{usernamecolor}{orange}
% \shchangecolor{machinenamecolor}{orange}
% }
% \shpreset{odd}
% \begin{sh}
% \shuser{doctorX}
% \shmachine{supercomputer}
% \begin{shbox}
% \shline{/home/doctorX/Documents}{exit}
% \end{shbox}
% \caption{Go away.}
% \label{sh:exit}
% \end{sh}
% \end{verbatim}
% \shuser{doctorX}
% \shmachine{supercomputer}
% \begin{shbox}
% \shline{/home/doctorX/Documents}{exit}
% \end{shbox}
% \caption{Go away.}
% \label{sh:exit}
% \end{sh}
%
% \shpresetdef{mystyle}{
% \shchangecolor{backgroundcolor}{white}
% \shchangecolor{usernamecolor}{red}
% \shchangecolor{machinenamecolor}{red}
% \shchangecolor{separatorcolor}{RoyalBlue}
% \shchangecolor{optioncolor}{orange!50!yellow}
% \shchangesymbol{indicatorsymbol}{!}
% \shchangesymbol{separatorsymbol}{$\geq$}
% }
% \shpreset{mystyle}
% \begin{sh}
% \begin{verbatim}
% \shpresetdef{mystyle}{
% \shchangecolor{backgroundcolor}{white}
% \shchangecolor{usernamecolor}{red}
% \shchangecolor{machinenamecolor}{red}
% \shchangecolor{separatorcolor}{RoyalBlue}
% \shchangecolor{optioncolor}{orange!50!yellow}
% \shchangesymbol{indicatorsymbol}{!}
% \shchangesymbol{separatorsymbol}{$\geq$}
% }
%
% \begin{sh}
% \shuser{joe}
% \shmachine{joesraspian}%
% \begin{shbox}
% \shline{}{history}
% \shoutput{480}{rubber}
% \shoutput{481}{xsensors}
% \shoutput{482}{tracepath www.google.com}
% \shoutput{483}{whoami}
% \shoutput{484}{help}
% \shoutput{485}{exit}
% \end{shbox}
% \caption{History of my session}
% \label{sh:history}
% \end{sh}
% \end{verbatim}
% \shuser{joe}
% \shmachine{joesraspian}%
% \begin{shbox}
% \shline{}{history}
% \shoutput{480}{rubber}
% \shoutput{481}{xsensors}
% \shoutput{482}{tracepath www.google.com}
% \shoutput{483}{whoami}
% \shoutput{484}{help}
% \shoutput{485}{exit}
% \end{shbox}
% \caption{History of my session}
% \label{sh:history}
% \end{sh}\newpage
%
%
% \subsection{All the predefined presets}
% \shpreset{default}
%\begin{sh}[th!]
% \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} -- \textit{default} or \textit{mint} preset}
% \label{sh:minttest}
%\end{sh}
% \shpreset{arrows}
%\begin{sh}[th!]
% \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} -- \textit{arrows} preset}
% \label{sh:arrtest}
%\end{sh}\newpage
% \shpreset{darkblue}
%\begin{sh}[th!]
% \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} -- \textit{darkblue} preset}
% \label{sh:dbtest}
%\end{sh}
% \shpreset{airy}
%\begin{sh}[th!]
% \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} -- \textit{airy} preset}
% \label{sh:airtest}
%\end{sh}
%\shpreset{blackwhite}
%\begin{sh}[th!]
% \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} -- \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}
%
% \newpage
% \section{Implementation}\label{sec:implementation}
% This section describes the implementation of the \textit{shdoc} package and its
% features. The package was written as a \texttt{*.dtx} source file and therefore the
% package code begins with the following instruction:\par
% \begin{macrocode}
%<*package>
% \end{macrocode}
% \subsection{Options}
% First of all, the package options for colouring and symbol options and their default values are defined. The options
% are then processed to make them available for the user.
%\begin{macro}{
% color, symbol
% }
% \begin{macrocode}
\DeclareStringOption[gray!70]{backgroundcolor}
\DeclareStringOption[green!80!yellow]{usernamecolor}
\DeclareStringOption[green!80!yellow]{machinenamecolor}
\DeclareStringOption[RoyalBlue]{pathcolor}
\DeclareStringOption[RoyalBlue]{indicatorcolor}
\DeclareStringOption[green!80!yellow]{separatorcolor}
\DeclareStringOption[white!60!gray]{optioncolor}
\DeclareStringOption[black]{textcolor}
\DeclareStringOption[\$]{indicatorsymbol}
\DeclareStringOption[\~]{defaultpath}
\DeclareStringOption[@]{separatorsymbol}
\ProcessKeyvalOptions*
% \end{macrocode}
%\end{macro}
%
% \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.
% To make the presets better loadable for users \cmd{\shpreset} is defined
% to simply execute the package internal preset macro:
%
%\begin{macro}{\shpreset}
% \begin{macrocode}
\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
% is \cmd{\shpresetdef}, which creates a new preset macro with the desired settings.
% The macro calls \cmd{\shpreset\{default\}} at the beginning, so the inital settings of the new preset
% are the default settings of \textit{shdoc}.
%\begin{macro}{
% \shpresetdef}
% \begin{macrocode}
\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, symbol or value within the package, namely
% \cmd{\shchange}, \cmd{\shchangecolor} and \cmd{\shchangesymbol}.
%
% \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,
% other names than those implemented by the package are not valid. The macro simply
% redefines the according parameter.
%\begin{macro}{\shchange}
% \begin{macrocode}
\def\shchange#1#2{\expandafter\gdef\csname shdoc@#1\endcsname{#2}}
% \end{macrocode}
%\end{macro}
%
%\begin{macro}{\shchangesymbol}
%\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\shchange%
\let\shchangecolor\shchange%
% \end{macrocode}
%\end{macro}\end{macro}
%
% \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{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}}%
% \end{macrocode}
%\end{macro}
%
% \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}%
}%
% \end{macrocode}
%\end{macro}
%
% \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}% 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}
%
% For those, who print their documents with the black ink cartridge only there is the
% ``blackwhite'' preset. The definition sets the background and all the other colors to
% 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}%
}
% \end{macrocode}
%\end{macro}
%
% 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}%
}
% \end{macrocode}
%\end{macro}
%
% \subsection{Environment}
% After all the setting definitions above the actual environment for the
% shell commands can be defined. The whole environment consists of a
% float environment with caption and label and one or more inner frameboxes, which
% are generated with the \textit{mdframed} package. Further there is a
% line number on the left side of every box. The number is defined as a
% standard \LaTeX\ counter and is initially set to 0.
%\begin{macro}{\shlinenumber}
% \begin{macrocode}
\newcounter{shlinenumber}% def new counter
\setcounter{shlinenumber}{0}% set counter to 0
% \end{macrocode}
%\end{macro}
%
% \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
% name according to the users' input. After the definition the
% standard value is set.
%\begin{macro}{\shlistname}
% \begin{macrocode}
\let\@shlistname\relax%
\gdef\shlistname#1{\gdef\@shlistname{#1}}%
\shlistname{List of Terminal Sessions}% set default value
% \end{macrocode}
%\end{macro}
%
% \subsubsection{Float environment}
% Now, the whole float environment is defined. The float is named
% \cmd{\sh} and uses the plain float style. The float name is stored
% in a variable, which is implemented in the same way as the list name.
% Afterwards the name is set. The caption is set to be at the bottom of the
% float and a macro for the generation of the ``List of Terminal Sessions''
% is defined.
%\begin{macro}{\sh}
% \begin{macrocode}
\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. The default value for the username is \texttt{root},
% whereas the default for the machine is \texttt{linux}.
%\begin{macro}{
% \shuser,
% \shmachine}
% \begin{macrocode}
\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.
% 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\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&%
\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}
%\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}
\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&%
\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}
%\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}
\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}
%\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}
\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}
%
%\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}
\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}
%\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}
\def\shclearfiles{
\immediate\write18{rm shrun.tmp; rm shrun-formatted.tmp; rm shpath.tmp}
}
% \end{macrocode}
%\end{macro}
%
% \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}
% \begin{macrocode}
\newmdenv[linecolor=white,backgroundcolor=\shdoc@backgroundcolor,
settings=\setcounter{shlinenumber}{1}]{shbox}
% \end{macrocode}
%\end{macro}
% \begin{macrocode}
\makeatother
%</package>
% \end{macrocode}
%\Finale
%
|