tmux-copyrat/copyrat.tmux

68 lines
2.6 KiB
Text
Raw Normal View History

2020-05-28 07:07:51 +02:00
#!/usr/bin/env bash
2020-06-03 23:55:09 +02:00
# This script is run only once at tmux launch.
# It provides configuration based on the @copyrat-* options set in your `tmux.conf`.
2020-05-28 07:07:51 +02:00
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2020-06-03 23:55:09 +02:00
BINARY="${CURRENT_DIR}/tmux-copyrat"
setup_option() {
local opt_name=$1
local default_value=$2
local current_value=$(tmux show-option -gqv @copyrat-${opt_name})
value=${current_value:-${default_value}}
tmux set-option -g @copyrat-${opt_name} ${value}
}
# Sets the window name when copyrat is run, providing a default if @copyrat-window-name was not defined.
setup_option "window-name" "[copyrat]"
# DEFAULT_COPYRAT_WINDOW_NAME="[copyrat]"
# COPYRAT_WINDOW_NAME=$(tmux show-option -gqv @copyrat-window-name)
# COPYRAT_WINDOW_NAME=${COPYRAT_WINDOW_NAME:-$DEFAULT_COPYRAT_WINDOW_NAME}
# # overrides with the same value, I did not bother writing a test
# tmux set-option -g @copyrat-window-name ${COPYRAT_WINDOW_NAME}
# Sets the keytable for all bindings, providing a default if @copyrat-keytable was not defined.
# Keytables open a new shortcut space: if 't' is the switcher (see below), prefix + t + <your-shortcut>
setup_option "keytable" "cpyrt"
# DEFAULT_COPYRAT_KEYTABLE="cpyrt"
# COPYRAT_KEYTABLE=$(tmux show-option -gqv @copyrat-keytable)
# COPYRAT_KEYTABLE=${COPYRAT_KEYTABLE:-$DEFAULT_COPYRAT_KEYTABLE}
# Sets the key to access the keytable: prefix + <key> + <your-shortcut>
# providing a default if @copyrat-keyswitch is not defined.
setup_option "keyswitch" "u"
local keyswitch=$(tmux show-option @copyrat-keyswitch)
local keytable=$(tmux show-option @copyrat-keytable)
tmux bind-key ${keyswitch} -T ${keytable}
setup_binding() {
local key=$1
local pattern_name=$2
local window_name=$(tmux show-option -gqv @copyrat-window-name)
tmux bind-key -T ${keytable} $key new-window -d -n ${window_name} "${BINARY} --window-name ${window_name} --reverse --unique"
}
2020-05-28 07:07:51 +02:00
2020-06-03 23:55:09 +02:00
# Search
setup_pattern_binding "space" ""
setup_pattern_binding "p" "--pattern-name path"
setup_pattern_binding "u" "--pattern-name url"
setup_pattern_binding "h" "--pattern-name sha"
setup_pattern_binding "d" "--pattern-name docker"
setup_pattern_binding "c" "--pattern-name hexcolor"
setup_pattern_binding "i" "--pattern-name ip"
2020-05-28 07:07:51 +02:00
2020-06-03 23:55:09 +02:00
# DEFAULT_COPYRAT_KEY="space"
# COPYRAT_KEY=$(tmux show-option -gqv @copyrat-key)
# COPYRAT_KEY=${COPYRAT_KEY:-$DEFAULT_COPYRAT_KEY}
2020-05-29 11:50:19 +02:00
2020-05-28 07:07:51 +02:00
2020-06-03 23:55:09 +02:00
# tmux bind-key -T ${keytable} "/" command-prompt "search:" new-window -d -n ${COPYRAT_WINDOW_NAME} "${BINARY} --window-name ${COPYRAT_WINDOW_NAME} --reverse --unique --custom-regex '%%'"
2020-05-28 07:07:51 +02:00
2020-06-03 23:55:09 +02:00
# if [ ! -f "$BINARY" ]; then
# cd "${CURRENT_DIR}" && cargo build --release
# fi