A presentation at FOSDEM in February 2025 in Brussels, Belgium by Lorna Jane Mitchell
CLI Magic Tricks for Docs Projects Lorna Mitchell @lornajane@indieweb.social, @lornajane.net (bsky)
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)
Reusable magic @lornajane@indieweb.social, @lornajane.net (bsky)
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)
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)
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)
Project structure @lornajane@indieweb.social, @lornajane.net (bsky)
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)
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)
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)
Content wrangling @lornajane@indieweb.social, @lornajane.net (bsky)
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)
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)
Managing changes @lornajane@indieweb.social, @lornajane.net (bsky)
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)
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)
Content conversion @lornajane@indieweb.social, @lornajane.net (bsky)
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)
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)
Scripting @lornajane@indieweb.social, @lornajane.net (bsky)
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)
CLI Magic Tricks for Docs Projects @lornajane@indieweb.social, @lornajane.net (bsky)
Resources •https://lornajane.net •https://wizardzines.com •https://www.writethedocs.org @lornajane@indieweb.social, @lornajane.net (bsky)
Extra jq tee xargs gh @lornajane@indieweb.social, @lornajane.net (bsky)
View CLI Magic Tricks for Docs Projects on Notist.
Dismiss