CLI Magic Tricks for Docs Projects

A presentation at FOSDEM in February 2025 in Brussels, Belgium by Lorna Jane Mitchell

Slide 1

Slide 1

CLI Magic Tricks for Docs Projects Lorna Mitchell @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 2

Slide 2

Why, why, why …. CLI? Command line is a great interface choice: •use the same tools everywhere •transferrable CLI-wrangling skills •command names are searchable •scripts to save and replay commands @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 3

Slide 3

Reusable magic @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 4

Slide 4

Redirect operator Take the output and put it in a file. ls *.md > files_list.txt Capture output to share or use later @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 5

Slide 5

Pipe operator Send output of one command as input to another. grep -Ri Flamingo * | wc -l Tools each do one thing well. We combine them as we please. @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 6

Slide 6

Regular expressions “RegEx” is a way to describe complex and flexible character matching. /h.*p # matches “hip” “hoop” and “hippo camp” /^The # only matches The (or Theatre, etc) after a newline s/=/-/g # replace all = with - @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 7

Slide 7

Project structure @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 8

Slide 8

ls List command. ls ls ls ls ls ls .md **/.md -l -lt -ltr Use with cd to change directory. @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 9

Slide 9

tree Representation of files/folders tree tree -L 1 keys Also a good visualisation tool for including in docs. @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 10

Slide 10

wc Word count: counts lines (and words/bytes). wc wc wc wc -l index.md -w index.md .md guides/.md @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 11

Slide 11

Content wrangling @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 12

Slide 12

grep Find things (it’s a verb: to grep for …) grep -R png grep -Ri png | grep -v jetbrains grep -Ril png | grep -v jetbrains > files.txt grep -R ‘^## ’ * grep ‘[1]’ * grep ‘[1]’ * grep ‘^[[0-9]]’ * @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 13

Slide 13

sed Find and replace in multiple files. sed -i ‘s/Vale\b/VALE/g’ styles.md see also: vim macros, or IDE find/replace with regex. @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 14

Slide 14

Managing changes @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 15

Slide 15

diff Choose a diff tool to work with versions of content. cp index.md myindex.md vim myindex.md # make changes diff index.md myindex.md vimdiff index.md myindex.md Your Editor/IDE may have this feature. @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 16

Slide 16

git diff(tool) Git can show diffs in nice tools too git diff git difftool Configure it: git config diff.tool vimdiff @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 17

Slide 17

Content conversion @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 18

Slide 18

pandoc Pandoc is a document format conversion multitool. pandoc install.md -o install.pdf pandoc install.md -o install.html pandoc install.md -o install.rst Styles and templates can be adjusted. @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 19

Slide 19

convert Part of the ImageMagick library: converts images. • convert action.png -resize 10% •Resize •Reduce file size (compress) •Change image format action-new.png Also identify to check the properties of an image. @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 20

Slide 20

Scripting @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 21

Slide 21

Scripts are repeatable Write a shell script to use exactly the same commands every time. #!/bin/bash convert action.png -resize 10% action-new.png convert error.png -resize 10% error-new.png Scripts can accept input too @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 22

Slide 22

CLI Magic Tricks for Docs Projects @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 23

Slide 23

Resources •https://lornajane.net •https://wizardzines.com •https://www.writethedocs.org @lornajane@indieweb.social, @lornajane.net (bsky)

Slide 24

Slide 24

Extra jq tee xargs gh @lornajane@indieweb.social, @lornajane.net (bsky)