r/bash

pdfmt - I wrote a multi tool, cause I got tired of manual duplex scanning for my family's paperwork
▲ 28 r/bash+1 crossposts

pdfmt - I wrote a multi tool, cause I got tired of manual duplex scanning for my family's paperwork

Taking over the paperwork for my aging parents meant dealing with a mountain of legacy documents and a Brother ADF scanner that is quite fast but only supports simplex. Being happily frugal, I wasn't about to drop money on a new duplex scanner while my current hardware works totally fine. Handling mixed stacks of single- and double-sided pages through GUI tools became a massive time bottleneck.

So, I wrote several simple scripts to do the dirty work for me. All those scripts evolved into a lightweight, transparent CLI tool to automate the work without any heavy frameworks or bloat.

Instead of clicking through endless menus, moving pages in previews, and so on I can now process stacks right from the terminal with an easy interface:

# Example 1: 
# Scan a stack of 1-page documents (invoices, delivery notes, etc.) via ADF and split it into individual files with prefix "invoice_"
# Workflow:
# - scan all invoices
# - split all pages into individual files with prefix "invoice_"

pdfmt scan adf invoices.pdf
pdfmt split all invoices.pdf invoice_



# Example 2: 
# Scan a stack of 2-sided documents (1 physical sheet, printed on both sides), but your scanner _DOES NOT_ have a duplex ADF.
# Workflow:
# - scan all front sides
# - flip the stack over, put it back in the ADF, and scan the back sides
# - merge both files in correct page order
# - split the result into chunks of 2 pages with prefix document_

pdfmt scan adf front.pdf
pdfmt scan adf back.pdf
pdfmt merge duplex front.pdf back.pdf documents.pdf
pdfmt split length 2 documents.pdf document_

It's built for a real-world workflow to handle thousands of documents, saved me weeks of time, works on Linux, macOS (and WSL) and you can easily integrate it into your own scripts and workflows. There are more features in this tool, check out the readme.

If you deal with similar paper hell or just like simple CLI tools, check it out here:

👉 https://www.github.com/eifelcode/pdfmt

I'm also open for feedback on how to improve my script, architecture and workflow. =)

AI notice: AI (mistral) was used to generate parts of the README.md, the .github workflow, the code coverage tool, and parts of the unit tests in the tests/ folder. Architecture, Makefile, and code within the sources/ folder is written by me

u/eifelcode — 7 days ago
▲ 25 r/bash

Parsing ipv6 with pure bash is actually my villain origin story

Genuinely thought writing a quick validation script for some access logs would take 10 minutes. ipv4? fine, simple regex, four octets, we move on.

But ipv6 is just cruel. The double colons, the omitted leading zeros, the hex formatting. Trying to catch all the valid shorthand abbreviations using just standard sed and grep is completely rotting my brain.

I was staring at a helpful guide just trying to map out every single possible way a v6 address can be legally formatted in the wild, and about halfway through I just realized doing this in pure shell is a massive mistake.

Why do we torture ourselves trying to build bulletproof parsers in bash? Im literally just going to pipe the logs to a python script with the ipaddress module tomorrow. My regex days are over tbh.

reddit.com
u/ImpressiveAnt3405 — 8 days ago
▲ 31 r/bash

For some reason, when I run this script, it always plays the same song.

When I run ls ~/Music/ | shuf | tail -1 | read file && echo $file it gives a random output as expected, but every time I run this script it plays a file labeled "3S.mp3" exclusively, which just so happens to be the first one in the list when I run ls

Does anyone know what could be causing this?

u/MonkiWasTooked — 10 days ago
▲ 15 r/bash

TIL command_not_found_handle

You don’t want to know what hoops I’ve jumped through to implement FPATH in bash. Then today I innocently asked GPT how it would implement FPATH in bash and it introduced me to this hook.

Now have to go home now get rid of a lot of needless code. Oh well. Less code is the best code!

reddit.com
u/mpersico — 9 days ago