mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-11-24 23:17:55 +00:00
asciinema-manuscript: Initial release.
This commit is contained in:
parent
477c86c778
commit
4307949091
142
src/asciinema-manuscript
Executable file
142
src/asciinema-manuscript
Executable file
|
@ -0,0 +1,142 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright (C) 2007-2022 Ole Tange, http://ole.tange.dk and Free
|
||||
# Software Foundation, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <https://www.gnu.org/licenses/>
|
||||
# or write to the Free Software Foundation, Inc., 51 Franklin St,
|
||||
# Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2021-2022 Ole Tange, http://ole.tange.dk and Free Software and Foundation, Inc.
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
# tty1: asciinema rec demo.cast
|
||||
# tty2: asciinema-manuscript
|
||||
# Run commands in tty2 to set clipboard to next command
|
||||
|
||||
manuscript() {
|
||||
# <digit> sleep this many seconds before executing command
|
||||
cat <<'_'
|
||||
###
|
||||
# Definitions
|
||||
PS1='$ '
|
||||
S() { sleep $@; }
|
||||
T() { echo -n '$ '; sleep $@; echo; }
|
||||
# Wait for asciinema to read all input
|
||||
sleep 5
|
||||
###
|
||||
S 0; # Make some files
|
||||
S 3; seq 100 | parallel --bar seq {}0000 '>' file-{}
|
||||
T 1;
|
||||
S 0; # gzip files with -1 .. -7 Note how all combinations are made
|
||||
S 3; parallel --bar gzip {1} '<{2}' '>{2}{1}.gz' ::: -{1..7} ::: *
|
||||
T 1;
|
||||
S 0; # Count the bytes in some files. Each job gets its own color
|
||||
S 3; parallel --color --tag wc {} ::: file-99*
|
||||
T 1;
|
||||
S 0; # Remove .gz-files
|
||||
S 3; rm *.gz
|
||||
T 1;
|
||||
S 0; # Make a big file
|
||||
S 3; seq 10000000 > bigfile
|
||||
T 1;
|
||||
S 0; # Chop bigfile into parts with 100000 lines (slow)
|
||||
S 3; cat bigfile | parallel --pipe -n100000 cat '>lines-{#}'
|
||||
S 3; ls lines-*
|
||||
T 1;
|
||||
S 0; # Chop bigfile into parts each ~10mb (faster)
|
||||
S 3; cat bigfile | parallel --pipe --block 10m cat '>10mb-{#}'
|
||||
S 3; ls -l 10mb-*
|
||||
T 1;
|
||||
S 0; # Chop bigfile into one part per CPU thread (fastest)
|
||||
S 3; parallel --pipepart -a bigfile --block -1 \
|
||||
cat '>thread-part-{#}'
|
||||
S 3; ls -l thread-part-*
|
||||
T 1;
|
||||
S 0; # Chop bigfile into one part per CPU thread - chop at 000\n
|
||||
S 3; parallel --pipepart -a bigfile --block -1 --recend '000\n' \
|
||||
cat '>p000-{#}'
|
||||
S 3; head -1 p000-*
|
||||
T 1;
|
||||
S 0; # Rename all files to UPPERCASE using a {= perl expr =}
|
||||
S 3; parallel mv {} {= tr/a-z/A-Z/ =} ::: *
|
||||
S 3; ls
|
||||
T 1;
|
||||
S 0; # Move files into dirs named after the last char in the name
|
||||
S 3; parallel 'mkdir -p {= $_=chop =}; mv {} {= $_=chop =}' ::: *
|
||||
S 3; ls
|
||||
T 1;
|
||||
S 0; # Zip dirs into files
|
||||
S 3; parallel --ll --color --tag zip -r '{= s:/$:: =}'.zip {} ::: */
|
||||
T 1;
|
||||
S 0; # Remove the dirs
|
||||
S 3; rm -r */
|
||||
T 1;
|
||||
S 0; # Unzip zip files into dirs
|
||||
S 3; parallel --ll --tag 'mkdir {.}; cd {.}; unzip ../{}' ::: *.zip
|
||||
T 1;
|
||||
S 0; # Remove zip and dirs
|
||||
S 3; rm -r *.zip ?
|
||||
T 1;
|
||||
S 0; # Paint output of the failing commands
|
||||
S 3; parallel --colorfailed echo Arg:{} ';' exit {} ::: 0 0 1 2 0
|
||||
T 1;
|
||||
S 0; # Use a bash function with one argument
|
||||
doit() {
|
||||
echo Doing it for $1
|
||||
sleep 2
|
||||
echo Done with $1
|
||||
}
|
||||
export -f doit
|
||||
S 3; parallel doit ::: 1 2 3
|
||||
T 1;
|
||||
S 0; # Use a bash function with two argument
|
||||
doubleit() {
|
||||
echo Doing it for $1 $2
|
||||
sleep 2
|
||||
echo Done with $1 $2
|
||||
}
|
||||
export -f doubleit
|
||||
S 3; parallel doubleit ::: 1 2 3 ::: a b
|
||||
T 1;
|
||||
S 0; # Make some logfiles
|
||||
S 1; touch log
|
||||
S 3; parallel seq {} '>' log.{} ::: {1..10}
|
||||
S 3; ls -l
|
||||
T 1;
|
||||
S 0; # Simple log rotate
|
||||
S 3; seq 9 -1 1 | parallel -j1 mv log.{} log.'{= $_++ =}'
|
||||
S 1; mv log log.1
|
||||
S 3; ls -l
|
||||
T 1;
|
||||
S 0; # Monitor progress of multiple jobs in parallel
|
||||
slowseq() { seq "$@" | pv -qL 20; }
|
||||
export -f slowseq
|
||||
S 3; parallel --ll --color --tag slowseq {} ::: 150 {1..60}
|
||||
T 3;
|
||||
###
|
||||
exit
|
||||
_
|
||||
}
|
||||
|
||||
pwd=$(pwd)
|
||||
tmp=$(mktemp -d)
|
||||
cd "$tmp" &&
|
||||
manuscript |
|
||||
parallel -j1 echo '{= s/^(\d+)\s/sleep($1);""/e; =}' |
|
||||
asciinema rec - |
|
||||
perl -ne 's/[ST] \d;\s?//;
|
||||
/###/ and $mark++ and next;
|
||||
($mark == 0 or $mark == 5) and print;
|
||||
' > "$pwd"/parallel.cast
|
Loading…
Reference in a new issue