mirror of
https://github.com/Xevion/dotfiles.git
synced 2026-01-31 08:24:11 -06:00
refactor: replace lazy zoxide with eager init and add fd-based directory discovery
- Switch from lazy-loaded z/zi to eager zoxide initialization in config.fish - Alias cd to use zoxide for automatic frecency tracking - Add Alt+D: discover directories from git root/cwd with fd+fzf (no gitignore) - Add Alt+Shift+D: discover directories from HOME with fd+fzf (depth 5)
This commit is contained in:
@@ -55,7 +55,29 @@ if functions -q fzf_search_abbr
|
||||
bind -M insert \ea fzf_search_abbr # Also bind in insert mode
|
||||
end
|
||||
|
||||
# Alt+C: Replace line with 'cd <last-arg>' (useful after mkdir)
|
||||
bind \ec fish_cd_last_arg
|
||||
bind -M insert \ec fish_cd_last_arg
|
||||
|
||||
# Alt+D: Discover directories with fd+fzf (from git root or cwd)
|
||||
bind \ed _fzf_discover_directory
|
||||
bind -M insert \ed _fzf_discover_directory
|
||||
|
||||
# Alt+Shift+D: Discover directories from HOME with fd+fzf
|
||||
bind \eD _fzf_discover_home
|
||||
bind -M insert \eD _fzf_discover_home
|
||||
|
||||
# Load abbreviations
|
||||
if test -f ~/.config/fish/conf.d/abbr.fish
|
||||
source ~/.config/fish/conf.d/abbr.fish
|
||||
end
|
||||
|
||||
# Initialize zoxide eagerly for cd tracking
|
||||
if command -q zoxide
|
||||
zoxide init fish | source
|
||||
|
||||
# Alias cd to use zoxide (keeps muscle memory, gets smart navigation)
|
||||
function cd --description "zoxide-powered smart cd"
|
||||
__zoxide_z $argv
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# Smart directory finder with fd + fzf (shows all directories including gitignored)
|
||||
# Searches from git root if in repo, otherwise current directory
|
||||
function _fzf_discover_directory --description "Alt+D: Discover directories with fd+fzf (no-ignore)"
|
||||
# Start from git root if in a git repo, otherwise current directory
|
||||
set -l search_root (git rev-parse --show-toplevel 2>/dev/null || pwd)
|
||||
|
||||
set -l selected (
|
||||
fd --type d --hidden --no-ignore --exclude .git --exclude node_modules \
|
||||
. "$search_root" | \
|
||||
fzf --height=50% \
|
||||
--preview="lsd -1 --color=always --icon=always {}" \
|
||||
--preview-window=right,40% \
|
||||
--prompt="📁 Discover > " \
|
||||
--header="Searching from: $search_root (all dirs, no gitignore)"
|
||||
)
|
||||
|
||||
if test -n "$selected"
|
||||
cd "$selected"
|
||||
commandline -f repaint
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
# Directory finder starting from HOME with fd + fzf (shows all directories)
|
||||
function _fzf_discover_home --description "Alt+Shift+D: Discover directories from HOME with fd+fzf"
|
||||
set -l selected (
|
||||
fd --type d --hidden --no-ignore --max-depth 5 \
|
||||
--exclude .git --exclude node_modules \
|
||||
. "$HOME" | \
|
||||
fzf --height=50% \
|
||||
--preview="lsd -1 --color=always --icon=always {}" \
|
||||
--preview-window=right,40% \
|
||||
--prompt="🏠 Home > " \
|
||||
--header="Searching from: $HOME (max depth 5, all dirs)"
|
||||
)
|
||||
|
||||
if test -n "$selected"
|
||||
cd "$selected"
|
||||
commandline -f repaint
|
||||
end
|
||||
end
|
||||
@@ -1,18 +0,0 @@
|
||||
# Lazy-load zoxide on first use of z command
|
||||
function z --description "zoxide smart cd"
|
||||
# Initialize zoxide only once
|
||||
if not set -q __zoxide_initialized
|
||||
set -g __zoxide_initialized 1
|
||||
|
||||
# Run zoxide init
|
||||
if command -q zoxide
|
||||
zoxide init fish | source
|
||||
else
|
||||
echo "zoxide is not installed" >&2
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
# Execute the actual z command (defined by zoxide init)
|
||||
__zoxide_z $argv
|
||||
end
|
||||
@@ -1,24 +1,15 @@
|
||||
# Lazy-load zoxide on first use of zi command
|
||||
# Interactive zoxide with fzf (initialization handled in config.fish)
|
||||
function zi --description "zoxide interactive smart cd"
|
||||
# Initialize zoxide only once (shared flag with z.fish)
|
||||
if not set -q __zoxide_initialized
|
||||
set -g __zoxide_initialized 1
|
||||
|
||||
# Configure fzf options for zoxide interactive mode
|
||||
set -gx _ZO_FZF_OPTS '
|
||||
# Configure fzf options for zoxide interactive mode
|
||||
set -gx _ZO_FZF_OPTS '
|
||||
--preview="lsd -1 --color=always --icon=always {2..}"
|
||||
--preview-window=down,30%
|
||||
'
|
||||
|
||||
# Run zoxide init
|
||||
if command -q zoxide
|
||||
zoxide init fish | source
|
||||
else
|
||||
echo "zoxide is not installed" >&2
|
||||
return 1
|
||||
end
|
||||
if command -q zoxide
|
||||
__zoxide_zi $argv
|
||||
else
|
||||
echo "zoxide is not installed" >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
# Execute the actual zi command (defined by zoxide init)
|
||||
__zoxide_zi $argv
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user