Sun Jun 23 10:25:35 PM CEST 2024

This commit is contained in:
Thomas Avé 2024-06-23 22:25:35 +02:00
parent f30ff52f92
commit 5da182da3d
4 changed files with 86 additions and 85 deletions

View File

@ -27,7 +27,8 @@
commands = { commands = {
jump = '' jump = ''
''${{ ''${{
res=$(zsh -c "source $HOME/.zshrc && find_global d") source ${../zsh/files/functions.zsh}
res=$(zsh -c " && find_global d")
lf -remote "send $id cd \"$res\"" lf -remote "send $id cd \"$res\""
}} }}
''; '';

View File

@ -73,7 +73,7 @@
source ${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k/powerlevel10k.zsh-theme source ${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k/powerlevel10k.zsh-theme
source ${./files/p10k.zsh} source ${./files/p10k.zsh}
source ${pkgs.zsh-vi-mode}/share/zsh-vi-mode/zsh-vi-mode.plugin.zsh source ${pkgs.zsh-vi-mode}/share/zsh-vi-mode/zsh-vi-mode.plugin.zsh
source ${./files/keys.zsh} source ${./files/functions.zsh}
function zvm_after_init() { function zvm_after_init() {
source ${pkgs.nix-index}/etc/profile.d/command-not-found.sh source ${pkgs.nix-index}/etc/profile.d/command-not-found.sh
source ${./files/term.zsh} source ${./files/term.zsh}
@ -82,6 +82,7 @@
source "$(fzf-share)/key-bindings.zsh" source "$(fzf-share)/key-bindings.zsh"
source "$(fzf-share)/completion.zsh" source "$(fzf-share)/completion.zsh"
fi fi
source ${./files/keys.zsh}
} }
function run() { function run() {
nix run "nixpkgs#$1" -- "''${@:2}" nix run "nixpkgs#$1" -- "''${@:2}"

View File

@ -0,0 +1,82 @@
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.
cd $dir
zle accept-line
local ret=$?
unset dir # ensure this doesn't end up appearing in prompt expansion
zle reset-prompt
}
function find_local() {
fd . -t $1 | fzy -l 20
}
function find_global() {
file_type=$1
FZY_CACHE=~/.cache/fzy_paths_$file_type
if [ -f $FZY_CACHE ]; then
if [ $(stat -c %Y $FZY_CACHE) -lt $(date +%s -d '-1 day') ]; then
rm $FZY_CACHE
fi
fi
if [ ! -f $FZY_CACHE ]; then
PATHS=""
for i in "$LOCAL_SEARCH_DIRS[@]"; do
if [ -d $i ]; then
PATHS="$PATHS\n$i\n$(fd . $i -t $file_type -d 8)"
fi
done
for i in "$REMOTE_SEARCH_DIRS[@]"; do
if [ -d $i ]; then
PATHS="$PATHS\n$i\n$(ssh mallorea fd . \"$i\" -t $file_type -d 8)"
fi
done
echo "$PATHS" > $FZY_CACHE
fi
file="$(cat $FZY_CACHE | fzy -l 20)"
echo "$file" | cat - $FZY_CACHE | awk '!x[$0]++' > /tmp/fzy_paths_$file_type && mv /tmp/fzy_paths_$file_type $FZY_CACHE
echo "$file"
}
function open_path() {
file_type=$1
search_fn=$2
selection="$($search_fn $file_type)"
if [ "$selection" = "" ]; then
zle reset-prompt
return
fi
if [ "$LBUFFER" = "" ]; then
if [ "$file_type" = "d" ]; then
cd_to "$selection"
else
selection=$(realpath "$selection")
parent=$(dirname "$selection")
cd_to "$parent"
nvim "$selection"
fi
else
emulate -L zsh
zle -I
LBUFFER="${LBUFFER}\"$selection\""
zle reset-prompt
fi
}
function open_global_path_d() { open_path d find_global }
function open_global_path_f() { open_path f find_global }
function open_local() { open_path f find_local }
function register_key() {
zle -N $2
bindkey "^$1" $2
bindkey -M emacs "^$1" $2
bindkey -M vicmd "^$1" $2
bindkey -M viins "^$1" $2
}

View File

@ -1,78 +1,3 @@
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.
cd $dir
zle accept-line
local ret=$?
unset dir # ensure this doesn't end up appearing in prompt expansion
zle reset-prompt
}
function find_local() {
fd . -t $1 | fzy -l 20
}
function find_global() {
file_type=$1
FZY_CACHE=~/.cache/fzy_paths_$file_type
if [ -f $FZY_CACHE ]; then
if [ $(stat -c %Y $FZY_CACHE) -lt $(date +%s -d '-1 day') ]; then
rm $FZY_CACHE
fi
fi
if [ ! -f $FZY_CACHE ]; then
PATHS=""
for i in "$LOCAL_SEARCH_DIRS[@]"; do
if [ -d $i ]; then
PATHS="$PATHS\n$i\n$(fd . $i -t $file_type -d 8)"
fi
done
for i in "$REMOTE_SEARCH_DIRS[@]"; do
if [ -d $i ]; then
PATHS="$PATHS\n$i\n$(ssh mallorea fd . \"$i\" -t $file_type -d 8)"
fi
done
echo "$PATHS" > $FZY_CACHE
fi
file="$(cat $FZY_CACHE | fzy -l 20)"
echo "$file" | cat - $FZY_CACHE | awk '!x[$0]++' > /tmp/fzy_paths_$file_type && mv /tmp/fzy_paths_$file_type $FZY_CACHE
echo "$file"
}
function open_path() {
file_type=$1
search_fn=$2
selection="$($search_fn $file_type)"
if [ "$selection" = "" ]; then
zle reset-prompt
return
fi
if [ "$LBUFFER" = "" ]; then
if [ "$file_type" = "d" ]; then
cd_to "$selection"
else
selection=$(realpath "$selection")
parent=$(dirname "$selection")
cd_to "$parent"
nvim "$selection"
fi
else
emulate -L zsh
zle -I
LBUFFER="${LBUFFER}\"$selection\""
zle reset-prompt
fi
}
function open_global_path_d() { open_path d find_global }
function open_global_path_f() { open_path f find_global }
function open_local() { open_path f find_local }
zle -N push_local_files zle -N push_local_files
zle -N find_local_directories zle -N find_local_directories
@ -114,14 +39,6 @@ bindkey -M vicmd "^R" fzf-history-widget
bindkey -M viins "^R" fzf-history-widget bindkey -M viins "^R" fzf-history-widget
bindkey -M emacs "^R" fzf-history-widget bindkey -M emacs "^R" fzf-history-widget
function register_key() {
zle -N $2
bindkey "^$1" $2
bindkey -M emacs "^$1" $2
bindkey -M vicmd "^$1" $2
bindkey -M viins "^$1" $2
}
register_key "T" open_global_path_d register_key "T" open_global_path_d
register_key "E" open_global_path_f register_key "E" open_global_path_f
register_key "W" open_local register_key "W" open_local