Fix FZF integration in to ZSH
This commit is contained in:
27
zsh/.profile.d/fzf.sh
Normal file → Executable file
27
zsh/.profile.d/fzf.sh
Normal file → Executable file
@@ -1,8 +1,31 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
is_debian_based() {
|
||||||
|
# Checking /etc/os-release
|
||||||
|
if [[ -f /etc/os-release ]]; then
|
||||||
|
. /etc/os-release
|
||||||
|
if [[ "$ID_LIKE" == *"debian"* ]] || [[ "$ID" == "debian" ]]; then
|
||||||
|
return 0 # OK: Debian-based
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Alternative check: /etc/debian_version
|
||||||
|
if [[ -f /etc/debian_version ]]; then
|
||||||
|
return 0 # OK: Debian-based
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 1 # NO Debian-based
|
||||||
|
}
|
||||||
|
|
||||||
# Add fzf keybindings and enhancements
|
# Add fzf keybindings and enhancements
|
||||||
export FZF_CTRL_T_COMMAND="fd --type f"
|
if is_debian_based; then
|
||||||
export FZF_ALT_C_COMMAND="fd --type d"
|
export FZF_CTRL_T_COMMAND="fdfind --type f"
|
||||||
|
export FZF_ALT_C_COMMAND="fdfind --type d"
|
||||||
|
else
|
||||||
|
export FZF_CTRL_T_COMMAND="fd --type f"
|
||||||
|
export FZF_ALT_C_COMMAND="fd --type d"
|
||||||
|
fi
|
||||||
|
|
||||||
export FZF_CTRL_R_OPTS="--preview 'echo {}'"
|
export FZF_CTRL_R_OPTS="--preview 'echo {}'"
|
||||||
|
|
||||||
# Export Catppuccin Mocha theme for FZF
|
# Export Catppuccin Mocha theme for FZF
|
||||||
|
|||||||
36
zsh/.zshrc
36
zsh/.zshrc
@@ -76,7 +76,6 @@ plugins=(
|
|||||||
aws
|
aws
|
||||||
colored-man-pages
|
colored-man-pages
|
||||||
command-not-found
|
command-not-found
|
||||||
fzf
|
|
||||||
gitignore
|
gitignore
|
||||||
mise
|
mise
|
||||||
zoxide
|
zoxide
|
||||||
@@ -122,35 +121,8 @@ fpath=(~/.zsh $fpath)
|
|||||||
autoload run-help
|
autoload run-help
|
||||||
autoload -Uz compinit && compinit -u
|
autoload -Uz compinit && compinit -u
|
||||||
|
|
||||||
# Key bindings using bindkey and fzf-tmux where possible
|
export FZF_HOME=$HOME/.oh-my-zsh/custom/plugins/fzf
|
||||||
# Ctrl+R: Enhanced reverse history search
|
source <(fzf --zsh)
|
||||||
bindkey '^R' fzf-history-widget
|
source "$FZF_HOME/shell/key-bindings.zsh"
|
||||||
|
source "$FZF_HOME/shell/completion.zsh"
|
||||||
|
|
||||||
# Ctrl+T: Fuzzy find file
|
|
||||||
bindkey '^T' fzf-file-widget
|
|
||||||
|
|
||||||
# Alt+C: Fuzzy change directory
|
|
||||||
bindkey '^[c' fzf-cd-widget
|
|
||||||
|
|
||||||
# Additional useful bindings
|
|
||||||
# Alt+H: Search and insert from history
|
|
||||||
fzf-history-widget() {
|
|
||||||
BUFFER=$(fc -l 1 | fzf --tac +s --no-sort --preview 'echo {}' | sed 's/^[ 0-9]*//')
|
|
||||||
CURSOR=$#BUFFER
|
|
||||||
zle reset-prompt
|
|
||||||
}
|
|
||||||
zle -N fzf-history-widget
|
|
||||||
|
|
||||||
fzf-file-widget() {
|
|
||||||
local file
|
|
||||||
file=$(fzf --preview 'bat --style=numbers --color=always --line-range :500 {}' 2> /dev/null) && LBUFFER+="$file"
|
|
||||||
zle reset-prompt
|
|
||||||
}
|
|
||||||
zle -N fzf-file-widget
|
|
||||||
|
|
||||||
fzf-cd-widget() {
|
|
||||||
local dir
|
|
||||||
dir=$(fd --type d | fzf --preview 'tree -a -C {} | head -100') && cd "$dir"
|
|
||||||
zle reset-prompt
|
|
||||||
}
|
|
||||||
zle -N fzf-cd-widget
|
|
||||||
|
|||||||
Reference in New Issue
Block a user