Commit 85cd526f64

85cd526f64e0555c721b24be65c67e8e50ac4f5c

Unsigned

Ilkay Alakay <ilkay@exherbo.domain.foo> · 2026-09-30 15:39 UTC

ilkay/ipatch: add README.md and ipatch

Layout: unified · split

README.md added +6
@@ -0,0 +1,6 @@
1# ipatch
2
3worlds most basic patching program written in bash *since my brain refuses to learn GNU patch*
4
5# installing (as root)
6chmod +x ipatch && mv ipatch /usr/local/bin
ipatch added +10
@@ -0,0 +1,10 @@
1#!/bin/bash
2[ $# -ne 3 ] && { echo "usage: ipatch <file> <line> <new line>"; exit 1; }
3f=$1 n=$2 new=$3
4[ -f "$f" ] || { echo "unable to find a file named $f"; exit 1; }
5[[ $n =~ ^[0-9]+$ ]] || { echo "<line> should be a number"; exit 1; }
6total=$(wc -l < "$f")
7(( n >= 1 && n <= total )) || { echo "<line> is out of range (1-$total)"; exit 1; }
8tmp=$(mktemp) || exit 1
9NEW=$new awk -v n="$n" 'NR==n{print ENVIRON["NEW"];next}1' "$f" > "$tmp" && cat "$tmp" > "$f"
10rm -f "$tmp"