Skip to content

Commit

Permalink
feat: improve fzf config
Browse files Browse the repository at this point in the history
  • Loading branch information
okaufmann committed Apr 24, 2024
1 parent 67d5d7f commit feb9198
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ brew 'tldr'
brew 'bind' # used to have dig as binary
brew 'nmap'
brew 'fzf'
brew 'fd'
brew 'bat'
brew 'fx'
brew 'eza'
Expand Down
55 changes: 54 additions & 1 deletion shell/.exports
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,62 @@ export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=5'
source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh

# FZF
export FZF_DEFAULT_OPTS="--bind='ctrl-o:execute(code {})+abort' --layout=reverse --info=inline --preview 'cat {}' --border --margin=1 --padding=1"

[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

# --- setup fzf theme ---
fg="#CBE0F0"
bg="#011628"
bg_highlight="#143652"
purple="#B388FF"
blue="#06BCE4"
cyan="#2CF9ED"

export FZF_DEFAULT_OPTS="--color=fg:${fg},bg:${bg},hl:${purple},fg+:${fg},bg+:${bg_highlight},hl+:${purple},info:${blue},prompt:${cyan},pointer:${cyan},marker:${cyan},spinner:${cyan},header:${cyan}"

export FZF_DEFAULT_OPTS="--info=inline
--layout=reverse
--bind='ctrl-o:execute(code {})+abort'
--color=fg:${fg},bg:${bg},hl:${purple},fg+:${fg},bg+:${bg_highlight},hl+:${purple},info:${blue},prompt:${cyan},pointer:${cyan},marker:${cyan},spinner:${cyan},header:${cyan}"

export FZF_DEFAULT_COMMAND="fd --hidden --strip-cwd-prefix --exclude .git"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND="fd --type=d --hidden --strip-cwd-prefix --exclude .git"

# Use fd (https://github.com/sharkdp/fd) for listing path candidates.
# - The first argument to the function ($1) is the base path to start traversal
# - See the source code (completion.{bash,zsh}) for the details.
_fzf_compgen_path() {
fd --hidden --exclude .git . "$1"
}

# Use fd to generate the list for directory completion
_fzf_compgen_dir() {
fd --type=d --hidden --exclude .git . "$1"
}

# not yet installed
# source ~/fzf-git.sh/fzf-git.sh

export FZF_CTRL_T_OPTS="--preview 'bat -n --color=always --line-range :500 {}'"
export FZF_ALT_C_OPTS="--preview 'eza --tree --color=always {} | head -200'"

# Advanced customization of fzf options via _fzf_comprun function
# - The first argument to the function is the name of the command.
# - You should make sure to pass the rest of the arguments to fzf.
_fzf_comprun() {
local command=$1
shift

case "$command" in
cd) fzf --preview 'eza --tree --color=always {} | head -200' "$@" ;;
export|unset) fzf --preview "eval 'echo \$'{}" "$@" ;;
ssh) fzf --preview 'dig {}' "$@" ;;
*) fzf --preview "bat -n --color=always --line-range :500 {}" "$@" ;;
esac
}


# zoxide
eval "$(zoxide init zsh --cmd cd)"

Expand Down

0 comments on commit feb9198

Please sign in to comment.