first commit

config imported from personal dotfiles aleee-idk/dots
This commit is contained in:
Alexander Navarro 2024-08-05 14:51:17 -04:00
commit d3a88cbb28
85 changed files with 5236 additions and 0 deletions

View file

@ -0,0 +1,49 @@
forgit-list-command-widget() {
local cmd=$(alias | grep 'forgit' | sed -E 's/::/ /g; s/=/ :- /g; s/for//g' | \
awk -v BLD=${BLD} -v RST=${RST} -v BLU=${BLU} -v CYN=${CYN} -F":" '{print BLU BLD $1 RST ":" CYN $2 RST }' | \
column -ts":")
LBUFFER="$LBUFFER$( \
fzf-tmux -p -w 30% -h 53% --preview-window=hidden --prompt=' List > ' \
--header=$'Alias\t Description' <<< "$cmd" | awk '{print $1}')"
if [[ -n $LBUFFER ]]; then
zle accept-line
fi
zle reset-prompt
}
zle -N forgit-list-command-widget
bindkey '^[g^[l' forgit-list-command-widget #<Alt-G+Alt-L>
export FORGIT_FZF_SHOW_HELP_OPTS="$(
cat <<-EOF
Forgit Commands (Aliases)
fga add
fgbl blame
fgbd branch delete
fgcb checkout branch
fgco checkout commit
fgcf checkout file
fgct checkout tag
fgcp cherry pick
fgclean clean
fgd diff
fgfu fixup
fgi ignore
fglo log
fgrb rebase
fgrh reset head
fgrev revert commit
fgsta stash push
fgsts stash show
EOF
)"
export FORGIT_FZF_DEFAULT_OPTS="
--cycle
--reverse
--height '80%'
--preview-window=nohidden
--bind 'alt-?:preview(printf \"${FORGIT_FZF_SHOW_HELP_OPTS}\")'
"

View file

@ -0,0 +1,130 @@
export FZF_SHOW_HELP_OPTS="$(
cat <<-EOF
FZF Keybinds Shortcut
? Toggle/Hide Preview
C-space Change preview layout
C-e Open in Editor
C-v Open in VsCode
C-o Launch Application Chooser
M-o Open in Default Appllication
C-/ Directory: Navigate on broot
C-/ File: Open in Pager (bat)
M-s Toggle Sort
C-y Copy/Yank
C-M-y Copy/Yank Working Directory
C-a Select all
C-M-d Deselect All
Del Delete/Remove file
Alt-? Help (this page)
ESC Quit
EOF
)"
export FZF_DEFAULT_OPTS=" \
--color=bg+:#363a4f,bg:#24273a,spinner:#f4dbd6,hl:#ed8796 \
--color=fg:#cad3f5,header:#ed8796,info:#c6a0f6,pointer:#f4dbd6 \
--color=marker:#f4dbd6,fg+:#cad3f5,prompt:#c6a0f6,hl+:#ed8796"
export FZF_PREVIEW_OPTS="--preview
'([[ {} =~ ('.jpg'|'.jpeg'|'.png'|'.gif'|'.bmp'|'.svg'|'.mp4'|'.mkv')$ ]] && (chafa --center=on {} && exiftool {})) ||
([[ -f {} ]] && (bat --style=header,numbers,changes,plain --color=always --language=sh --line-range :500 {} || cat {})) ||
([[ -d {} ]] && (lsd -all --long --tree --depth=5 --group-dirs=first -I=.git {} )) || echo {} 3>/dev/null | head -n 500'
"
#'([[ \$(file -bL --mime-type {} 2> /dev/null = image) ]] && (catimg -w 100 {})) || # throwing an stb error cant silence
export FZF_PREVIEW_KEYBIND_OPTS="
--bind '?:toggle-preview'
--bind 'alt-?:preview(printf \"${FZF_SHOW_HELP_OPTS}\")'
--bind 'alt-j:preview-down'
--bind 'alt-k:preview-up'
--bind 'ctrl-d:preview-page-down'
--bind 'ctrl-u:preview-page-up'
--bind 'ctrl-t:preview-top'
--bind 'ctrl-b:preview-bottom'
--bind 'ctrl-l:clear-screen+clear-query+first'
--bind 'ctrl-space:change-preview-window(right,80%,nohidden|down,80%,border-top,nohidden|down,50%,nohidden|up,80%,border-down,nohidden|up,50%,nohidden|left,80%,nohidden|left,50%,nohidden|down:3:nohidden:wrap|up:3,nohidden:wrap|right,50%,nohidden)'
"
export FZF_KEYBIND_SHORTCUTS="
$FZF_PREVIEW_KEYBIND_OPTS
--bind 'alt-o:execute(xdg-open {+})'
--bind 'alt-s:toggle-sort'
--bind 'ctrl-/:execute(
if [[ -d {} ]]; then
broot {} < /dev/tty > /dev/tty 2>&1
elif [[ {} =~ ('.jpg'|'.jpeg'|'.png'|'.gif'|'.bmp'|'.svg'|'.mp4'|'.mkv')$ ]]; then
chafa --center {} | less > /dev/tty
else
bat --paging=always --style=plain --color=always --language=sh {} > /dev/tty
fi)'
--bind 'ctrl-a:select-all'
--bind 'ctrl-alt-d:deselect-all'
--bind 'ctrl-o:execute(flatpak run re.sonny.Junction {+})'
--bind 'ctrl-y:execute-silent(wl-copy {+})'
--bind 'ctrl-alt-y:execute-silent(readlink -f {+} | wl-copy)'
--bind 'ctrl-e:execute(${EDITOR} {} > /dev/tty)'
--bind 'ctrl-v:execute(code {+})'
--bind 'del:execute(rm -iv {};)+reload($FZF_DEFAULT_COMMAND)+clear-screen'
"
# --bind 'ctrl-/:execute(if [[ -f {} ]]; then bat --paging=always --style=\"header,numbers,changes\" --language=sh {} < /dev/tty > /dev/tty 2>&1; else broot {} < /dev/tty > /dev/tty 2>&1
# ; fi)'
export FZF_DEFAULT_COMMAND="fd --color=always --hidden --exclude .git"
export FZF_DEFAULT_OPTS="
"$FZF_PREVIEW_OPTS"
"$FZF_KEYBIND_SHORTCUTS"
"$FZF_THEME_CATPPUCCIN_MOCHA"
-i
--ansi
--multi
--height=90%
--info=inline
--no-separator
--layout=reverse
--preview-window=:hidden
"
export FZF_ALT_C_COMMAND="fd --type=d --color=always --hidden --exclude .git"
export FZF_ALT_C_OPTS="
--preview 'lsd --all --long --tree --depth=3 {} | head -500'
--preview-window 'nohidden,<50(down,75%,border-top)'
--bind 'alt-h:reload(fd --type=d --color=always --follow --exclude .git)'
--bind 'alt-c:reload(fd -p ~ --color=always --hidden --type=d --follow)'
"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_CTRL_T_OPTS="
--exit-0
--select-1
--info=default
--layout=reverse-list
--preview-window '50%,<50(up,75%,border-down)'
--header 'Alt-D: Directories | Alt-F: Files | Alt-H: Hide Files'
--bind 'alt-d:change-prompt( Directories > )+reload("$FZF_ALT_C_COMMAND")'
--bind 'alt-f:change-prompt( Files > )+reload("$FZF_DEFAULT_COMMAND")'
--bind 'alt-h:change-prompt( Hide Files > )+reload(fd --type=f --color=always --follow)'
--bind 'ctrl-t:change-prompt(Home > )+reload(fd --base-directory ~ --color=always --hidden --exclude .git)'
"
export FZF_CTRL_R_OPTS="
--preview 'echo {+} | bat --color=always --wrap never --language=sh --style=plain'
--preview-window 'down:3:nohidden:wrap'"
# export FZF_TMUX_OPTS='-p80% --color=border:blue'
# FZF_TMUX_CTRL_R_OPT="fzf-tmux -p $FZF_CTRL_R_OPTS"
# --bind 'alt-p:execute($'FZF_TMUX_OPTS'='-p90% --color=border:blue')'
# fzf completion '**' doesn't preview files (idk if it is a bug)
_fzf_compgen_path() {
fd --color=always --hidden --follow --exclude ".git" . "$1"
}
_fzf_compgen_dir() {
fd --color=always --type d --hidden --follow --exclude ".git" . "$1"
}

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