commit b31fc81ccfb036349aef0e8f5fe74a0b12a8f17b
parent e392c6f7225bab70899a95afefac7a1165d88908
Author: Jacob R. Edwards <n/a>
Date: Wed, 17 Nov 2021 21:00:16 -0800
Rewrite the urls script and rename it to netquery
Now the main script is written in awk(1) which makes it much more
clean and simple in this case.
Diffstat:
6 files changed, 39 insertions(+), 32 deletions(-)
diff --git a/local/Makefile b/local/Makefile
@@ -6,10 +6,10 @@ MODULES =\
dillo\
git\
links\
+ netquery\
rc\
ssh\
sxiv\
- urls\
xenodm\
xmodmap\
xresources\
diff --git a/local/bin/bin/netquery b/local/bin/bin/netquery
@@ -0,0 +1,33 @@
+#!/usr/bin/awk -f
+# Copyright 2021 Jacob R. Edwards
+#
+# Find the url shortcut specified by the first argument and replace
+# `$query' with the subsequent arguments concatnated on `+'.
+
+
+BEGIN {
+ FS = " ";
+ for (i in ARGV) {
+ argv[i] = ARGV[i];
+ delete ARGV[i];
+ }
+
+ home = ENVIRON["XDG_CONFIG_HOME"];
+ if (!home)
+ home = ENVIRON["HOME"] "/.config";
+ ARGV[1] = home "/netquery";
+ ARGC = 2;
+}
+
+/^(#|$)/ { next }
+
+match($1, "^" argv[1] "$") > 0 {
+ query = argv[2];
+ for (i = 3; i < length(argv); ++i)
+ query = query "+" argv[i];
+ if (!sub("\\$query", query, $2)) {
+ printf "%s: No substitution made.\n", $1 > "/dev/stderr";
+ exit 1;
+ }
+ print $2;
+}
diff --git a/local/bin/bin/urls b/local/bin/bin/urls
@@ -1,24 +0,0 @@
-#!/bin/ksh
-# Copyright 2021 Jacob R. Edwards
-# License: GPLv3
-#
-# urls -- url shortcut
-
-set -o pipefail
-
-error() {
- echo "$1" 1>&2
- exit 1
-}
-
-find() {
- grep -m1 "^$1 " <"${XDG_CONFIG_HOME:-$HOME/.config}/urls" | cut -f2
-}
-
-insert() {
- sed "s/\$query/$(printf '%s%%20' $* | sed -e 's!/!\\/!g' -e 's/%20$//')/"
-}
-
-shortcut="$1"
-shift
-{ find "$shortcut" || error "$shortcut: Not found"; } | insert "$@"
diff --git a/local/bin/bin/xnetquery b/local/bin/bin/xnetquery
@@ -0,0 +1,5 @@
+#!/bin/sh
+# Copyright 2021 Jacob R. Edwards
+# Graphical netquery wrapper
+
+netquery $(dmenu -p netquery -w $(pfw) < /dev/null) | xgrab
diff --git a/local/bin/bin/xurls b/local/bin/bin/xurls
@@ -1,7 +0,0 @@
-#!/bin/sh
-# Copyright 2021 Jacob R. Edwards
-# License: GPLv3
-#
-# xurls -- X11 url shortcut
-
-urls $(dmenu -w $(pfw) -p search "$@" </dev/null) | xgrab
diff --git a/local/urls/config/urls b/local/netquery/config/netquery