aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2017-02-13 01:08:15 +0100
committerDuncaen <mail@duncano.de>2017-02-13 01:10:58 +0100
commitf871abfffe3162084ab014477f1ad74ed77604bd (patch)
treec410c1666f4f80504669571cd99c6f59caac6287
parent9ca97c271a5779735c0f14ee860fa4426e062441 (diff)
downloaddotfiles-f871abfffe3162084ab014477f1ad74ed77604bd.tar.gz
bin: add grurls
-rwxr-xr-xbin/grurls28
1 files changed, 28 insertions, 0 deletions
diff --git a/bin/grurls b/bin/grurls
new file mode 100755
index 0000000..e6b2e39
--- /dev/null
+++ b/bin/grurls
@@ -0,0 +1,28 @@
+#!/bin/awk -f
+# grurls - substitute and group urls
+
+BEGIN {
+ i = 0
+}
+END {
+ for (l = 0; l < i; l++) {
+ printf "[%d] %s\n", l, links[l]
+ }
+}
+{
+ # [title](url)
+ while (match($0, /\[[^]]*\]\([^)]*\)/)) {
+ lnk = substr($0, RSTART, RLENGTH)
+ match(lnk, /\[[^]]*\]/)
+ t = substr(lnk, RSTART+1, RLENGTH-2)
+ match(lnk,/\([^)]*\)/)
+ links[i] = substr(lnk, RSTART+1, RLENGTH-2)
+ sub(/\[[^]]*\]\([^)]*\)/, t " [" i++ "]")
+ }
+ # http[s]://foo/bar
+ while (match($0, /http[s]?:\/\/[^ ]*/)) {
+ links[i] = substr($0, RSTART, RLENGTH)
+ sub(/http[s]?:\/\/[^ ]*/, "[" i++ "]")
+ }
+ print
+}