From 0622ab7bf68416ccd7e559ca1b1507f0b32628b7 Mon Sep 17 00:00:00 2001 From: graelo Date: Thu, 4 Jun 2020 08:03:59 +0200 Subject: [PATCH] chore(docs): add doc to feat: copyrat.tmux --- copyrat.tmux | 66 +++++++++++++++++++++++++++++++++++--------------- src/regexes.rs | 2 +- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/copyrat.tmux b/copyrat.tmux index 45a6bf7..d6b3f1b 100755 --- a/copyrat.tmux +++ b/copyrat.tmux @@ -1,7 +1,28 @@ #!/usr/bin/env bash -# This script is run only once at tmux launch. -# It provides configuration based on the @copyrat-* options set in your `tmux.conf`. +# This scripts provides a default configuration for tmux-copyrat options and key bindings. +# It is run only once at tmux launch. +# +# Each option and binding can be overridden in your `tmux.conf` by defining options like +# +# set -g @copyrat-keytable "foobar" +# set -g @copyrat-keyswitch "z" +# set -g @copyrat-match-bg "magenta" +# +# and bindings like +# +# bind-key -T foobar h new-window -d -n "[copyrat]" '/path/to/tmux-copyrat --window-name "[copyrat]" --pattern-name urls' +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +# +# changing this will probably break integration - +# +# Just make sure you first open a named window in the background and provide that name to tmux-copyrat. +# +# Don't even try to run tmux-copyrat with run-shell, this cannot work because Tmux launches these processes +# without attaching them to a pty. + +# You could also entirely ignore this file (not even source it) and define all options and bindings +# in your `tmux.conf`. CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" BINARY="${CURRENT_DIR}/tmux-copyrat" @@ -18,22 +39,13 @@ setup_option() { # 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 + 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 + + # providing a default if @copyrat-keyswitch is not defined. -setup_option "keyswitch" "u" +setup_option "keyswitch" "t" local keyswitch=$(tmux show-option @copyrat-keyswitch) local keytable=$(tmux show-option @copyrat-keytable) @@ -46,22 +58,36 @@ setup_binding() { tmux bind-key -T ${keytable} $key new-window -d -n ${window_name} "${BINARY} --window-name ${window_name} --reverse --unique" } -# Search +# prefix + t + Space searches for all known regexes (noisy and slower) setup_pattern_binding "space" "" +# prefix + t + p searches for absolute & relative paths setup_pattern_binding "p" "--pattern-name path" +# prefix + t + u searches for URLs setup_pattern_binding "u" "--pattern-name url" +# prefix + t + m searches for Markdown URLs [...](matched.url) +setup_pattern_binding "m" "--pattern-name markdown-url" +# prefix + t + h searches for SHA1/2 (hashes) setup_pattern_binding "h" "--pattern-name sha" -setup_pattern_binding "d" "--pattern-name docker" +# prefix + t + e searches for email addresses (see https://www.regular-expressions.info/email.html) +setup_pattern_binding "e" "--pattern-name email" +# prefix + t + D searches for docker shas +setup_pattern_binding "D" "--pattern-name docker" +# prefix + t + c searches for hex colors #aa00f5 setup_pattern_binding "c" "--pattern-name hexcolor" -setup_pattern_binding "i" "--pattern-name ip" - -# DEFAULT_COPYRAT_KEY="space" -# COPYRAT_KEY=$(tmux show-option -gqv @copyrat-key) -# COPYRAT_KEY=${COPYRAT_KEY:-$DEFAULT_COPYRAT_KEY} - +# prefix + t + U searches for UUIDs +setup_pattern_binding "U" "--pattern-name uuid" +# prefix + t + d searches for any string of 4+ digits +setup_pattern_binding "d" "--pattern-name digits" +# prefix + t + m searches for hex numbers: 0xbedead +setup_pattern_binding "m" "--pattern-name mem-address" +# prefix + t + 4 searches for IPV4 +setup_pattern_binding "4" "--pattern-name ipv4" +# prefix + t + 6 searches for IPV6 +setup_pattern_binding "6" "--pattern-name ipv6" # 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 '%%'" +# Auto-install is currently disabled as it requires the user to have cargo installed. # if [ ! -f "$BINARY" ]; then # cd "${CURRENT_DIR}" && cargo build --release # fi diff --git a/src/regexes.rs b/src/regexes.rs index 9bb81fa..89001b0 100644 --- a/src/regexes.rs +++ b/src/regexes.rs @@ -28,7 +28,7 @@ pub const PATTERNS: [(&'static str, &'static str); 15] = [ ("ipv4", r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"), ("ipv6", r"[A-f0-9:]+:+[A-f0-9:]+[%\w\d]+"), ("mem-address", r"0x[0-9a-fA-F]+"), - ("number", r"[0-9]{4,}"), + ("digits", r"[0-9]{4,}"), ]; /// Type-safe string Pattern Name (newtype).