From 9d4f3f24122b58e21c646580df5b27cb0fe63c4b Mon Sep 17 00:00:00 2001 From: Lnk User Date: Thu, 26 Jun 2025 18:26:55 +0200 Subject: [PATCH] lnk: added .fzf_custom --- .fzf_custom | 29 +++++++++++++++++++++++++++++ .lnk | 1 + 2 files changed, 30 insertions(+) create mode 100644 .fzf_custom diff --git a/.fzf_custom b/.fzf_custom new file mode 100644 index 0000000..179015c --- /dev/null +++ b/.fzf_custom @@ -0,0 +1,29 @@ +# FZF options +export FZF_COMPLETION_OPTS='--border --info=inline' +[ -x ~/Software/bin/eza ] && export FZF_ALT_C_OPTS="--preview 'eza --tree --level=2 {} | head -200'" +[ -x "$(command -v tree)" ] && export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'" + +# Custom fuzzy completion for "z" command +# e.g. z ** +_fzf_complete_z() { + _fzf_complete --multi --reverse --preview 'eza --tree --level=2 {} | head -200' --prompt="z> " -- "$@" < <( + z -l | sort -nr | sed 's/^[0-9,.]* *//' + ) +} +[ -n "$BASH" ] && complete -F _fzf_complete_z -o default -o bashdefault z + +export FZF_GHQ_OPTS="--preview 'cat \$(find {} -iname readme*) | head -200'" +[ -x "$(command -v bat)" ] && export FZF_GHQ_OPTS="--preview 'bat -l md --color=always \$(find {} -iname readme*) | head -200'" +[ -x "$(command -v glow)" ] && export FZF_GHQ_OPTS="--preview 'glow -s dark \$(find {} -iname readme*) | head -200'" + +function fzf-repo() { + cmd="ghq list --full-path | fzf --query \"$LBUFFER\" $FZF_GHQ_OPTS" + # local selected_repo=$(ghq list --full-path | fzf --query "$LBUFFER" --preview 'glow -s dark $(find {} -iname readme*) | head -200') + local selected_repo=$(eval $cmd) + if [ -n "$selected_repo" ]; then + if [ -t 1 ]; then + pushd ${selected_repo} + fi + fi +} +bind -x '"\C-g": fzf-repo' diff --git a/.lnk b/.lnk index 4d3289f..a3e21fe 100644 --- a/.lnk +++ b/.lnk @@ -3,3 +3,4 @@ .bashrc .config/atuin/config.toml .emacs +.fzf_custom