about summary refs log blame commit diff stats
path: root/bin/fl
blob: 1a2d0f772e8beef5be297e7468fc955daac9df78 (plain) (tree)
1
2
3
4
5
6
7
8
9
10






                                                                  
                                

 

                                                                             



                                                       

                                                                        
                             

                                              

                       
 
                                                                                 


                            
#!/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}"
}

# url-finding regex
re_urls='(((https?|aesgcm)://|www\.)[[:alnum:].]*:?[[:alnum:]./@$&%?$#=_-]*)'

# finds links, puts them in a list
# sort -u prevents duplicates, but also sorts the links
urlparse() {
	input="$(if [ -n "$1" ]; then printf '%s\n' "$*"; else cat; fi)"
	lstrip "$input" "*\│" |
	grep -Eo "$re_urls" |
	sort -u | sed 's|^www.|http://www\.|g'
}

set -- $(urlparse "$@")

# send any found links to select so one can be chosen to be sent to the clipboard
for url; do
	printf '%s\n' "$url"
done