aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xfzf-url.sh33
-rwxr-xr-xfzf-url.tmux22
2 files changed, 40 insertions, 15 deletions
diff --git a/fzf-url.sh b/fzf-url.sh
new file mode 100755
index 0000000..3a99788
--- /dev/null
+++ b/fzf-url.sh
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+#===============================================================================
+# Author: Wenxuan
+# Email: wenxuangm@gmail.com
+# Created: 2018-04-06 12:12
+#===============================================================================
+
+fzf_cmd() {
+ fzf-tmux --multi --exit-0 --cycle --reverse --bind='ctrl-u:half-page-up' --bind='ctrl-d:half-page-down' --bind='ctrl-r:toggle-all' --bind='ctrl-s:toggle-sort'
+}
+
+if hash xdg-open &>/dev/null; then
+ open_cmd='nohup xdg-open'
+elif hash open &>/dev/null; then
+ open_cmd='open'
+fi
+
+content="$(tmux capture-pane -J -p)"
+urls=($(echo "$content" |grep -oE '\b(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]'))
+ips=($(echo "$content" |grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(:[0-9].*)?' | sed 's/\(.*\)/http:\/\/\1/'))
+
+merge() {
+ for item in "$@" ; do
+ echo "$item"
+ done
+}
+
+merge "${urls[@]}" "${ips[@]}" |
+ sort -u |
+ nl -w3 -s ' ' |
+ fzf_cmd |
+ awk '{print $2}'| xargs $open_cmd &>/dev/null ||
+ true
diff --git a/fzf-url.tmux b/fzf-url.tmux
index 8ac4b9e..a156cec 100755
--- a/fzf-url.tmux
+++ b/fzf-url.tmux
@@ -1,4 +1,10 @@
#!/usr/bin/env bash
+#===============================================================================
+# Author: Wenxuan
+# Email: wenxuangm@gmail.com
+# Created: 2018-04-06 09:30
+#===============================================================================
+SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) && cd "$SCRIPT_DIR"
# $1: option
# $2: default value
@@ -7,20 +13,6 @@ tmux_get() {
[ -n "$value" ] && echo $value || echo $2
}
-# $1: option
-# $2: value
-tmux_set() {
- tmux set-option -gq "$1" "$2"
-}
-
-fzf_cmd="fzf-tmux --multi --exit-0 --cycle --reverse --bind='ctrl-u:half-page-up' --bind='ctrl-d:half-page-down' --bind='ctrl-r:toggle-all' --bind='ctrl-s:toggle-sort'"
-url_regex='\b(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]'
-if hash xdg-open &>/dev/null; then
- open_cmd='nohup xdg-open'
-elif hash open &>/dev/null; then
- open_cmd='open'
-fi
-
key="$(tmux_get "@fzf-url-bind" "u")"
-tmux bind-key "$key" run -b "tmux capture-pane -J -p |grep -oE '"$url_regex"' |sort -u |nl -w3 -s' ' |$fzf_cmd |awk '{print \$2}'| xargs $open_cmd &>/dev/null || true";
+tmux bind-key "$key" run -b "$SCRIPT_DIR/fzf-url.sh";