From 6aed1cecacb63b2ba3d3070aa992f3b65bdaa551 Mon Sep 17 00:00:00 2001 From: Tomasz Kapias Date: Fri, 1 Mar 2024 01:49:20 +0700 Subject: [PATCH] feat: secondary key-binding U - remove newlines from the capture before parsing --- README.md | 10 +++++++++- fzf-url.sh | 6 +++++- fzf-url.tmux | 5 ++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8505b7c..06863de 100644 --- a/README.md +++ b/README.md @@ -28,13 +28,20 @@ Clone this repo somewhere and source `fzf-url.tmux` at the config file. ### 📝 Usage -The default key-binding is `u`(of course prefix hit is needed), it can be modified by +The default main key-binding is `u`(of course prefix hit is needed), it can be modified by setting value to `@fzf-url-bind` at the tmux config like this: ``` tmux set -g @fzf-url-bind 'x' ``` +A secondary key-binding, eliminating newlines from the capture, is `U` , it can be modified by +setting value to `@fzf-url-bind-no-newlines`: + +``` tmux +set -g @fzf-url-bind-no-newlines 'X' +``` + You can also extend the capture groups by defining `@fzf-url-extra-filter`: ``` tmux @@ -68,6 +75,7 @@ set -g @fzf-url-open "firefox" - You can mark multiple urls and open them at once. - The tmux theme showed in the screenshot is [tmux-power](https://github.com/wfxr/tmux-power). +- The no-newlines key-binding is useful for some programs badly wrapping long Urls, e.g., neomutt mail client. ### 🔗 Other plugins diff --git a/fzf-url.sh b/fzf-url.sh index e240397..3b86197 100755 --- a/fzf-url.sh +++ b/fzf-url.sh @@ -17,7 +17,7 @@ fzf_filter() { custom_open=$3 open_url() { - if [[ -n $custom_open ]]; then + if [[ -n $custom_open ]]; then $custom_open "$@" elif hash xdg-open &>/dev/null; then nohup xdg-open "$@" @@ -37,6 +37,10 @@ else content="$(tmux capture-pane -J -p -e -S -"$limit")" fi +if [[ $4 == 'no-newlines' ]]; then + content=$(echo "$content" | tr -d '\n') +fi + urls=$(echo "$content" |grep -oE '(https?|ftp|file):/?//[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]') 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/') 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/') diff --git a/fzf-url.tmux b/fzf-url.tmux index 370af9a..eb2a7ee 100755 --- a/fzf-url.tmux +++ b/fzf-url.tmux @@ -15,9 +15,12 @@ tmux_get() { } key="$(tmux_get '@fzf-url-bind' 'u')" +key2="$(tmux_get '@fzf-url-bind-no-newlines' 'U')" history_limit="$(tmux_get '@fzf-url-history-limit' 'screen')" extra_filter="$(tmux_get '@fzf-url-extra-filter' '')" custom_open="$(tmux_get '@fzf-url-open' '')" echo "$extra_filter" > /tmp/filter -tmux bind-key "$key" run -b "$SCRIPT_DIR/fzf-url.sh '$extra_filter' $history_limit '$custom_open'"; +tmux bind-key "$key" run -b "$SCRIPT_DIR/fzf-url.sh '$extra_filter' $history_limit '$custom_open' ''"; +tmux bind-key "$key2" run -b "$SCRIPT_DIR/fzf-url.sh '$extra_filter' $history_limit '$custom_open' 'no-newlines'"; +