Released as 20240522 ('Tbilisi')
[parallel.git] / src / asciinema-manuscript
blobfbceb133da9ff761f125e81bce58f5a6cb9e81b7
1 #!/bin/bash
3 # Copyright (C) 2007-2022 Ole Tange, http://ole.tange.dk and Free
4 # Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, see <https://www.gnu.org/licenses/>
18 # or write to the Free Software Foundation, Inc., 51 Franklin St,
19 # Fifth Floor, Boston, MA 02110-1301 USA
21 # SPDX-FileCopyrightText: 2021-2022 Ole Tange, http://ole.tange.dk and Free Software and Foundation, Inc.
22 # SPDX-License-Identifier: GPL-3.0-or-later
24 # tty1: asciinema rec demo.cast
25 # tty2: asciinema-manuscript
26 # Run commands in tty2 to set clipboard to next command
28 manuscript() {
29 # S <digit>; sleep this many seconds before executing command
30 # T <digit>; sleep this many seconds before pressing enter
31 cat <<'_'
32 ###
33 # Definitions
34 PS1='$ '
35 S() { sleep $@; }
36 T() { echo -n '$ '; sleep $@; echo; }
37 # Wait for asciinema to read all input
38 sleep 1
39 ###
40 S 0; # Make some files
41 S 1; seq 100 | parallel --bar seq {}0000 '>' file-{}
42 T 2;
43 S 0; # gzip files with -1 .. -7 Note how all combinations are made
44 S 1; parallel --bar gzip {1} '<{2}' '>{2}{1}.gz' ::: -{1..7} ::: *
45 T 1;
46 S 0; # Count the bytes in some files. Each job gets its own color
47 S 1; parallel --color --tag wc {} ::: file-99*
48 T 2;
49 S 0; # Remove .gz-files
50 S 1; rm *.gz
51 T 3;
52 S 0; # Make a big file
53 S 1; seq 10000000 > bigfile
54 T 3;
55 S 0; # Chop bigfile into parts with 100000 lines (slow)
56 S 0; cat bigfile | parallel --pipe -n100000 cat '>lines-{#}'
57 T 1;
58 S 1; ls lines-*
59 T 3;
60 S 0; # Chop bigfile into parts each ~10mb (faster)
61 S 0; cat bigfile | parallel --pipe --block 10m cat '>10mb-{#}'
62 S 3; ls -l 10mb-*
63 T 1;
64 S 0; # Chop bigfile into one part per CPU thread (fastest)
65 S 0; parallel --pipepart -a bigfile --block -1 \
66 cat '>thread-part-{#}'
67 S 3; ls -l thread-part-*
68 T 1;
69 S 0; # Chop bigfile into one part per CPU thread - chop at 000\n
70 S 0; parallel --pipepart -a bigfile --block -1 --recend '000\n' \
71 cat '>p000-{#}'
72 T 3;
73 S 1; head -1 p000-*
74 T 3;
75 S 0; # Rename all files to UPPERCASE using a {= perl expr =}
76 S 3; parallel mv {} {= tr/a-z/A-Z/ =} ::: *
77 S 1; ls
78 T 3;
79 S 0; # Move files into dirs named after the last char in the name
80 S 1; parallel 'mkdir -p {= $_=chop =}; mv {} {= $_=chop =}' ::: *
81 S 1; ls
82 T 3;
83 S 0; # Zip dirs into files
84 S 1; parallel --ll --color --tag zip -r '{= s:/$:: =}'.zip {} ::: */
85 T 3;
86 S 0; # Remove the dirs
87 S 1; rm -r */
88 T 3;
89 S 0; # Unzip zip files into dirs
90 S 1; parallel --ll --tag 'mkdir {.}; cd {.}; unzip ../{}' ::: *.zip
91 T 3;
92 S 0; # Remove zip and dirs
93 S 1; rm -r *.zip ?
94 T 3;
95 S 0; # Paint output of the failing commands
96 S 1; parallel --colorfailed echo Arg:{} ';' exit {} ::: 0 0 1 2 0
97 T 3;
98 S 0; # Use a bash function with one argument
99 doit() {
100 echo Doing it for $1
101 sleep 2
102 echo Done with $1
104 export -f doit
105 S 1; parallel doit ::: 1 2 3
106 T 3;
107 S 0; # Use a bash function with two argument
108 doubleit() {
109 echo Doing it for $1 $2
110 sleep 2
111 echo Done with $1 $2
113 export -f doubleit
114 S 1; parallel doubleit ::: 1 2 3 ::: a b
115 T 3;
116 S 0; # Make some logfiles
117 S 1; touch log
118 S 1; parallel seq {} '>' log.{} ::: {1..10}
119 S 3; ls -l
120 T 1;
121 S 0; # Simple log rotate
122 S 3; seq 9 -1 1 | parallel -j1 mv log.{} log.'{= $_++ =}'
123 S 1; mv log log.1
124 S 3; ls -l
125 T 1;
126 S 0; # Monitor progress of multiple jobs in parallel
127 slowseq() { seq "$@" | pv -qL 20; }
128 export -f slowseq
129 S 1; parallel --ll --color --tag slowseq {} ::: 150 {1..60}
130 T 3;
132 exit
136 # $sleep = $sleep/2+100.001;
137 # $sleep = $sleep/2+100.001;
138 # $sleep = $sleep/2+100.001;
139 # return $ms/2+100.001;
140 # if($something_printed) { $ms = $ms/2+100.001; }
142 pwd=$(pwd)
143 tmp=$(mktemp -d)
144 cd "$tmp" &&
145 manuscript |
146 asciinema rec - | tee /tmp/parallel.c |
147 perl -ne 's/;?[ST] \d;\s?//;s/; [ST] \d//;
148 /###/ and $mark++ and next;
149 ($mark == 0 or $mark == 4) and print;
150 ' > "$pwd"/parallel.cast