extract_url

This commit is contained in:
Motiejus Jakštys 2024-04-15 14:50:52 +03:00 committed by Motiejus Jakštys
parent bd53176626
commit 221ae40e4f
3 changed files with 60 additions and 0 deletions

View File

@ -67,6 +67,8 @@ in {
home.packages = with pkgs;
lib.mkMerge [
[extract_url]
(lib.mkIf devTools [
pkgs-unstable.go_1_22
zig
@ -203,6 +205,12 @@ in {
set-option -sg escape-time 10
set-option -g default-terminal "screen-256color"
set-option -sa terminal-features ',xterm-256color:RGB'
run-shell ${(pkgs.substituteAll {
src = ./urlview.tmux;
extract_url = pkgs.extract_url;
})
.outPath}
'';
};
}

View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
get_tmux_option() {
local option=$1
local default_value=$2
local option_value
option_value=$(tmux show-option -gqv "$option")
if [ -z "$option_value" ]; then
echo "$default_value"
else
echo "$option_value"
fi
}
readonly key="$(get_tmux_option "@urlview-key" "u")"
tmux bind-key "$key" capture-pane -J \\\; \
save-buffer "${TMPDIR:-/tmp}/tmux-buffer" \\\; \
delete-buffer \\\; \
split-window -l 10 "@extract_url@/bin/extract_url" '${TMPDIR:-/tmp}/tmux-buffer'"

32
shared/home/urlview.tmux Normal file
View File

@ -0,0 +1,32 @@
#!/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 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 "$cmd '${TMPDIR:-/tmp}/tmux-buffer'"
fi