Skip to content

Commit

Permalink
Make a more compelling svg demo
Browse files Browse the repository at this point in the history
  • Loading branch information
riquito committed Dec 30, 2023
1 parent 58687b1 commit d300d5a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 52 deletions.
4 changes: 4 additions & 0 deletions doc/example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
banana,apple,strawberry
red,white,yellow,pink,black,green
car,boat,bycicle,airplane
small,medium,large
90 changes: 39 additions & 51 deletions doc/screencast.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/bin/bash
# Designed to be executed via svg-term from the fd root directory:
# This script is a modified version of the one made by the good `fd` maintainers,
# see https://github.com/sharkdp/fd/blob/f227bb2/doc/screencast.sh
# Designed to be executed via svg-term from the root directory:
# svg-term --command="bash doc/screencast.sh" --out doc/screencast.svg --padding=10
# Then run this (workaround for #1003):
# First copy doc/example in root (and delete it afterward).
# Then run this (workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=1677988):
# sed -i '' 's/<text/<text font-size="1.67"/g' doc/screencast.svg
set -e
set -u
Expand All @@ -12,18 +15,34 @@ enter() {
INPUT="$1"
DELAY=1

prompt
immediate_prompt
sleep "$DELAY"
type "$INPUT"
sleep 0.5
printf '%b' "\\n"
# this is to ensure that we can have examples with \n and still display it
x=$(printf "$INPUT")
eval "$x"
}

comment() {
INPUT="$1"
DELAY=1

prompt
sleep "$DELAY"
type "$INPUT"
sleep 0.5
type "\\n"
}

immediate_prompt() {
printf '%b ' "$PROMPT"
}

prompt() {
printf '%b ' "$PROMPT" | pv -q
sleep 2 # give some time to read previous output
}

type() {
Expand All @@ -33,60 +52,29 @@ type() {
main() {
IFS='%'

enter "# Cut and rearrange fields..."
enter "echo 'foo bar baz' | tuc -d ' ' -f 3,2,1"

enter "# ...and join them back with the same delimiter"
enter "echo 'foo bar baz' | tuc -d ' ' -f 3,2,1 -j"

enter "# Replace the delimiter with something else"
enter "echo 'foo bar baz' | tuc -d ' ' -r ' ➡ '"

enter "# Keep a range of fields"
enter "echo 'foo bar baz' | tuc -d ' ' -f 2:"

enter "# Indexes can be negative and rearranged"
enter "echo 'a b c' | tuc -d ' ' -f -1,-2,-3"

enter "# Cut using regular expressions"
enter "echo 'a,b, c' | tuc -e '[, ]+' -f 1,3"

enter "# Emit JSON output"
enter "echo 'foo bar baz' | tuc -d ' ' --json"

enter "# Delimiters can be any number of characters long"
enter "echo 'a<sep>b<sep>c' | tuc -d '<sep>' -f 1,3"

enter "# Cut using a greedy delimiter"
enter "echo 'foo bar' | tuc -d ' ' -f 1,2 -g"

enter "# Format output"
enter "echo 'foo bar baz' | tuc -d ' ' -f '{1}, {2} and lastly {3}'"

enter "# ...with support for \\\\n"
enter "echo '100Kb README.txt 2049-02-01' | tuc -d ' ' -f '{2}\\\\n├── {1}\\\\n└── {3}'"

enter "# Cut lines (e.g. keep everything between first and last line)"
enter "printf 'a\\\\nb\\\\nc\\\\nd\\\\ne' | tuc -l 2:-2"

enter "# Concatenate lines (-l implies join with \\\\n, so we need --no-join)"
enter "printf 'a\\\\nb\\\\nc\\\\nd\\\\ne' | tuc -l 1,2 --no-join"
comment "# Given this example file"
enter "cat example"
echo
sleep 5

enter "# Compress delimiters after cut"
enter "echo 'foo bar baz' | tuc -d ' ' -f 2: -p"
comment "# Say you want to keep only the 2nd element in each line"
enter "cat example | tuc -d , -f 2"

enter "# Replace remaining delimiters with something else"
enter "echo 'foo bar baz' | tuc -d ' ' -f 2: -p -r ' -> '"
comment "# Let's keep just the last element of each line"
enter "cat example | tuc -d , -f -1"

enter "# Cut characters (expects UTF-8 input)"
enter "echo '😁🤩😝😎' | tuc -c 4,3,2,1"
comment "# What if I wanted to skip first and last line?"
enter "cat example | tuc -l 2:-2"

enter "# Cut bytes (the following emoji are 4 bytes each)"
enter "echo '😁🤩😝😎' | tuc -b 5:8"
comment "# Let's make it json"
enter "cat example | tuc -d , --json"

enter "# Discard selected fields, keep the rest"
enter "echo 'a b c' | tuc --complement -d ' ' -f 2"
comment "# We can also format the output to do nifty things"
comment "# Imagine you have .bak files and you want to rename them"
comment "# (the file names would come from 'find' or similar tools)"
enter "echo somefile.bak | tuc -d '.bak' -f 'mv {1}.bak {1}'"

comment "# You can do much more than this. Check the documentation!"
prompt

sleep 3
Expand Down
2 changes: 1 addition & 1 deletion doc/screencast.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d300d5a

Please sign in to comment.