Better fzy

This commit is contained in:
Thomas Avé 2024-03-30 14:35:01 +01:00
parent a879cc0d2a
commit dc9b23333a
6 changed files with 75 additions and 30 deletions

3
.gitmodules vendored
View File

@ -13,3 +13,6 @@
[submodule "zsh/zsh-vi-mode"] [submodule "zsh/zsh-vi-mode"]
path = zsh/zsh-vi-mode path = zsh/zsh-vi-mode
url = https://github.com/jeffreytse/zsh-vi-mode.git url = https://github.com/jeffreytse/zsh-vi-mode.git
[submodule "zsh/zsh-quiet-accept-line"]
path = zsh/zsh-quiet-accept-line
url = git@github.com:AdrieanKhisbe/zsh-quiet-accept-line.git

View File

@ -6,3 +6,4 @@ Feywild
closeby closeby
ECML ECML
theshold-based theshold-based
distill

View File

@ -87,15 +87,40 @@ function zvm_after_init() {
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
fi fi
source "$XDG_CONFIG_HOME/zsh/zsh-quiet-accept-line/quiet-accept-line.plugin.zsh"
function cd_to() {
setopt localoptions pipefail no_aliases 2> /dev/null
local dir=$1
if [[ -z "$dir" ]]; then
zle redisplay
return 0
fi
zle push-line # Clear buffer. Auto-restored on next prompt.
BUFFER="cd ${(q)dir}"
zle quiet-accept-line
local ret=$?
unset dir # ensure this doesn't end up appearing in prompt expansion
zle reset-prompt
return $ret
}
# Use FZY instead of FZF for ctrl-t # Use FZY instead of FZF for ctrl-t
function find_files() { function find_global_files() {
zle -I zle -I
FZY_CACHE=~/.cache/fzy_paths
if [ -f $FZY_CACHE ]; then
# Check if cache is older than 1 day
if [ $(($(date +%s) - $(date -r $FZY_CACHE +%s))) -gt 86400 ]; then
rm $FZY_CACHE
fi
fi
if [ ! -f $FZY_CACHE ]; then
PATHS="" PATHS=""
if [ -d ~/.dotfiles ]; then if [ -d ~/.dotfiles ]; then
PATHS="$PATHS\n$(fd . ~/.dotfiles -t d -d 1)" PATHS="$PATHS\n$(fd . ~/.dotfiles -t d -d 2)"
fi fi
if [ -d ~/Workspace ]; then if [ -d ~/Workspace ]; then
PATHS="$PATHS\n$(fd . ~/Workspace -t d -d 5)" PATHS="$PATHS\n$(fd . ~/Workspace -t d -d 8)"
fi fi
if [ -d ~/Containers ]; then if [ -d ~/Containers ]; then
PATHS="$PATHS\n$(fd . ~/Containers -t d -d 2)" PATHS="$PATHS\n$(fd . ~/Containers -t d -d 2)"
@ -108,15 +133,30 @@ function zvm_after_init() {
PATHS="$PATHS\n~/Storage/Thomas" PATHS="$PATHS\n~/Storage/Thomas"
PATHS="$PATHS\n$(fd . ~/Storage/Thomas -t d -d 1)" PATHS="$PATHS\n$(fd . ~/Storage/Thomas -t d -d 1)"
fi fi
BUFFER=cd "$(echo $PATHS | fzy -l 20)" echo -e $PATHS > $FZY_CACHE
fi
cd_to "$(cat $FZY_CACHE | fzy -l 20)"
zle accept-line zle accept-line
clear
} }
zle -N find_files
bindkey "^T" find_files function find_local_files() {
bindkey -M emacs "^T" find_files zle -I
bindkey -M vicmd "^T" find_files cd_to "$(fd . -t d | fzy -l 20)"
bindkey -M viins "^T" find_files zle accept-line
}
zle -N find_global_files
zle -N find_local_files
bindkey "^T" find_global_files
bindkey -M emacs "^T" find_global_files
bindkey -M vicmd "^T" find_global_files
bindkey -M viins "^T" find_global_files
bindkey "^Y" find_local_files
bindkey -M emacs "^Y" find_local_files
bindkey -M vicmd "^Y" find_local_files
bindkey -M viins "^Y" find_local_files
} }
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*' zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*'

@ -1 +1 @@
Subproject commit 307bce24d19fa09d971a0d33c39f3c9fda82924e Subproject commit da9b03777c4f2390c7e3f5c720ee4689336f811b

@ -0,0 +1 @@
Subproject commit 2081e8b394a605d3b776c4318cf77b4f067dc4a8

@ -1 +1 @@
Subproject commit 1f28e1886dc8e49f41b817634d5c7695b6abb145 Subproject commit 7cf6fd19cf2ab38ec5b116eced158377cb3c35f6