mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-12 16:10:07 +01:00
fix(tmux): fix feat: copyrat.tmux
This commit is contained in:
parent
ffd8e9b12d
commit
8e7b1a2d05
1 changed files with 26 additions and 12 deletions
38
copyrat.tmux
38
copyrat.tmux
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
# This scripts provides a default configuration for tmux-copyrat options and key bindings.
|
# This scripts provides a default configuration for tmux-copyrat options and key bindings.
|
||||||
# It is run only once at tmux launch.
|
# It is run only once at tmux launch.
|
||||||
|
|
@ -26,9 +26,14 @@
|
||||||
# You can also entirely ignore this file (not even source it) and define all
|
# You can also entirely ignore this file (not even source it) and define all
|
||||||
# options and bindings in your `tmux.conf`.
|
# options and bindings in your `tmux.conf`.
|
||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "$0" )" && pwd )"
|
||||||
BINARY="${CURRENT_DIR}/tmux-copyrat"
|
BINARY="${CURRENT_DIR}/tmux-copyrat"
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Top-level options
|
||||||
|
#
|
||||||
|
|
||||||
setup_option() {
|
setup_option() {
|
||||||
local opt_name=$1
|
local opt_name=$1
|
||||||
local default_value=$2
|
local default_value=$2
|
||||||
|
|
@ -38,10 +43,13 @@ setup_option() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Sets the window name when copyrat is run, providing a default in case
|
# Sets the window name which copyrat should use when running, providing a
|
||||||
# @copyrat-window-name was not defined.
|
# default value in case @copyrat-window-name was not defined.
|
||||||
setup_option "window-name" "[copyrat]"
|
setup_option "window-name" "[copyrat]"
|
||||||
|
|
||||||
|
# Get that window name as a local variable for use in pattern bindings below.
|
||||||
|
window_name=$(tmux show-option -gqv @copyrat-window-name)
|
||||||
|
|
||||||
# Sets the keytable for all bindings, providing a default if @copyrat-keytable was not defined.
|
# 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>
|
# Keytables open a new shortcut space: if 't' is the switcher (see below), prefix + t + <your-shortcut>
|
||||||
setup_option "keytable" "cpyrt"
|
setup_option "keytable" "cpyrt"
|
||||||
|
|
@ -50,15 +58,21 @@ setup_option "keytable" "cpyrt"
|
||||||
# providing a default if @copyrat-keyswitch is not defined.
|
# providing a default if @copyrat-keyswitch is not defined.
|
||||||
setup_option "keyswitch" "t"
|
setup_option "keyswitch" "t"
|
||||||
|
|
||||||
local keyswitch=$(tmux show-option @copyrat-keyswitch)
|
keyswitch=$(tmux show-option -gv @copyrat-keyswitch)
|
||||||
local keytable=$(tmux show-option @copyrat-keytable)
|
keytable=$(tmux show-option -gv @copyrat-keytable)
|
||||||
tmux bind-key ${keyswitch} -T ${keytable}
|
tmux bind-key ${keyswitch} switch-client -T ${keytable}
|
||||||
|
|
||||||
setup_binding() {
|
|
||||||
|
#
|
||||||
|
# Pattern bindings
|
||||||
|
#
|
||||||
|
|
||||||
|
setup_pattern_binding() {
|
||||||
local key=$1
|
local key=$1
|
||||||
local pattern_name="$2"
|
local pattern_arg="$2"
|
||||||
local window_name=$(tmux show-option -gqv @copyrat-window-name)
|
# The default window name `[copyrat]` has to be single quoted because it is
|
||||||
tmux bind-key -T ${keytable} $key new-window -d -n ${window_name} "${BINARY} --window-name ${window_name} --reverse --unique ${pattern_name}"
|
# interpreted by the shell when launched by tmux.
|
||||||
|
tmux bind-key -T ${keytable} ${key} new-window -d -n ${window_name} "${BINARY} --window-name '"${window_name}"' --reverse --unique-hint ${pattern_arg}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# prefix + t + p searches for absolute & relative paths
|
# prefix + t + p searches for absolute & relative paths
|
||||||
|
|
@ -89,7 +103,7 @@ setup_pattern_binding "6" "--pattern-name ipv6"
|
||||||
setup_pattern_binding "space" "--all-patterns"
|
setup_pattern_binding "space" "--all-patterns"
|
||||||
|
|
||||||
# prefix + t + / prompts for a pattern and search for it
|
# prefix + t + / prompts for a pattern and search for it
|
||||||
tmux bind-key -T ${keytable} "/" command-prompt -p "search:" 'new-window -d -n ${COPYRAT_WINDOW_NAME} "${BINARY} --window-name ${COPYRAT_WINDOW_NAME} --reverse --unique --custom-pattern %%"'
|
tmux bind-key -T ${keytable} "/" command-prompt -p "search:" "new-window -d -n '${window_name}' \"${BINARY}\" --window-name '${window_name}' --reverse --unique-hint --custom-pattern %%"
|
||||||
|
|
||||||
|
|
||||||
# Auto-install is currently disabled as it requires the user to have cargo installed.
|
# Auto-install is currently disabled as it requires the user to have cargo installed.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue