diff --git a/README.md b/README.md index 76aa8d2..cbc312e 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,15 @@ You should now be able to use the plugin. Put `set -g @urlview-key 'x'` in `tmux.conf`. +> How can I use the default program FOO to get URLs explicitly? + +Put `set -g @urlview-extractor 'FOO'` in `tmux.conf`. The default is +`urlview` if available, or `extract_url`. + +> But I want to run FOO with command-line arguments '-a bar --b baz'! + +Fine. Use `set -g @urlview-extractor 'FOO -a bar --b baz'`. + ### Other goodies `tmux-urlview` works great with: diff --git a/urlview.tmux b/urlview.tmux index 88752ce..8d90d9b 100755 --- a/urlview.tmux +++ b/urlview.tmux @@ -4,29 +4,43 @@ get_tmux_option() { local option=$1 local default_value=$2 local option_value=$(tmux show-option -gqv "$option") - if [ -z $option_value ]; then - echo $default_value + if [ -z "$option_value" ]; then + echo "$default_value" else - echo $option_value + echo "$option_value" fi } find_executable() { + local extractor="$(get_tmux_option "@urlview-extractor")" + if type "${extractor%% *}" >/dev/null 2>&1; then + # FIXME: The %% idiom should work in sh, but it wasn't for me, so I + # reverted the interpreter to bash + echo "$extractor" + return + fi + tmux display-message "tmux-urlview: #{@urlview-extractor} not found" if type urlview >/dev/null 2>&1; then echo "urlview" - elif type extract_url >/dev/null 2>&1; then + return + fi + tmux display-message "tmux-urlview: urlview not found" + if type extract_url >/dev/null 2>&1; then echo "extract_url" + return fi + tmux display-message "tmux-urlview: extract_url not found" } readonly key="$(get_tmux_option "@urlview-key" "u")" readonly cmd="$(find_executable)" +readonly temp_file="$(mktemp --tmpdir tmux-urlview.XXX)" if [ -z "$cmd" ]; then - tmux display-message "Failed to load tmux-urlview: neither urlview nor extract_url were found on the PATH" + tmux display-message "Failed to load tmux-urlview: No extractor programs found" else tmux bind-key "$key" capture-pane -J \\\; \ - save-buffer "${TMPDIR:-/tmp}/tmux-buffer" \\\; \ + save-buffer "$temp_file" \\\; \ delete-buffer \\\; \ - split-window -l 10 "$cmd '${TMPDIR:-/tmp}/tmux-buffer'" + split-window -l 10 "$cmd '$temp_file'; rm '$temp_file' " fi