-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathurlview.tmux
More file actions
executable file
·46 lines (42 loc) · 1.27 KB
/
urlview.tmux
File metadata and controls
executable file
·46 lines (42 loc) · 1.27 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/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() {
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"
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: No extractor programs found"
else
tmux bind-key "$key" capture-pane -J \\\; \
save-buffer "$temp_file" \\\; \
delete-buffer \\\; \
split-window -l 10 "$cmd '$temp_file'; rm '$temp_file' "
fi