Skip to content

Commit

Permalink
Added @fzf-url-open (#36)
Browse files Browse the repository at this point in the history
* feature: added the setting 'custom_open' to specify a program to open the url/file. Can be used when xdg-open/open are installed but the user does not want to use them.

* refactor: moved $custom_open inside of open_url function

* docs: added fzf-url-open to the README.

* bugfix: added quotes around custom_open

---------

Co-authored-by: barts <[email protected]>
Co-authored-by: barts <[email protected]>
  • Loading branch information
3 people authored Sep 18, 2023
1 parent 93ca6fc commit 286eeca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ You can use custom fzf options by defining `@fzf-url-fzf-options`.
set -g @fzf-url-fzf-options '-w 50% -h 50% --multi -0 --no-preview --no-border'
```

By default, `tmux-fzf-url` will use `xdg-open`, `open`, or the `BROWSER`
environment variable to open the url, respectively. If you want to use a
different command, you can set `@fzf-url-open` to the command you want to use.

```tmux
set -g @fzf-url-open "firefox"
```

### 💡 Tips

- You can mark multiple urls and open them at once.
Expand Down
6 changes: 4 additions & 2 deletions fzf-url.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ fzf_filter() {
eval "fzf-tmux $(get_fzf_options)"
}

custom_open=$3
open_url() {
if hash xdg-open &>/dev/null; then
if [[ -n $custom_open ]]; then
$custom_open "$@"
elif hash xdg-open &>/dev/null; then
nohup xdg-open "$@"
elif hash open &>/dev/null; then
nohup open "$@"
Expand All @@ -25,7 +28,6 @@ open_url() {
fi
}


limit='screen'
[[ $# -ge 2 ]] && limit=$2

Expand Down
3 changes: 2 additions & 1 deletion fzf-url.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tmux_get() {
key="$(tmux_get '@fzf-url-bind' 'u')"
history_limit="$(tmux_get '@fzf-url-history-limit' 'screen')"
extra_filter="$(tmux_get '@fzf-url-extra-filter' '')"
custom_open="$(tmux_get '@fzf-url-open' '')"
echo "$extra_filter" > /tmp/filter

tmux bind-key "$key" run -b "$SCRIPT_DIR/fzf-url.sh '$extra_filter' $history_limit";
tmux bind-key "$key" run -b "$SCRIPT_DIR/fzf-url.sh '$extra_filter' $history_limit '$custom_open'";

0 comments on commit 286eeca

Please sign in to comment.