summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrique <me@gilgalab.com>2021-05-13 13:41:19 -0400
committerHenrique <me@gilgalab.com>2021-05-13 13:41:19 -0400
commit912a0c2420de01ad7c78e72eeca1aa6161d09df1 (patch)
tree770e9819a77577ec38a470ab92d1a84cb48c0ab5
parent4caefea46a2fced85c6849de4526161a5c0b32aa (diff)
downloadfork-tmux-urlscan-fzf-912a0c2420de01ad7c78e72eeca1aa6161d09df1.tar.gz
fork-tmux-urlscan-fzf-912a0c2420de01ad7c78e72eeca1aa6161d09df1.tar.bz2
fork-tmux-urlscan-fzf-912a0c2420de01ad7c78e72eeca1aa6161d09df1.zip
First commit
-rwxr-xr-xtmux-urlscan-fzf.sh24
-rwxr-xr-xtmux-urlscan-fzf.tmux14
2 files changed, 38 insertions, 0 deletions
diff --git a/tmux-urlscan-fzf.sh b/tmux-urlscan-fzf.sh
new file mode 100755
index 0000000..7e80702
--- /dev/null
+++ b/tmux-urlscan-fzf.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+fzf_filter() {
+ fzf-tmux -d 50% -m -0 --no-preview -p
+}
+
+open_url() {
+ if command -v xdg-open &>/dev/null; then
+ nohup xdg-open "$@"
+ elif command -v open &>/dev/null; then
+ nohup open "$@"
+ elif [[ -n $BROWSER ]]; then
+ nohup "$BROWSER" "$@"
+ fi
+}
+
+content="$(tmux capture-pane -J -p)"
+
+items=$(echo $content|urlscan -n -c -d)
+mapfile -t chosen < <(fzf_filter <<< "$items")
+
+for item in "${chosen[@]}"; do
+ open_url "$item"
+done
diff --git a/tmux-urlscan-fzf.tmux b/tmux-urlscan-fzf.tmux
new file mode 100755
index 0000000..26429a3
--- /dev/null
+++ b/tmux-urlscan-fzf.tmux
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
+
+# $1: option
+# $2: default value
+tmux_get() {
+ local value
+ value="$(tmux show -gqv "$1")"
+ [ -n "$value" ] && echo "$value" || echo "$2"
+}
+
+key="$(tmux_get '@fzf-url-bind' 'u')"
+
+tmux bind-key "$key" run -b "$SCRIPT_DIR/tmux-urlscan-fzf.sh";