| Hash | Commit message | Author | Date | Files | + | - |
1 | commit 139fe774c97ef2ce24f373ab63567c61f81c712a |
2 | Author: Connor Etherington <[email protected]> |
3 | Date: Sat Nov 11 04:34:45 2023 +0200 |
4 | |
5 | Auto-Commit Update - 20231111 |
6 | --- |
7 | PKGBUILD | 4 ++-- |
8 | usr/bin/psed | 44 ++++++++++++++++++++++++++++++++++++++++++++ |
9 | 2 files changed, 46 insertions(+), 2 deletions(-) |
10 | |
11 | diff --git a/PKGBUILD b/PKGBUILD |
12 | index 228d9cf..0abc3b4 100644 |
13 | --- a/PKGBUILD |
14 | +++ b/PKGBUILD |
15 | @@ -1,13 +1,13 @@ |
16 | # Maintainer: Connor Etherington <[email protected]> |
17 | # --- |
18 | pkgname=toolkit |
19 | -pkgver=0.1.0 |
20 | +pkgver=0.1.1 |
21 | pkgrel=1 |
22 | pkgdesc="A toolbox for the CLI, rapidly speeding up file editing and data management processes." |
23 | arch=(any) |
24 | url="https://gitlab.com/a4to/${pkgname}" |
25 | license=('MIT') |
26 | -depends=(bat) |
27 | +depends=(bat ruby) |
28 | optdepends=('nvim: the recommended editor for power users') |
29 | conflicts=(qed) |
30 | source=( |
31 | diff --git a/usr/bin/psed b/usr/bin/psed |
32 | new file mode 100755 |
33 | index 0000000..85c1011 |
34 | --- /dev/null |
35 | +++ b/usr/bin/psed |
36 | @@ -0,0 +1,44 @@ |
37 | +#!/usr/bin/env bash |
38 | + |
39 | +err(){ echo -e "\n[-] ERROR:[0;1m ${*}" && exit 1 ; } |
40 | + |
41 | +[[ -n $1 ]] || err "No arguments provided" |
42 | + |
43 | +inplace='' |
44 | +debug=0 |
45 | + |
46 | +while getopts ':id' opt; do |
47 | + case $opt in |
48 | + i) inplace='-i' ;; |
49 | + d) debug=1 ;; |
50 | + \?) echo "Invalid option: -$OPTARG" >&2; exit 1 ;; |
51 | + esac |
52 | +done |
53 | + |
54 | +shift $((OPTIND-1)) |
55 | + |
56 | +[[ $# -lt 2 ]] && { echo "Not enough arguments"; exit 1; } |
57 | + |
58 | +prepare_pattern() { |
59 | + local pattern=$1 |
60 | + pattern=$(echo -e "$pattern") |
61 | + pattern=$(echo "$pattern" | sed -E 's/([\/&])/\\&/g') |
62 | + echo "$pattern" |
63 | +} |
64 | + |
65 | +if [[ $1 =~ ^s/.* ]]; then |
66 | + pattern="$1" |
67 | + file="$2" |
68 | +else |
69 | + search=$(prepare_pattern "$1") |
70 | + replace=$(prepare_pattern "$2") |
71 | + pattern="s/$search/$replace/" |
72 | + file="$3" |
73 | +fi |
74 | + |
75 | +[[ -z "$file" ]] && { echo "No file provided"; exit 1; } |
76 | + |
77 | +[[ $debug -eq 1 ]] && echo "Debug: perl -0777 $inplace -pe \"$pattern\" \"$file\"" |
78 | + |
79 | +perl -0777 $inplace -pe "$pattern" "$file" |
80 | + |