diff options
author | Wenxuan <wenxuangm@gmail.com> | 2018-04-06 19:33:36 +0800 |
---|---|---|
committer | Wenxuan <wenxuangm@gmail.com> | 2018-04-06 19:33:36 +0800 |
commit | 8060fb27ab5d25bf740091de9f0e73e885370dc4 (patch) | |
tree | 4e3b50e96f807bcaa810c766cf18eb48766939a0 | |
parent | 7c025728aefe0833df149ee06a5356b506ee46c9 (diff) | |
download | fork-tmux-fzf-url-8060fb27ab5d25bf740091de9f0e73e885370dc4.tar.gz fork-tmux-fzf-url-8060fb27ab5d25bf740091de9f0e73e885370dc4.tar.bz2 fork-tmux-fzf-url-8060fb27ab5d25bf740091de9f0e73e885370dc4.zip |
Add support for ip address
-rwxr-xr-x | fzf-url.sh | 33 | ||||
-rwxr-xr-x | fzf-url.tmux | 22 |
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"; |