-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmux-fzf-popup-default-command.pl
executable file
·205 lines (191 loc) · 4.85 KB
/
tmux-fzf-popup-default-command.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env perl
# fzf defaults to just the 'find' command. This perl script adds the following strings to fzf:
# - ~/.bash_history
# - fd . ~ || find ~
# - contents of nvim open files
# - contents of tmux pane history
# - ~/.fzf-default-strings contents
# - split all words found by spaces /@,\+()
# - allows for recall variables/words with minimum editing
use Time::HiRes qw(time);
# time how long it takes the script to run
$epoc_start = time(); # $epoc_stop = time() <- bottom "$epoc_stop - $epoc_start";
# - ~/.bash_history
foreach(`cat ~/.bash_history`) {
next if /^\s*$/;
chomp;
!$bash_history{$_}++;
}
# - ~/.fzf-default-strings
foreach(`cat ~/.fzf-default-strings`) {
next if /^\s*$/;
chomp;
!$fzf_default_strings{$_}++;
}
# - contents of nvim open files
# https://www.reddit.com/r/neovim/comments/w6fxhu/opened_files_in_neovim_from_the_command_line/
# lsof | grep nvim| awk '{ print $9 }' |grep .swp|cut -f2- -d%| sed -e 's!%!/!g' -e 's!.swp!!' -e 's!^!/!'
foreach(`lsof`) {
if(/$ENV{USER}/ && /nvim/ && /\s.+?(%.+\.swp)/) {
$fname=$1;
$fname=~s!\%!/!g;
$fname=~s!\.swp!!;
#print "$fname\n";
!$nvimfiles{$fname}++;
}
}
foreach(keys %nvimfiles) {
foreach(`cat $_`) {
next if /^\s*$/;
!$nvimfilescontents{$_}++;
}
}
# gets tmux history of just panes in current window (Default)
$tmux_list_panes="tmux list-panes";
# gets history of ALL panes, NOTE: this could take a long time
#$tmux_list_panes="tmux list-panes -a";
foreach(`tmux list-panes | cut -f 7 -d " "`) {
$pane_number=$_;
chomp $pane_number;
foreach(`tmux capture-pane -t $pane_number -pS -`) {
next if /^\s*$/;
!$lines{$_}++;
$pane_lines_count++;
if(/(".+")/) {
!$quotes{"$1"}++;
#print "2\" $1\n";
}
if(/"(.+)"/) {
#print "2\" $1\n";
!$quotes{"$1"}++;
}
}
}
# - contents of tmux pane history
# remove dupe words and store in %words_by_space
foreach $line (keys %lines) {
# finds default Ubuntu/Rocky prompts and store command for recall
if ( $line =~ /^\S+@\S+[\s|:]\S+[$|#]\s+(\S.+)/ ) {
#print "DB59: $1\n";
!$bash_commands{"$1"}++;
}
foreach(split /\s+/, $line) {
next if /^\s*$/;
$words_by_space{$_}++;
if ( m/^[^\p{PosixAlnum}]+/ or m/[^\p{PosixAlnum}]+$/ ) {
s/^[^\p{PosixAlnum}]+//g;
s/[^\p{PosixAlnum}]+$//g;
next if /^\s*$/;
!$strip_symbol_words{$_}++;
}
}
}
foreach (keys %words_by_space) {
if(m!/!) {
foreach(split /\//) {
!$words_by_symbol{$_}++;
}
}
if(/-/) {
foreach(split /-/) {
!$words_by_symbol{$_}++;
}
}
if(/_/) {
foreach(split /_/) {
!$words_by_symbol{$_}++;
}
}
if(/@/) {
foreach(split /@/) {
$words_by_symbol{$_}++;
}
}
if(/\./) {
foreach(split /\./) {
!$words_by_symbol{$_}++;
}
}
if(/\+/) {
foreach(split /\+/) {
!$words_by_symbol{$_}++;
}
}
if(/=/) {
foreach(split /=/) {
!$words_by_symbol{$_}++;
}
}
if(/"/) {
foreach(split /"/) {
!$words_by_symbol{$_}++;
}
}
if(/\(/) {
foreach(split /\(/) {
!$words_by_symbol{$_}++;
}
}
if(/\)/) {
foreach(split /\)/) {
!$words_by_symbol{$_}++;
}
}
}
# strip non-alphanumeric characters from beginning and end
foreach (keys %words_by_symbol) {
if ( m/^[^\p{PosixAlnum}]+/ or m/[^\p{PosixAlnum}]+$/ ) {
s/^[^\p{PosixAlnum}]+//g;
s/[^\p{PosixAlnum}]+$//g;
next if /^\s*$/;
!$strip_symbol_words{$_}++;
}
}
foreach(keys %fzf_default_strings) {
# print "DB156: $_";
!$ALL{$_}++;
}
foreach(keys %bash_history) {
!$ALL{$_}++;
}
foreach(keys %nvimfilescontents) {
!$ALL{$_}++;
}
foreach(keys %strip_symbol_words) {
!$ALL{$_}++;
}
foreach(keys %words_by_symbol) {
!$ALL{$_}++;
}
foreach(keys %words_by_space) {
!$ALL{$_}++;
}
foreach(keys %lines) {
chomp;
!$ALL{$_}++;
}
foreach(keys %bash_commands) {
!$ALL{$_}++;
}
# uses fd if found, but will fall back to find
$fdlocation=`which fd`;
chomp $fdlocation;
if ( -e "$fdlocation" ) {
$files_cmd='fd . ~';
} else {
$files_cmd="find ~ -not -path '*/.*'"
}
foreach(`$files_cmd`) {
chomp;
!$ALL{$_}++;
$file_count++;
}
foreach(keys %ALL) {
print "$_\n"
}
printf "file cmd: %s\n", $files_cmd;
printf "file count: %d\n", $file_count;
printf "pane lines count: %d\n", $pane_lines_count;
printf "total unique lines: %d\n", scalar keys %ALL;
$epoc_stop = time();
printf "script run time: %3.3f seconds\n", $epoc_stop - $epoc_start;