-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathurlview.tmux
More file actions
executable file
·33 lines (29 loc) · 873 Bytes
/
urlview.tmux
File metadata and controls
executable file
·33 lines (29 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env bash
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
else
echo $option_value
fi
}
find_executable() {
if type urlview >/dev/null 2>&1; then
echo "urlview"
elif type extract_url >/dev/null 2>&1; then
echo "extract_url"
fi
}
readonly key="$(get_tmux_option "@urlview-key" "u")"
readonly reader="$(get_tmux_option "@urlview-reader" "cat")"
readonly cmd="$(find_executable)"
if [ -z "$cmd" ]; then
tmux display-message "Failed to load tmux-urlview: neither urlview nor extract_url were found on the PATH"
else
tmux bind-key "$key" capture-pane -J \\\; \
save-buffer "${TMPDIR:-/tmp}/tmux-buffer" \\\; \
delete-buffer \\\; \
split-window -l 10 "$reader '${TMPDIR:-/tmp}/tmux-buffer' | $cmd"
fi