├── LICENSE.txt ├── cspell.json ├── fzf-url.tmux ├── fzf-url.sh └── README.md /LICENSE.txt: -------------------------------------------------------------------------------- 1 | https://wfxr.mit-license.org/2018 2 | -------------------------------------------------------------------------------- /cspell.json: -------------------------------------------------------------------------------- 1 | {"language":"en","flagWords":[],"words":["nohup","elif","wwws","npmjs"],"version":"0.2"} 2 | -------------------------------------------------------------------------------- /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 | echo "$extra_filter" > /tmp/filter 21 | 22 | tmux bind-key "$key" run -b "$SCRIPT_DIR/fzf-url.sh '$extra_filter' $history_limit"; 23 | -------------------------------------------------------------------------------- /fzf-url.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | get_fzf_options() { 4 | local fzf_options 5 | local fzf_default_options='-d 35% -m -0 --no-preview --no-border' 6 | fzf_options="$(tmux show -gqv '@fzf-url-fzf-options')" 7 | [ -n "$fzf_options" ] && echo "$fzf_options" || echo "$fzf_default_options" 8 | } 9 | 10 | fzf_filter() { 11 | eval "fzf-tmux $(get_fzf_options)" 12 | } 13 | 14 | open_url() { 15 | if hash xdg-open &>/dev/null; then 16 | nohup xdg-open "$@" 17 | elif hash open &>/dev/null; then 18 | nohup open "$@" 19 | elif [[ -n $BROWSER ]]; then 20 | nohup "$BROWSER" "$@" 21 | fi 22 | } 23 | 24 | limit='screen' 25 | [[ $# -ge 2 ]] && limit=$2 26 | 27 | if [[ $limit == 'screen' ]]; then 28 | content="$(tmux capture-pane -J -p)" 29 | else 30 | content="$(tmux capture-pane -J -p -S -"$limit")" 31 | fi 32 | 33 | urls=$(echo "$content" | grep -oE '(https?|ftp|file):/?//[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]') 34 | 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/') 35 | 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/') 36 | gits=$(echo "$content" | grep -oE '(ssh://)?git@\S*' | sed 's/:/\//g' | sed 's/^\(ssh\/\/\/\)\{0,1\}git@\(.*\)$/https:\/\/\2/') 37 | gh=$(echo "$content" | grep -oE "['\"]([A-Za-z0-9-]*/[.A-Za-z0-9-]*)['\"]" | sed "s/['\"]//g" | sed 's#.#https://github.com/&#') 38 | npm=$(echo "$content" | grep -oE "import\s+[^\"';]*[\"']([^.][^\"';]*)[\"']" | sed "s/[^'\"]*['\"]\([^'\"]*\)['\"];*/\1/" | sed 's@.@https:\/\/npmjs.com\/package\/&@') 39 | 40 | if [[ $# -ge 1 && "$1" != '' ]]; then 41 | extras=$(echo "$content" | eval "$1") 42 | fi 43 | 44 | items=$( 45 | printf '%s\n' "${urls[@]}" "${wwws[@]}" "${gh[@]}" "${npm[@]}" "${ips[@]}" "${gits[@]}" "${extras[@]}" | 46 | grep -v '^$' | 47 | sort -u | 48 | nl -w3 -s ' ' 49 | ) 50 | [ -z "$items" ] && tmux display 'tmux-fzf-url: no URLs found' && exit 51 | 52 | fzf_filter <<<"$items" | awk '{print $2}' | 53 | while read -r chosen; do 54 | open_url "$chosen" &>"/tmp/tmux-$(id -u)-fzf-url.log" 55 | done 56 | -------------------------------------------------------------------------------- /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 | 15 | - [tmux](https://github.com/tmux/tmux) (>= 3.2) 16 | - [tpm](https://github.com/tmux-plugins/tpm) 17 | - [`fzf`](https://github.com/junegunn/fzf) 18 | - [`bash`](https://www.gnu.org/software/bash/) 19 | 20 | **Install using [TPM](https://github.com/tmux-plugins/tpm)** 21 | 22 | Add this line to your tmux config file, then hit `prefix + I`: 23 | 24 | ```tmux 25 | set -g @plugin 'joshmedeski/tmux-fzf-url' 26 | ``` 27 | 28 | **Install manually** 29 | 30 | Clone this repo somewhere and source `fzf-url.tmux` at the config file. 31 | 32 | ### 📝 Usage 33 | 34 | The default key-binding is `u`(of course prefix hit is needed), it can be modified by 35 | setting value to `@fzf-url-bind` at the tmux config like this: 36 | 37 | ```tmux 38 | set -g @fzf-url-bind 'x' 39 | ``` 40 | 41 | You can also extend the capture groups by defining `@fzf-url-extra-filter`: 42 | 43 | ```tmux 44 | # simple example for capturing files like 'abc.txt' 45 | set -g @fzf-url-extra-filter 'grep -oE "\b[a-zA-Z]+\.txt\b"' 46 | ``` 47 | 48 | The plugin default captures the current screen. You can set `history_limit` to capture 49 | the scrollback history: 50 | 51 | ```tmux 52 | set -g @fzf-url-history-limit '2000' 53 | ``` 54 | 55 | You can use custom fzf options by defining `@fzf-url-fzf-options`. 56 | 57 | ``` 58 | # open tmux-fzf-url in a tmux v3.2+ popup 59 | set -g @fzf-url-fzf-options '-w 50% -h 50% --multi -0 --no-preview --no-border' 60 | ``` 61 | 62 | ### 💡 Tips 63 | 64 | - You can mark multiple urls and open them at once. 65 | - The tmux theme showed in the screenshot is [tmux-power](https://github.com/wfxr/tmux-power). 66 | 67 | ### 🔗 Other plugins 68 | 69 | - [tmux-power](https://github.com/wfxr/tmux-power) 70 | - [tmux-net-speed](https://github.com/wfxr/tmux-net-speed) 71 | 72 | ### 📃 License 73 | 74 | [MIT](https://wfxr.mit-license.org/2018) (c) Wenxuan Zhang 75 | --------------------------------------------------------------------------------