This commit is contained in:
Alexander Navarro 2023-02-21 18:22:19 -03:00
parent 4524a86376
commit 0552ffdae8
37 changed files with 8770 additions and 49 deletions

View file

@ -0,0 +1,16 @@
fzf-aliases-widget() {
LBUFFER="$LBUFFER$(FZF_DEFAULT_COMMAND=
alias | sed 's/=/ --- /' | \
awk -v blu=$(tput setaf 4) -v cyn=$(tput setaf 6) -v bld=$(tput bold) -v rst=$(tput sgr0) -F '---' \
'{
print bld cyn $1 rst blu "--" $2
}' | \
tr -d "'" | column -tl2 | \
fzf --prompt=" Aliases > " \
--preview 'echo {3..} | bat --color=always --plain --language=sh' \
--preview-window 'up:4:nohidden:wrap' | cut -d' ' -f 1)"
zle reset-prompt
}
zle -N fzf-aliases-widget
bindkey '^[a' fzf-aliases-widget #<Alt-A>

View file

@ -0,0 +1,25 @@
fzf-atuin-history-widget() {
local selected num
setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2> /dev/null
selected=( $(atuin history list --cmd-only | tac | awk '{ cmd=$0; sub(/^[ \t]*[0-9]+\**[ \t]+/, "", cmd); if (!seen[cmd]++) print $0 }' | bat --color=always --wrap never --language=sh --style=plain |
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} ${FZF_DEFAULT_OPTS-} --scheme=history --bind=ctrl-r:toggle-sort,ctrl-z:ignore ${FZF_CTRL_R_OPTS-} --query=${(qqq)LBUFFER} +m" $(__fzfcmd)) )
local ret=$?
if [ -n "$selected" ]; then
cmd=$selected[1,-1]
if [ -n "$cmd" ]; then
zle vi-fetch-history -n $cmd
fi
fi
zle -U "$cmd"
zle kill-buffer
zle reset-prompt
return $ret
}
if ! command -v atuin > /dev/null; then
zle -N fzf-history-widget
bindkey '^R' fzf-history-widget
else
zle -N fzf-atuin-history-widget
bindkey '^R' fzf-atuin-history-widget
fi

View file

@ -0,0 +1,15 @@
fzf-cd-recent-dir-widget () {
local dir
print -rNC1 -- $dirstack |
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_ALT_C_OPTS-}" $(__fzfcmd) +m \
--color=fg:bold:blue --query=${LBUFFER} --read0 --print0 |
IFS= read -rd '' dir
if [[ -n $dir ]]; then
BUFFER=" builtin cd -- $dir"
zle accept-line
fi
zle reset-prompt
}
zle -N fzf-cd-recent-dir-widget
bindkey '^[C' fzf-cd-recent-dir-widget #<Alt-Shift-C>

View file

@ -0,0 +1,20 @@
fzf-cd-widget() {
local cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
-o -type d -print 2> /dev/null | cut -b3-"}"
setopt localoptions pipefail no_aliases 2> /dev/null
local dir="$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_ALT_C_OPTS-}" $(__fzfcmd) +m)"
if [[ -z "$dir" ]]; then
zle redisplay
return 0
fi
zle push-line # Clear buffer. Auto-restored on next prompt.
BUFFER=" builtin cd -- ${(q)dir}"
zle accept-line
local ret=$?
unset dir # ensure this doesn't end up appearing in prompt expansion
zle reset-prompt
return $ret
}
zle -N fzf-cd-widget
bindkey '^[c' fzf-cd-widget #<Alt-C>

View file

@ -0,0 +1,24 @@
fzf-dictionary-widget() {
local dict wiki wikis gogl
dict="dict {}"
wiki="wiki {} > /dev/tty"
wweb="w3m https://en.wikipedia.org/wiki/{}"
gogl="w3m https://google.com/search?q=define\ {}"
LBUFFER="$LBUFFER$(FZF_DEFAULT_COMMAND= cat /usr/share/dict/*words | sort | uniq -id | \
fzf-tmux \
-p60% \
--layout=default \
--header-first \
--header="M-w: Wiki | M-d: Define | M-g: Google" \
--color=fg:blue,fg+:blue,border:blue \
--bind="alt-d:change-preview($dict)" \
--bind="alt-w:execute($wiki)" \
--bind="alt-g:execute($gogl)" \
--prompt=" > " \
--preview "$dict" \
--preview-window='up,85%,border-bottom,wrap' | paste -sd" " -)"
zle reset-prompt
}
zle -N fzf-dictionary-widget
bindkey '^[d' fzf-dictionary-widget #<Alt-D>

View file

@ -0,0 +1,7 @@
function fzf-rg-widget() {
bash ${DOOTS:-$HOME/.local}/bin/fzf-rg-launcher "$LBUFFER"
zle redisplay
}
zle -N fzf-rg-widget
bindkey '^F' fzf-rg-widget

View file

@ -0,0 +1,13 @@
fzf-locate-widget() {
local selected
if selected=$(locate / | fzf --prompt " Locate > " -q "$LBUFFER" \
--bind 'alt-u:execute(sudo updatedb)' --header 'M-u: UpdateDB' \
--color=fg:bold:blue --preview-window '<50(down,75%,border-top)'
); then
LBUFFER=$selected
fi
zle reset-prompt
}
zle -N fzf-locate-widget
bindkey '^[i' fzf-locate-widget #<Alt-I>

View file

@ -0,0 +1,21 @@
fzf-man-widget() {
batman="man {1} | col -bx | bat --language=man --plain --color always --theme=\"Monokai Extended\""
man -k . | sort \
| awk -v CYN=${CYN} -v BLU=${BLU} -v RES=${RES} -v BLD=${BLD} '{ $1=CYN BLD $1; $2=RES BLU;} 1' \
| fzf \
-q "$LBUFFER" \
--ansi \
--tiebreak=begin \
--prompt=' Man > ' \
--header="M-u: update mandb | M-t: tl;dr | M-c: cheat.sh | M:m manual " \
--preview-window '50%,rounded,<50(down,80%,border-up)' \
--preview "${batman}" \
--bind "enter:execute(man {1})" \
--bind "alt-c:+change-preview(curl -s cht.sh/{1})+change-prompt(ﯽ Cheat > )" \
--bind "alt-m:+change-preview(${batman})+change-prompt( Man > )" \
--bind "alt-u:execute(sudo mandb && echo -e '\nUpdating tl;dr cache...';tldr --update)" \
--bind "alt-t:+change-preview(tldr --color=always {1})+change-prompt(ﳁ TLDR > )"
zle reset-prompt
}
zle -N fzf-man-widget
bindkey '^[h' fzf-man-widget