├── FUNDING.yml ├── LICENSE.txt ├── README.md ├── fzf-url.sh └── fzf-url.tmux /FUNDING.yml: -------------------------------------------------------------------------------- 1 | ko_fi: wfxr 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | https://wfxr.mit-license.org/2018 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tmux-fzf-url 2 | 3 | [![TPM](https://img.shields.io/badge/tpm--support-true-blue)](https://github.com/tmux-plugins/tpm) 4 | [![Awesome](https://img.shields.io/badge/Awesome-tmux-d07cd0?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAABVklEQVRIS+3VvWpVURDF8d9CRAJapBAfwWCt+FEJthIUUcEm2NgIYiOxsrCwULCwktjYKSgYLfQF1JjCNvoMNhYRCwOO7HAiVw055yoBizvN3nBmrf8+M7PZsc2RbfY3AfRWeNMSVdUlHEzS1t6oqvt4n+TB78l/AKpqHrdwLcndXndU1WXcw50k10c1PwFV1fa3cQVzSR4PMd/IqaoLeIj2N1eTfG/f1gFVtQMLOI+zSV6NYz4COYFneIGLSdZSVbvwCMdxMsnbvzEfgRzCSyzjXAO8xlHcxMq/mI9oD+AGlhqgxjD93OVOD9TUuICdXd++/VeAVewecKKv2NPlfcHUAM1qK9FTnBmQvJjkdDfWzzE7QPOkAfZiEce2ECzhVJJPHWAfGuTwFpo365pO0NYjmEFr5Eas4SPeJfll2rqb38Z7/yaaD+0eNM3kPejt86REvSX6AamgdXkgoxLxAAAAAElFTkSuQmCC)](https://github.com/rothgar/awesome-tmux) 5 | [![License](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://wfxr.mit-license.org/2018) 6 | 7 | A tmux plugin for opening urls from browser quickly without mouse. 8 | 9 | ![screenshot](https://raw.githubusercontent.com/wfxr/i/master/tmux-fzf-url.gif) 10 | 11 | ### 📥 Installation 12 | 13 | Prerequisites: 14 | * [`fzf`](https://github.com/junegunn/fzf) 15 | * [`bash`](https://www.gnu.org/software/bash/) 16 | 17 | **Install using [TPM](https://github.com/tmux-plugins/tpm)** 18 | 19 | Add this line to your tmux config file, then hit `prefix + I`: 20 | 21 | ``` tmux 22 | set -g @plugin 'wfxr/tmux-fzf-url' 23 | ``` 24 | 25 | **Install manually** 26 | 27 | Clone this repo somewhere and source `fzf-url.tmux` at the config file. 28 | 29 | ### 📝 Usage 30 | 31 | The default key-binding is `u`(of course prefix hit is needed), it can be modified by 32 | setting value to `@fzf-url-bind` at the tmux config like this: 33 | 34 | ``` tmux 35 | set -g @fzf-url-bind 'x' 36 | ``` 37 | 38 | You can also extend the capture groups by defining `@fzf-url-extra-filter`: 39 | 40 | ``` tmux 41 | # simple example for capturing files like 'abc.txt' 42 | set -g @fzf-url-extra-filter 'grep -oE "\b[a-zA-Z]+\.txt\b"' 43 | ``` 44 | 45 | The plugin default captures the current screen. You can set `history_limit` to capture 46 | the scrollback history: 47 | 48 | ```tmux 49 | set -g @fzf-url-history-limit '2000' 50 | ``` 51 | 52 | You can use custom fzf options by defining `@fzf-url-fzf-options`. 53 | 54 | ``` 55 | # open tmux-fzf-url in a tmux v3.2+ popup 56 | set -g @fzf-url-fzf-options '-w 50% -h 50% --multi -0 --no-preview --no-border' 57 | ``` 58 | 59 | By default, `tmux-fzf-url` will use `xdg-open`, `open`, or the `BROWSER` 60 | environment variable to open the url, respectively. If you want to use a 61 | different command, you can set `@fzf-url-open` to the command you want to use. 62 | 63 | ```tmux 64 | set -g @fzf-url-open "firefox" 65 | ``` 66 | 67 | ### 💡 Tips 68 | 69 | - You can mark multiple urls and open them at once. 70 | - The tmux theme showed in the screenshot is [tmux-power](https://github.com/wfxr/tmux-power). 71 | 72 | ### 🧩 Similar projects 73 | 74 | - [tmux-fzf-links](https://github.com/alberti42/tmux-fzf-links): A more versatile tmux plugin that allows you to search for and open links. 75 | 76 | ### 🔗 Other plugins 77 | 78 | - [tmux-power](https://github.com/wfxr/tmux-power) 79 | - [tmux-net-speed](https://github.com/wfxr/tmux-net-speed) 80 | 81 | ### 📃 License 82 | 83 | [MIT](https://wfxr.mit-license.org/2018) (c) Wenxuan Zhang 84 | -------------------------------------------------------------------------------- /fzf-url.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #=============================================================================== 3 | # Author: Wenxuan 4 | # Email: wenxuangm@gmail.com 5 | # Created: 2018-04-06 12:12 6 | #=============================================================================== 7 | get_fzf_options() { 8 | local fzf_options 9 | local fzf_default_options='-w 100% -h 50% --multi -0 --no-preview' 10 | fzf_options="$(tmux show -gqv '@fzf-url-fzf-options')" 11 | [ -n "$fzf_options" ] && echo "$fzf_options" || echo "$fzf_default_options" 12 | } 13 | 14 | fzf_filter() { 15 | eval "fzf-tmux $(get_fzf_options)" 16 | } 17 | 18 | custom_open=$3 19 | open_url() { 20 | if [[ -n $custom_open ]]; then 21 | $custom_open "$@" 22 | elif hash xdg-open &>/dev/null; then 23 | nohup xdg-open "$@" 24 | elif hash open &>/dev/null; then 25 | nohup open "$@" 26 | elif [[ -n $BROWSER ]]; then 27 | nohup "$BROWSER" "$@" 28 | fi 29 | } 30 | 31 | limit='screen' 32 | [[ $# -ge 2 ]] && limit=$2 33 | 34 | if [[ $limit == 'screen' ]]; then 35 | content="$(tmux capture-pane -J -p -e |sed -r 's/\x1B\[[0-9;]*[mK]//g'))" 36 | else 37 | content="$(tmux capture-pane -J -p -e -S -"$limit" |sed -r 's/\x1B\[[0-9;]*[mK]//g'))" 38 | fi 39 | 40 | urls=$(echo "$content" |grep -oE '(https?|ftp|file):/?//[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]') 41 | 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/') 42 | 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/') 43 | gits=$(echo "$content" |grep -oE '(ssh://)?git@\S*' | sed 's/:/\//g' | sed 's/^\(ssh\/\/\/\)\{0,1\}git@\(.*\)$/https:\/\/\2/') 44 | gh=$(echo "$content" |grep -oE "['\"]([_A-Za-z0-9-]*/[_.A-Za-z0-9-]*)['\"]" | sed "s/['\"]//g" | sed 's#.#https://github.com/&#') 45 | 46 | if [[ $# -ge 1 && "$1" != '' ]]; then 47 | extras=$(echo "$content" |eval "$1") 48 | fi 49 | 50 | items=$(printf '%s\n' "${urls[@]}" "${wwws[@]}" "${gh[@]}" "${ips[@]}" "${gits[@]}" "${extras[@]}" | 51 | grep -v '^$' | 52 | sort -u | 53 | nl -w3 -s ' ' 54 | ) 55 | [ -z "$items" ] && tmux display 'tmux-fzf-url: no URLs found' && exit 56 | 57 | fzf_filter <<< "$items" | awk '{print $2}' | \ 58 | while read -r chosen; do 59 | open_url "$chosen" &>"/tmp/tmux-$(id -u)-fzf-url.log" 60 | done 61 | -------------------------------------------------------------------------------- /fzf-url.tmux: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #=============================================================================== 3 | # Author: Wenxuan 4 | # Email: wenxuangm@gmail.com 5 | # Created: 2018-04-06 09:30 6 | #=============================================================================== 7 | SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) 8 | 9 | # $1: option 10 | # $2: default value 11 | tmux_get() { 12 | local value 13 | value="$(tmux show -gqv "$1")" 14 | [ -n "$value" ] && echo "$value" || echo "$2" 15 | } 16 | 17 | key="$(tmux_get '@fzf-url-bind' 'u')" 18 | history_limit="$(tmux_get '@fzf-url-history-limit' 'screen')" 19 | extra_filter="$(tmux_get '@fzf-url-extra-filter' '')" 20 | custom_open="$(tmux_get '@fzf-url-open' '')" 21 | echo "$extra_filter" > /tmp/filter 22 | 23 | tmux bind-key "$key" run -b "$SCRIPT_DIR/fzf-url.sh '$extra_filter' $history_limit '$custom_open'"; 24 | --------------------------------------------------------------------------------