fish: use zoxide instead of fre + fzf
This commit is contained in:
parent
6a5196b4d4
commit
09946832c1
2 changed files with 125 additions and 0 deletions
100
.config/fish/conf.d/zoxide.fish
Normal file
100
.config/fish/conf.d/zoxide.fish
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
# =============================================================================
|
||||||
|
#
|
||||||
|
# Utility functions for zoxide.
|
||||||
|
#
|
||||||
|
|
||||||
|
# pwd based on the value of _ZO_RESOLVE_SYMLINKS.
|
||||||
|
function __zoxide_pwd
|
||||||
|
builtin pwd -L
|
||||||
|
end
|
||||||
|
|
||||||
|
# A copy of fish's internal cd function. This makes it possible to use
|
||||||
|
# `alias cd=z` without causing an infinite loop.
|
||||||
|
if ! builtin functions --query __zoxide_cd_internal
|
||||||
|
if builtin functions --query cd
|
||||||
|
builtin functions --copy cd __zoxide_cd_internal
|
||||||
|
else
|
||||||
|
alias __zoxide_cd_internal='builtin cd'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# cd + custom logic based on the value of _ZO_ECHO.
|
||||||
|
function __zoxide_cd
|
||||||
|
__zoxide_cd_internal $argv
|
||||||
|
end
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
#
|
||||||
|
# Hook configuration for zoxide.
|
||||||
|
#
|
||||||
|
|
||||||
|
# Initialize hook to add new entries to the database.
|
||||||
|
function __zoxide_hook --on-variable PWD
|
||||||
|
test -z "$fish_private_mode"
|
||||||
|
and command zoxide add -- (__zoxide_pwd)
|
||||||
|
end
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
#
|
||||||
|
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
||||||
|
#
|
||||||
|
|
||||||
|
if test -z $__zoxide_z_prefix
|
||||||
|
set __zoxide_z_prefix 'z!'
|
||||||
|
end
|
||||||
|
set __zoxide_z_prefix_regex ^(string escape --style=regex $__zoxide_z_prefix)
|
||||||
|
|
||||||
|
# Jump to a directory using only keywords.
|
||||||
|
function __zoxide_z
|
||||||
|
set -l argc (count $argv)
|
||||||
|
if test $argc -eq 0
|
||||||
|
__zoxide_cd $HOME
|
||||||
|
else if test "$argv" = -
|
||||||
|
__zoxide_cd -
|
||||||
|
else if test $argc -eq 1 -a -d $argv[1]
|
||||||
|
__zoxide_cd $argv[1]
|
||||||
|
else if set -l result (string replace --regex $__zoxide_z_prefix_regex '' $argv[-1]); and test -n $result
|
||||||
|
__zoxide_cd $result
|
||||||
|
else
|
||||||
|
set -l result (command zoxide query --exclude (__zoxide_pwd) -- $argv)
|
||||||
|
and __zoxide_cd $result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Completions.
|
||||||
|
function __zoxide_z_complete
|
||||||
|
set -l tokens (commandline --current-process --tokenize)
|
||||||
|
set -l curr_tokens (commandline --cut-at-cursor --current-process --tokenize)
|
||||||
|
|
||||||
|
if test (count $tokens) -le 2 -a (count $curr_tokens) -eq 1
|
||||||
|
# If there are < 2 arguments, use `cd` completions.
|
||||||
|
complete --do-complete "'' "(commandline --cut-at-cursor --current-token) | string match --regex '.*/$'
|
||||||
|
else if test (count $tokens) -eq (count $curr_tokens); and ! string match --quiet --regex $__zoxide_z_prefix_regex. $tokens[-1]
|
||||||
|
# If the last argument is empty and the one before doesn't start with
|
||||||
|
# $__zoxide_z_prefix, use interactive selection.
|
||||||
|
set -l query $tokens[2..-1]
|
||||||
|
set -l result (zoxide query --exclude (__zoxide_pwd) --interactive -- $query)
|
||||||
|
and echo $__zoxide_z_prefix$result
|
||||||
|
commandline --function repaint
|
||||||
|
end
|
||||||
|
end
|
||||||
|
complete --command __zoxide_z --no-files --arguments '(__zoxide_z_complete)'
|
||||||
|
|
||||||
|
# Jump to a directory using interactive search.
|
||||||
|
function __zoxide_zi
|
||||||
|
set -l result (command zoxide query --interactive -- $argv)
|
||||||
|
and __zoxide_cd $result
|
||||||
|
end
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
#
|
||||||
|
# Commands for zoxide. Disable these using --no-cmd.
|
||||||
|
#
|
||||||
|
|
||||||
|
abbr --erase cd &>/dev/null
|
||||||
|
alias cd=__zoxide_z
|
||||||
|
|
||||||
|
abbr --erase cdi &>/dev/null
|
||||||
|
alias cdi=__zoxide_zi
|
||||||
|
|
||||||
|
set -gx _ZO_EXCLUDE_DIRS "$HOME/media:$HOME/media/*"
|
|
@ -28,6 +28,7 @@ if status is-interactive
|
||||||
eza --tree --color=always $argv | bat --wrap=never
|
eza --tree --color=always $argv | bat --wrap=never
|
||||||
end
|
end
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
## Directory jumping with frecency
|
## Directory jumping with frecency
|
||||||
|
|
||||||
function fre_after_cd --on-variable PWD
|
function fre_after_cd --on-variable PWD
|
||||||
|
@ -40,6 +41,30 @@ if status is-interactive
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
bind \cg jump
|
bind \cg jump
|
||||||
|
||||||| parent of 931ae14 (fish: use zoxide instead of fre + fzf)
|
||||||
|
function rg --wraps rg --description 'ripgrep with bat'
|
||||||
|
/usr/bin/rg --color=always $argv | bat --wrap=never
|
||||||
|
end
|
||||||
|
|
||||||
|
## Directory jumping with frecency
|
||||||
|
|
||||||
|
function fre_after_cd --on-variable PWD
|
||||||
|
fre --add "$PWD"
|
||||||
|
end
|
||||||
|
|
||||||
|
function jump
|
||||||
|
set _dir $(fre --sorted | fzf --no-sort --border=rounded --layout=reverse '--bind=ctrl-g:become(br -f --conf ~/.config/broot/select.hjson $(git rev-parse --show-toplevel 2>/dev/null || pwd))')
|
||||||
|
[ -n "$_dir" ] && pushd $_dir >>/dev/null
|
||||||
|
commandline -f repaint
|
||||||
|
end
|
||||||
|
bind \cg jump
|
||||||
|
=======
|
||||||
|
function rg --wraps rg --description 'ripgrep with bat'
|
||||||
|
/usr/bin/rg --color=always $argv | bat --wrap=never
|
||||||
|
end
|
||||||
|
|
||||||
|
bind \cg __zoxide_zi
|
||||||
|
>>>>>>> 931ae14 (fish: use zoxide instead of fre + fzf)
|
||||||
|
|
||||||
function git_jump
|
function git_jump
|
||||||
set _dir $(git rev-parse --show-toplevel 2>/dev/null || pwd)
|
set _dir $(git rev-parse --show-toplevel 2>/dev/null || pwd)
|
||||||
|
|
Loading…
Reference in a new issue