~yerinalexey/dotfiles

ref: 144a38b0aa0a39003633d53b77fe4e3ca29c054b dotfiles/scripts/copy-link -rwxr-xr-x 476 bytes
144a38b0Alexey Yerin river,update-volume: fix old wob crashes 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/sh -e

# Copy a link in the text stream

# Read until EOF
links="$(while read -r ln; do echo "$ln"; done | \
	awk '{
	# Thanks to https://ihateregex.io/expr/url/
	matches = match($0, /(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]+\.[a-zA-Z0-9]{1,6}\B([-a-zA-Z0-9!@:%_+.~#?&/\/=]*))/)

	if (matches) {
		print substr($0, matches, RLENGTH)
	}
}')"

if [ -z "$links" ]; then
	printf "No links found\n"
	exit 1
fi

selected="$(printf "%s" "$links" | fzf)"

wl-copy "$selected"