-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmy.zshrc
620 lines (530 loc) · 21.3 KB
/
my.zshrc
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
## -*- mode: sh -*-
export HISTFILE=$TRU_HISTFILE
export HISTSIZE=5000000
export SAVEHIST=1000000
# setopt HIST_FIND_NO_DUPS
setopt EXTENDED_HISTORY
# https://github.com/zsh-users/zsh-autosuggestions#suggestion-highlight-style
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=99,underline"
# ZSH_AUTOSUGGEST_STRATEGY=(history completion)
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
ZSH_AUTOSUGGEST_USE_ASYNC=1
ZSH_AUTOSUGGEST_MANUAL_REBIND=1
ZSH_AUTOSUGGEST_COMPLETION_IGNORE='( |man |pikaur -S )*'
# _per-directory-history-set-global-history # set per directory default to glboal
# This query will find the most frequently issued command
# that is issued in the current directory or any subdirectory.
# You can get other behaviours by changing the query, for example
_zsh_autosuggest_strategy_histdb_top_here() {
local query="select commands.argv from
history left join commands on history.command_id = commands.rowid
left join places on history.place_id = places.rowid
where places.dir LIKE '$(sql_escape $PWD)%'
and commands.argv LIKE '$(sql_escape $1)%'
group by commands.argv order by count(*) desc limit 1"
suggestion=$(_histdb_query "$query")
}
# https://www.dev-diaries.com/blog/terminal-history-auto-suggestions-as-you-type/
# This will find the most frequently issued command issued exactly in this directory,
# or if there are no matches it will find the most frequently issued command in any directory.
# You could use other fields like the hostname to restrict to suggestions on this host, etc.
_zsh_autosuggest_strategy_histdb_top() {
local query="select commands.argv from
history left join commands on history.command_id = commands.rowid
left join places on history.place_id = places.rowid
where commands.argv LIKE '$(sql_escape $1)%'
group by commands.argv
order by places.dir != '$(sql_escape $PWD)', count(*) desc limit 1"
suggestion=$(_histdb_query "$query")
}
# Query to pull in the most recent command if anything was found similar
# in that directory. Otherwise pull in the most recent command used anywhere
# Give back the command that was used most recently
_zsh_autosuggest_strategy_histdb_top_fallback() {
local query="
select commands.argv from
history left join commands on history.command_id = commands.rowid
left join places on history.place_id = places.rowid
where places.dir LIKE
case when exists(select commands.argv from history
left join commands on history.command_id = commands.rowid
left join places on history.place_id = places.rowid
where places.dir LIKE '$(sql_escape $PWD)'
AND commands.argv LIKE '$(sql_escape $1)%')
then '$(sql_escape $PWD)'
else '%'
end
and commands.argv LIKE '$(sql_escape $1)%'
order by places.dir LIKE '$(sql_escape $PWD)' desc,
history.id desc
limit 1"
suggestion=$(_histdb_query "$query")
}
_zsh_autosuggest_strategy_histdb_here_fallback() {
local current_dir=$PWD
local all_parents=("$current_dir")
while [ "$current_dir" != "/" ]; do
all_parents+=("$current_dir%")
current_dir=$(dirname "$current_dir")
done
all_parents+=("/%")
for parent in "${all_parents[@]}"; do
local query="select commands.argv from
history left join commands on history.command_id = commands.rowid
left join places on history.place_id = places.rowid
where places.dir LIKE '$(sql_escape $parent)'
and commands.argv LIKE '$(sql_escape $1)%'
group by commands.argv order by history.id desc limit 1"
# debug
#echo $query
local result=$(_histdb_query "$query")
if [[ -n $result ]]; then
suggestion=$result
break
fi
done
}
_zsh_autosuggest_strategy_histdb_here_fallback2() {
local current_dir=$PWD
local all_parents=("$current_dir")
while [ "$current_dir" != "/" ]; do
all_parents+=("$current_dir%")
current_dir=$(dirname "$current_dir")
done
all_parents+=("/%")
# https://stackoverflow.com/questions/50427449/behavior-of-arrays-in-bash-scripting-and-zsh-shell-start-index-0-or-1
local query="WITH RECURSIVE search_dir AS (
SELECT 1 AS level, '$(echo ${all_parents[@]:0:1})' AS dir
UNION ALL
SELECT level + 1, CASE level + 1"
local i=2
for dir in "${all_parents[@]:1}"; do
query="$query WHEN $i THEN '$dir'
"
i=$((i + 1))
done
query="$query ELSE '%' END FROM search_dir WHERE level < $i
)
SELECT commands.argv
FROM history
LEFT JOIN commands ON history.command_id = commands.rowid
LEFT JOIN places ON history.place_id = places.rowid
WHERE places.dir LIKE
(SELECT dir FROM search_dir WHERE EXISTS (
SELECT 1
FROM history
LEFT JOIN commands ON history.command_id = commands.rowid
LEFT JOIN places ON history.place_id = places.rowid
WHERE places.dir LIKE search_dir.dir
AND commands.argv LIKE '$(sql_escape $1)%'
)
LIMIT 1)
AND commands.argv LIKE '$(sql_escape $1)%'
ORDER BY history.id DESC
LIMIT 1;"
suggestion=$(_histdb_query "$query")
}
#ZSH_AUTOSUGGEST_STRATEGY=(histdb_top_here histdb_top_fallback)
#ZSH_AUTOSUGGEST_STRATEGY=(histdb_top)
#ZSH_AUTOSUGGEST_STRATEGY=(history completion)
#ZSH_AUTOSUGGEST_STRATEGY=(histdb_top_fallback history completion)
ZSH_AUTOSUGGEST_STRATEGY=(histdb_here_fallback2 history completion)
# https://github.com/larkery/zsh-histdb/pull/31
HISTDB_TABULATE_CMD=(sed -e $'s/\x1f/\t/g')
alias histdb2='HISTDB_TABULATE_CMD=(sed -e $"s/.*\x1f//") histdb'
tru/show_local_history() {
# limit="${1:-10}"
# local query="
# select history.start_time, commands.argv
# from history left join commands on history.command_id = commands.rowid
# left join places on history.place_id = places.rowid
# where places.dir LIKE '$(sql_escape $PWD)%'
# order by history.start_time desc
# limit $limit
# "
local query="
select
replace(commands.argv, '
', ' \\n') as cmd
from
history left join commands on history.command_id = commands.rowid
left join places on history.place_id = places.rowid
where places.dir LIKE
case when exists(select commands.argv from history
left join commands on history.command_id = commands.rowid
left join places on history.place_id = places.rowid
where places.dir LIKE '$(sql_escape $PWD)'
AND commands.argv LIKE '$(sql_escape $1)%')
then '$(sql_escape $PWD)'
else '%'
end
and commands.argv LIKE '$(sql_escape $1)%'
group by commands.argv
order by places.dir LIKE '$(sql_escape $PWD)' desc,
history.id desc
limit 1000
"
results=$(_histdb_query "$query")
#echo -e `echo -n "$results" | fzf-tmux -p 90% -m --cycle`
echo "`_histdb_query "$query" | fzf-tmux -p 90% -m --cycle`"
}
# globalias
GLOBALIAS_FILTER_VALUES=(ls ll mv cp grep rm emacs tmux fzf)
export ZSH_PLUGINS_ALIAS_TIPS_TEXT="Alias tip: "
export ZSH_PLUGINS_ALIAS_TIPS_EXCLUDES="_ emacs ll"
# Add em alias for macOS
# PR Merged!
if [[ "$(uname)" == 'Darwin' ]]; then
alias em="emacs"
alias emacs='open -a "/Applications/Emacs.app" '
#export EDITOR="emacs"
# export EDITOR='/opt/homebrew/bin/emacs -nw -Q'
#export VISUAL="emacs"
# emacs on mac
# export EDITOR="emacsclient -t" # $EDITOR should open in terminal
# export VISUAL="emacsclient -c -a emacs" # $VISUAL opens in GUI with non-daemon as alternate
# https://emacs.stackexchange.com/questions/60339/using-emacsclient-for-visual-raises-end-of-file-during-parsing
export VISUAL="$EDITOR_PATH/EDITOR"
export EDITOR=$VISUAL
else
export EDITOR="emacs"
# workaround for https://github.com/robbyrussell/oh-my-zsh/pull/5714
# alias emacs="te"
fi
# tramp mode for zsh: https://www.gnu.org/software/tramp/tramp-emacs.html
[ $TERM = "dumb" ] && unsetopt zle && PS1='# '
# https://github.com/zsh-users/zsh-history-substring-search
bindkey -M emacs '^P' history-substring-search-up
bindkey -M emacs '^N' history-substring-search-down
HISTORY_SUBSTRING_SEARCH_FUZZY=1
HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=1
set -o emacs
if [ -n "$INSIDE_EMACS" ]; then
# chpwd() { print -P "\033AnSiTc %d" }
# print -P "\033AnSiTu %n"
# print -P "\033AnSiTc %d"
# echo $INSIDE_EMACS
alias clear='printf "\e]51;Evterm-clear-scrollback\e\\";tput clear'
export ZSH_THEME="rawsyntax"
# vterm_prompt_end() {
# printf "\e]51;A$(whoami)@$(hostname):$(pwd)\e\\";
# }
# PROMPT=$PROMPT'%{$(vterm_prompt_end)%}'
else
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
# tab title show hostname
# function precmd {
# vcs_info
# print -P "\n$(repo_information) %F{yellow}$(cmd_exec_time) \e]0;%m\a%f"
# }
fi
# doom emacs
if [[ "$(uname)" == 'Darwin' ]]; then
# export DOOMDIR=$DOOMDIR_MAC
# export DOOMLOCALDIR=$DOOMLOCALDIR_MAC
alias doome='doom sync && emacs'
fi
# The emacs or emacsclient command to use
e() {
local TMP;
if [[ "$1" == "-" ]]; then
TMP="$(mktemp /tmp/emacsstdinXXX)";
cat >"$TMP";
if ! emacsclient --alternate-editor /usr/bin/false --eval "(let ((b (create-file-buffer \"my_drafts\"))) (tab-bar-new-tab) (switch-to-buffer b) (insert-file-contents \"${TMP}\") (delete-file \"${TMP}\"))" > /dev/null 2>&1; then
emacs --eval "(let ((b (create-file-buffer \"my_drafts\"))) (tab-bar-new-tab) (switch-to-buffer b) (insert-file-contents \"${TMP}\") (delete-file \"${TMP}\"))" &
fi;
else
emacsclient --alternate-editor "emacs" --no-wait "$@" > /dev/null 2>&1 &
fi;
}
# https://github.com/akermu/emacs-libvterm/blob/7adecaa48c222f2567d503705547cf239e38fc4b/README.md#shell-side-configuration
vterm_printf(){
if [ -n "$TMUX" ] && ([ "${TERM%%-*}" = "tmux" ] || [ "${TERM%%-*}" = "screen" ] ); then
# Tell tmux to pass the escape sequences through
printf "\ePtmux;\e\e]%s\007\e\\" "$1"
elif [ "${TERM%%-*}" = "screen" ]; then
# GNU screen (screen, screen-256color, screen-256color-bce)
printf "\eP\e]%s\007\e\\" "$1"
else
printf "\e]%s\e\\" "$1"
fi
}
# notmuch seach
# https://emacs-china.org/t/topic/305/73?u=tru
export XAPIAN_CJK_NGRAM=1
# FIX OSError: dlopen(libnotmuch.5.dylib, 6): image not found
export DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib/:/usr/local/lib/
## If you need to have imagemagick@6 first in your PATH, run:
## For compilers to find imagemagick@6 you may need to set:
## For pkg-config to find imagemagick@6 you may need to set:
# export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"
# export LDFLAGS="-L/usr/local/opt/imagemagick@6/lib"
# export CPPFLAGS="-I/usr/local/opt/imagemagick@6/include"
# export PKG_CONFIG_PATH="/usr/local/opt/imagemagick@6/lib/pkgconfig"
alias magit='emacsclient --eval "(magit-status)" && emacs'
alias emacsk="emacsclient --eval \"(progn (save-some-buffers) (kill-emacs))\""
export PS1_backup=$PS1
function tru/proxy () {
local prefix
if [ "$1" = "on" ]; then
export https_proxy=127.0.0.1:8888
export http_proxy=127.0.0.1:8888
# echo Local HTTP Proxy is enabled.
prefix="ProxyOn"
else
unset https_proxy
unset http_proxy
# echo Local HTTP Proxy is disabled.
prefix=""
fi
# export PS1="%K{blue} $prefix $PS1_backup"
export PS1="$prefix $PS1_backup"
}
tru/proxy off
export PATH=/opt/homebrew/bin:/opt/homebrew/sbin:$PATH
export PATH=/usr/local/bin:/opt/homebrew/bin:/usr/local/opt:$PATH:/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:~/.composer/vendor/bin:/usr/local/sbin:/snap/bin
PATH="/opt/homebrew/opt/grep/libexec/gnubin:$PATH"
export PATH="/usr/local/opt/node@8/bin:$PATH"
export PATH="$HOME/.tgenv/bin:$PATH"
export PATH="/usr/local/opt/sqlite/bin:$PATH"
export PATH="/usr/local/opt/node@10/bin:$PATH"
export PATH="/usr/local/opt/curl/bin:$PATH"
# Go path for macOS
if [[ "$(uname)" == 'Darwin' ]]; then
if [[ "$(uname -m)" == 'arm64' ]]; then
export GOPATH=$HOME/go
export GOROOT=/opt/homebrew/opt/go/libexec
export PATH=$PATH:${GOPATH}/bin:${GOROOT}/bin
else
export GOPATH=$HOME/go
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:${GOPATH}/bin:${GOROOT}/bin
fi
fi
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
# autoload -U +X bashcompinit && bashcompinit
# complete -o nospace -C /opt/homebrew/bin/mc mc
# broot
[ -f ~/.config/broot/launcher/bash/br ] && source ~/.config/broot/launcher/bash/br
# fzf https://github.com/junegunn/fzf/wiki/Configuring-shell-key-bindings
export FZF_TMUX=1
alias fzf='fzf-tmux -p 80% --cycle'
fzf-history-widget-accept() {
fzf-history-widget
zle accept-line
}
zle -N fzf-history-widget-accept
bindkey '^X^R' fzf-history-widget-accept
bindkey '^[g' fzf-cd-widget
# export FZF_DEFAULT_OPTS='--no-height --no-reverse --bind alt-a:select-all,alt-A:deselect-all,ctrl-t:toggle-all'
export FZF_DEFAULT_OPTS='--no-height --no-reverse
--bind alt-a:toggle-all
--bind ctrl-t:toggle-preview
--bind=ctrl-alt-j:preview-down
--bind=ctrl-alt-k:preview-up
'
# Using highlight (http://www.andre-simon.de/doku/highlight/en/highlight.html)
export FZF_CTRL_T_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'"
# Full command on preview window
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview'"
# preview
export FZF_ALT_G_OPTS="--preview 'tree -C {} | head -200'"
# https://github.com/junegunn/fzf/pull/1946
export FZF_TMUX_OPTS='-p 80%'
# https://stnly.com/fzf-and-rg/
# Setting rg as the default source for fzf
#export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow -g "!{.git,node_modules}/*" 2> /dev/null'
# To apply the command to CTRL-T as well
#export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
j() {
local preview_cmd="ls {2}"
if command -v exa &> /dev/null; then
preview_cmd="exa -l {2}"
fi
if [[ $# -eq 0 ]]; then
cd "$(autojump -s | sort -k1gr | awk '$1 ~ /[0-9]:/ && $2 ~ /^\// {print $1 " " $2}' | fzf --height 40% --reverse --inline-info --preview "$preview_cmd" --preview-window down:50% | awk '{print $2}')"
else
cd $(command autojump $@)
fi
}
# https://github.com/junegunn/fzf/wiki/examples#searching-file-contents
# fif() {
# ag --nobreak --nonumbers --noheading . | fzf
# }
fif() {
if [ ! "$#" -gt 0 ]; then echo "Need a string to search for!"; return 1; fi
local file
# file="$(rga --max-count=1 --ignore-case --files-with-matches --no-messages "$@" | fzf-tmux +m --preview="rga --ignore-case --pretty --context 10 '"$@"' {}")" && open "$file"
file="$(rga --max-count=1 --ignore-case --files-with-matches --no-messages "$@" | fzf-tmux +m --preview="rga --ignore-case --pretty --context 10 '"$@"' {}")" && echo "$file"
}
fif2() {
if [ ! "$#" -gt 0 ]; then echo "Need a string to search for!"; return 1; fi
rg --files-with-matches --no-messages "$1" | fzf --preview "highlight -O ansi -l {} 2> /dev/null | rg --colors 'match:bg:yellow' --ignore-case --pretty --context 10 '$1' || rg --ignore-case --pretty --context 10 '$1' {}"
}
_jump_to_tabstop_in_snippet() {
# the idea is to match ${\w+}, and replace
# that with the empty string, and move the cursor to
# beginning of the match. If no match found, simply return
# valid place holders: ${}, ${somealphanumericstr}
local str=$BUFFER
local searchstr=''
[[ $str =~ ([$]\\{[[:alnum:]]*\\}) ]] && searchstr=$MATCH
[[ -z "$searchstr" ]] && return
local rest=${str#*$searchstr}
local pos=$(( ${#str} - ${#rest} - ${#searchstr} ))
BUFFER=$(echo ${str//${MATCH}/})
CURSOR=$pos
}
zle -N _jump_to_tabstop_in_snippet
bindkey '^J' _jump_to_tabstop_in_snippet
# https://github.com/junegunn/fzf/wiki/Examples#tmux
tru/tmux-ftpane() {
local panes current_window current_pane target target_window target_pane
panes=$(tmux list-panes -s -F '#I:#P - #{pane_current_path} #{pane_current_command}')
current_pane=$(tmux display-message -p '#I:#P')
current_window=$(tmux display-message -p '#I')
target=$(echo "$panes" | grep -v "$current_pane" | fzf +m --reverse) || return
target_window=$(echo $target | awk 'BEGIN{FS=":|-"} {print$1}')
target_pane=$(echo $target | awk 'BEGIN{FS=":|-"} {print$2}' | cut -c 1)
if [[ $current_window -eq $target_window ]]; then
tmux select-pane -t ${target_window}.${target_pane}
else
tmux select-pane -t ${target_window}.${target_pane} &&
tmux select-window -t $target_window
fi
}
is_in_git_repo() {
git rev-parse HEAD > /dev/null 2>&1
}
fzf-down() {
fzf -p 88% --border --bind ctrl-/:toggle-preview "$@"
}
fzf_gf() {
is_in_git_repo || return
git -c color.status=always status --short |
fzf-down -m --ansi --nth 2..,.. \
--preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1})' |
cut -c4- | sed 's/.* -> //'
}
fzf_gb() {
is_in_git_repo || return
git branch -a --color=always | grep -v '/HEAD\s' | sort |
fzf-down --ansi --multi --tac --preview-window right:70% \
--preview 'git log --oneline --graph --date=short --color=always --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1)' |
sed 's/^..//' | cut -d' ' -f1 |
sed 's#^remotes/##'
}
fzf_gt() {
is_in_git_repo || return
git tag --sort -version:refname |
fzf-down --multi --preview-window right:70% \
--preview 'git show --color=always {}'
}
fzf_gh() {
is_in_git_repo || return
git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=always |
fzf-down --ansi --no-sort --reverse --multi --bind 'ctrl-s:toggle-sort' \
--header 'Press CTRL-S to toggle sort' \
--preview 'grep -o "[a-f0-9]\{7,\}" <<< {} | xargs git show --color=always' |
grep -o "[a-f0-9]\{7,\}"
}
fzf_gr() {
is_in_git_repo || return
git remote -v | awk '{print $1 "\t" $2}' | uniq |
fzf-down --tac \
--preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" {1}' |
cut -d$'\t' -f1
}
fzf_gs() {
is_in_git_repo || return
git stash list | fzf-down --reverse -d: --preview 'git show --color=always {1}' |
cut -d: -f1
}
join-lines() {
local item
while read item; do
echo -n "${(q)item} "
done
}
bind-git-helper() {
local c
for c in $@; do
eval "fzf-g$c-widget() { local result=\$(fzf_g$c | join-lines); zle reset-prompt; LBUFFER+=\$result }"
eval "zle -N fzf-g$c-widget"
eval "bindkey '^g^$c' fzf-g$c-widget"
done
}
bind-git-helper f b t r h s
unset -f bind-git-helper
rgf() {
for arg; do
case "$arg" in
--noignore ) FLAG='--no-ignore' ;;
esac
done
RG_PREFIX="rg $FLAG --column --line-number --no-heading --color=always --smart-case "
INITIAL_QUERY=$(echo "${*:-}" | sed 's/--noignore//')
# IFS=: read -ra selected < <(
fzf=$(FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY")" \
fzf --ansi \
-e -m \
--color "hl:-1:underline,hl+:-1:underline:reverse" \
--disabled --query "$INITIAL_QUERY" \
--bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
--bind "alt-enter:unbind(change,alt-enter)+change-prompt(2. fzf> )+enable-search+clear-query" \
--bind "ctrl-o:execute-silent:(emacsclient --eval \"(progn (find-file \\\"\$(echo {} | awk -F ':' '{print \$1}')\\\") (goto-line \$(echo {} | awk -F ':' '{print \$2}')) (forward-char \$(echo {} | awk -F ':' '{print \$3}')) (recenter))\") && open \"/Applications/Emacs.app\"" \
--prompt '1. ripgrep> ' \
--delimiter : \
--preview 'bat --color=always {1} --highlight-line {2}' \
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3'
)
if [[ -n $fzf ]]; then
echo $fzf
# cmd=$(echo $fzf | awk -F ':' '{print "emacsclient --eval \"(progn (+workspace/new) (+workspace/switch-to-final) (find-file \\\""$1"\\\") (goto-line "$2") (forward-char "$3") (recenter))\"; " }' )
cmd=$(echo $fzf | awk -F ':' '{print "emacsclient --eval \"(progn (find-file \\\""$1"\\\") (goto-line "$2") (forward-char "$3") (recenter))\"; " }' )
echo $cmd
eval $cmd > /dev/null 2>&1
#emacs
osascript -e "tell application \"Emacs\" to activate"
fi
}
# github_latest_release_download "Canop/broot"
tru/github_latest_release_download() {
curl -s "https://api.github.com/repos/$1/releases/latest" | jq -r ".assets[] | select(.name | contains(\"zip\"|\"gz\")) | .browser_download_url"
}
#export AWS_PROFILE=
awsp() {
export AWS_PROFILE="$(aws-profiles | fzf --height 30% --inline-info)"
}
aws-profiles() {
cat ~/.aws/credentials | grep '\[' | grep -v '#' | tr -d '[' | tr -d ']'
}
export AWS_PAGER=""
addspace_ (){
BUFFER=" $BUFFER"
CURSOR=$#BUFFER
}
zle -N addspace_
bindkey "^s" addspace_
alias t=tmux
[[ ! -f $DOTDIR/misc/custom.zsh ]] || source $DOTDIR/misc/custom.zsh
# https://twitter.com/dailyzshtip/status/1466384154778472459
for n ({1..5}) alias -g NF$n="*(.om[$n])"
# e.g. this gives you
# vi NF2 # edit 2nd newest file
# https://twitter.com/dailyzshtip/status/1458483872417583118
for n ({1..5}) alias -g ND$n="*(/om[$n])"
# ND1 # newest dir
# ND2 # 2nd newest dir
for n ({1..5}) alias -g NH$n=".*(.om[$n])"
# NH1 # newest hidden file
# NH2 # 2nd newest hidden file
# Ref: https://cli.github.com/manual/gh_completion
compinit -i
chatgpt() {
local OPENAI_KEY
export OPENAI_KEY=$(pass show openai/key)
command chatgpt "$@"
}
# source /Users/tru/Dropbox/git/src/github.com/m42e/zsh-histdb-fzf/fzf-histdb.zsh