aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWenxuan Zhang <wenxuangm@gmail.com>2020-09-05 12:37:59 +0800
committerWenxuan Zhang <wenxuangm@gmail.com>2020-09-05 12:40:58 +0800
commit64da84f1664494681348785f125ce400af4f593a (patch)
tree31ccdde5885c314ad52504468578664bb2d94c56
parent74d4f13c98cec03e4243adf719275ad880dabde0 (diff)
downloadfork-tmux-fzf-url-64da84f1664494681348785f125ce400af4f593a.tar.gz
fork-tmux-fzf-url-64da84f1664494681348785f125ce400af4f593a.tar.bz2
fork-tmux-fzf-url-64da84f1664494681348785f125ce400af4f593a.zip
feat: support custom filter #7
-rw-r--r--README.md7
-rwxr-xr-xfzf-url.sh10
-rwxr-xr-xfzf-url.tmux4
3 files changed, 17 insertions, 4 deletions
diff --git a/README.md b/README.md
index 211559c..b11b526 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,13 @@ setting value to `@fzf-url-bind` at the tmux config like this:
set -g @fzf-url-bind 'x'
```
+You can also extend the capture groups by defining `@fzf-url-extra-filter`:
+
+``` tmux
+# simple example for capturing files like 'abc.txt'
+set -g @fzf-url-extra-filter 'grep -oE "\b[a-zA-Z]+\.txt\b"'
+```
+
### 💡 Tips
- Use `tab` to mark multiple urls and open them at once.
diff --git a/fzf-url.sh b/fzf-url.sh
index 09be041..70b2d39 100755
--- a/fzf-url.sh
+++ b/fzf-url.sh
@@ -9,7 +9,7 @@ fzf_cmd() {
fzf-tmux -d 35% --multi --exit-0 --cycle --reverse --bind='ctrl-r:toggle-all' --bind='ctrl-s:toggle-sort' --no-preview
}
-if hash xdg-open &>/dev/null; then
+if hash xdg-open &>/dev/null; then
open_cmd='nohup xdg-open'
elif hash open &>/dev/null; then
open_cmd='open'
@@ -23,16 +23,20 @@ wwws=($(echo "$content" |grep -oE 'www\.[a-zA-Z](-?[a-zA-Z0-9])+\.[a-zA-Z]{2,}(/
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/'))
gits=($(echo "$content" |grep -oE '(ssh://)?git@\S*' | sed 's/:/\//g' | sed 's/^\(ssh\/\/\/\)\{0,1\}git@\(.*\)$/https:\/\/\2/'))
+if [[ $# -ge 1 && "$1" != '' ]]; then
+ extras=($(echo "$content" |eval "$1"))
+fi
+
merge() {
for item in "$@" ; do
echo "$item"
done
}
-merge "${urls[@]}" "${wwws[@]}" "${ips[@]}" "${gits[@]}"|
+merge "${urls[@]}" "${wwws[@]}" "${ips[@]}" "${gits[@]}" "${extras[@]}"|
sort -u |
nl -w3 -s ' ' |
fzf_cmd |
awk '{print $2}'|
- xargs -n1 -I {} $open_cmd {} &>/dev/null ||
+ xargs -n1 -I {} "$open_cmd" {} &>/dev/null ||
true
diff --git a/fzf-url.tmux b/fzf-url.tmux
index f4ab019..6eb145c 100755
--- a/fzf-url.tmux
+++ b/fzf-url.tmux
@@ -15,5 +15,7 @@ tmux_get() {
}
key="$(tmux_get '@fzf-url-bind' 'u')"
+extra_filter="$(tmux_get '@fzf-url-extra-filter' '')"
+echo "$extra_filter" > /tmp/filter
-tmux bind-key "$key" run -b "$SCRIPT_DIR/fzf-url.sh";
+tmux bind-key "$key" run -b "$SCRIPT_DIR/fzf-url.sh '$extra_filter'";