diff options
author | vg <vgm+dev@devys.org> | 2025-09-24 16:14:20 +0200 |
---|---|---|
committer | vg <vgm+dev@devys.org> | 2025-09-24 16:14:20 +0200 |
commit | 48290dbfd2a33909856149d5031c8c94130ebeda (patch) | |
tree | 60250a3696fd9d4313a00ce7f03d545e6293958a | |
parent | b2d63addc5322267e3f85f2c01411fd68c498081 (diff) | |
download | fork-tmux-fzf-url-48290dbfd2a33909856149d5031c8c94130ebeda.tar.gz fork-tmux-fzf-url-48290dbfd2a33909856149d5031c8c94130ebeda.tar.bz2 fork-tmux-fzf-url-48290dbfd2a33909856149d5031c8c94130ebeda.zip |
simplify url management and allow [digit] context keeping
-rwxr-xr-x | fzf-url.sh | 31 |
1 files changed, 17 insertions, 14 deletions
@@ -44,23 +44,26 @@ else content="$(tmux capture-pane -J -p -S -"$limit")" fi -mapfile -t urls < <(echo "$content" |grep -oE '(https?|ftp|file):/?//[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]') -mapfile -t wwws < <(echo "$content" |grep -oE '(http?s://)?www\.[a-zA-Z](-?[a-zA-Z0-9])+\.[a-zA-Z]{2,}(/\S+)*' | grep -vE '^https?://' |sed 's/^\(.*\)$/http:\/\/\1/') -mapfile -t ips < <(echo "$content" |grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(:[0-9]{1,5})?(/\S+)*' |sed 's/^\(.*\)$/http:\/\/\1/') -mapfile -t gits < <(echo "$content" |grep -oE '(ssh://)?git@\S*' | sed 's/:/\//g' | sed 's/^\(ssh\/\/\/\)\{0,1\}git@\(.*\)$/https:\/\/\2/') +# debug +#exec >/tmp/url.log 2>&1 +#set -x -if [[ $# -ge 1 && "$1" != '' ]]; then - mapfile -t extras < <(echo "$content" |eval "$1") -fi - -items=$(printf '%s\n' "${urls[@]}" "${wwws[@]}" "${ips[@]}" "${gits[@]}" "${extras[@]}" | - grep -v '^$' | - nl -w3 -s ' ' +regexes=( + '(\[\d+\]\s*)?(https?|ftp|file):/?//[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]' + '(\[\d+\]\s*)?\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d{1,5})?(/\S+)*' + '(\[\d+\)\s*)?(ssh://)?git@\S*' ) -[ -z "$items" ] && tmux display 'tmux-fzf-url: no URLs found' && exit -mapfile -t chosen < <(fzf_filter <<< "$items" | awk '{print $2}') +urls=() +for regex in "${regexes[@]}"; do + mapfile -t -O "${#urls[@]}" urls < \ + <(printf "%s\n" "$content" | grep -Po -- "$regex") +done + +[ "${#urls[@]}" -eq 0 ] && tmux display 'tmux-fzf-url: no URLs found' && exit + +mapfile -t chosen < <(fzf_filter <<< "$(printf "%s\n" "${urls[@]}")") for item in "${chosen[@]}"; do - open_url "$item" &>"/tmp/tmux-$(id -u)-fzf-url.log" + open_url "$(printf "%s" "$item" | grep -Po '^\s*(\[\d+\])?\s*\K.*$')" &>"/tmp/tmux-$(id -u)-fzf-url.log" done |