diff --git a/home/dot_config/fish/config.fish.tmpl b/home/dot_config/fish/config.fish.tmpl index cd6b5ae..87dd6ab 100644 --- a/home/dot_config/fish/config.fish.tmpl +++ b/home/dot_config/fish/config.fish.tmpl @@ -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 ' (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 diff --git a/home/dot_config/fish/functions/_fzf_discover_directory.fish b/home/dot_config/fish/functions/_fzf_discover_directory.fish new file mode 100644 index 0000000..24148a7 --- /dev/null +++ b/home/dot_config/fish/functions/_fzf_discover_directory.fish @@ -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 diff --git a/home/dot_config/fish/functions/_fzf_discover_home.fish b/home/dot_config/fish/functions/_fzf_discover_home.fish new file mode 100644 index 0000000..716c8a3 --- /dev/null +++ b/home/dot_config/fish/functions/_fzf_discover_home.fish @@ -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 diff --git a/home/dot_config/fish/functions/z.fish b/home/dot_config/fish/functions/z.fish deleted file mode 100644 index f9e776d..0000000 --- a/home/dot_config/fish/functions/z.fish +++ /dev/null @@ -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 diff --git a/home/dot_config/fish/functions/zi.fish b/home/dot_config/fish/functions/zi.fish index b2b4a74..5a50992 100644 --- a/home/dot_config/fish/functions/zi.fish +++ b/home/dot_config/fish/functions/zi.fish @@ -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