aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Bobov <anton@bobov.name>2024-05-18 00:30:06 +0500
committerAnton Bobov <anton@bobov.name>2024-05-18 00:38:51 +0500
commita8b4132b7a5fe99ca1d5b9d575b377be078ee43e (patch)
tree9bd94f1d83c9fd616bced43c8b083b4feb2789dd
parent7515d6b576fe5f56462c5c2fdcc298c75b8c9dab (diff)
[tmux] Replace copycat with native search
-rwxr-xr-xfiles/.config/tmux/scripts/search35
-rw-r--r--files/.config/tmux/tmux.conf7
2 files changed, 41 insertions, 1 deletions
diff --git a/files/.config/tmux/scripts/search b/files/.config/tmux/scripts/search
new file mode 100755
index 0000000..027f789
--- /dev/null
+++ b/files/.config/tmux/scripts/search
@@ -0,0 +1,35 @@
+#!/bin/bash
+# From https://github.com/toupeira/dotfiles/blob/main/config/tmux/scripts/search
+
+set -euo pipefail
+
+search() {
+ tmux send-keys -X search-backward "$1"
+}
+
+search_string() {
+ tmux send-keys "?"
+}
+
+search_path() {
+ # pattern from copycat https://github.com/tmux-plugins/tmux-copycat/blob/d7f7e6c1de0bc0d6915f4beea5be6a8a42045c09/copycat.tmux#L21
+ # "(^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]*"
+ path='[-_.[:alnum:]]'
+ search "~?(/$path+|$path+/|$path*\.$path+)+$path*(:[0-9]+)*"
+}
+
+search_interesting() {
+ urls='(https?://|git@|git://|ssh://|ftp://|file:///)[[:alnum:]?=%/_.:,;~@!#$&()*+-]*'
+ emails='[-_\.[:alnum:]]+@[-_\.[:alnum:]]+'
+ hashes='\b(([0-9a-f]{7,40}|[[:alnum:]]{52}|[0-9a-f]{64})(\.{2,3})?)+\b'
+ ips='[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}'
+
+ search "($urls|$emails|$hashes|$ips)"
+}
+
+main() {
+ tmux copy-mode
+ "search_${1:-string}"
+}
+
+main "$@"
diff --git a/files/.config/tmux/tmux.conf b/files/.config/tmux/tmux.conf
index 5ba8335..9ec8220 100644
--- a/files/.config/tmux/tmux.conf
+++ b/files/.config/tmux/tmux.conf
@@ -58,6 +58,12 @@ bind BTab swap-pane -t -
# Status bar
set -g status-right "$USER@#h %H:%M"
+# Search
+search='~/.config/tmux/scripts/search'
+bind / run "$search"
+bind -n C-F run "$search path"
+bind -n C-G run "$search interesting"
+
set -g @colors-solarized 'light'
# To Install Plugin: <Prefix> + I
@@ -72,7 +78,6 @@ set -g @plugin 'seebi/tmux-colors-solarized'
set -g @plugin 'christoomey/vim-tmux-navigator'
set -g @plugin 'tmux-plugins/tmux-pain-control'
set -g @plugin 'tmux-plugins/tmux-yank'
-set -g @plugin 'tmux-plugins/tmux-copycat'
set -g @plugin 'tmux-plugins/tmux-open'
set -g @plugin 'tmux-plugins/tmux-resurrect'