about summary refs log tree commit diff stats
path: root/bin/fl
diff options
context:
space:
mode:
Diffstat (limited to 'bin/fl')
-rwxr-xr-xbin/fl32
1 files changed, 32 insertions, 0 deletions
diff --git a/bin/fl b/bin/fl
new file mode 100755
index 0000000..8c058d7
--- /dev/null
+++ b/bin/fl
@@ -0,0 +1,32 @@
+#!/bin/sh
+# fl: Find Links
+# uses regular expressions to find links in the stream it's given,
+# or its args if it is given args
+
+# from pure-sh-bible, strips from the start of a string
+lstrip() {
+	printf '%s\n' "${1##$2}"
+}
+
+# put url-finding regex in a variable so no lines go over 80 chars
+re_urls='((https?://|www\.)[[:alnum:].]*:?[[:alnum:]./@$&%?$#=_-]*)'
+
+# finds links, puts them in a list
+# sort -u prevents duplicates, but also sorts the links
+urlparse() {
+	lstrip "$(cat)" "*\│" |\
+	grep -Eo "$re_urls" |\
+	sort -u | sed 's|^www.|http://www\.|g'
+}
+if [ -n "$1" ]; then
+	urls=$(echo "$@"|urlparse)
+else
+	urls=$(urlparse)
+fi
+
+# wipe IFS so dmenu handles being sent the links properly
+IFS=
+
+# send any found links to dmenu so one can be chosen to be sent to the clipboard
+[ -n "$urls" ] &&\
+	echo $urls | dmenu -i -p 'copy which url?' -l 10 | xclip -r -sel c
\ No newline at end of file
-0800 7690' href='/akkartik/mu/commit/apps/tui.mu?h=hlt&id=74f1512ff113cf35706af57e9d40c78b7d77f49e'>74f1512f ^
41535426 ^
74f1512f ^
41535426 ^
7ecfd5eb ^
41535426 ^

74f1512f ^
8c78c3eb ^
74f1512f ^

c8e41a47 ^
9511ff5c ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34