From a859d5694e4f2dbe9b15fd948e4a3d04c7543f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Av=C3=A9?= Date: Wed, 24 Apr 2024 00:00:18 +0200 Subject: [PATCH] Fix lf + zsh find_global --- .config/lf/lfrc | 27 +++---------------- .config/zsh/.zshrc | 66 ++++++++++++++++++---------------------------- 2 files changed, 28 insertions(+), 65 deletions(-) diff --git a/.config/lf/lfrc b/.config/lf/lfrc index e4b8403..78f34e2 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -15,29 +15,8 @@ map - $nvim -c "lua require(\"oil\").open(\"$PWD\")" map open cmd jump ${{ - 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="$(/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME ls-files | xargs -n 1 dirname | uniq | grep -v '^\.$' | parallel echo ~/{})" - search_dirs=(~/Workspace/ \ - /home/server/Storage/Thomas/ \ - ) - for i in $search_dirs ; do - if [ -d $i ]; then - PATHS="$PATHS\n$i" - PATHS="$PATHS\n$(ssh mallorea fdfind . $i -t d -d 8)" - fi - done - echo -e $PATHS > $FZY_CACHE - fi - res="$(cat $FZY_CACHE | fzy -l 20)" - res="$(printf '%s' "$res" | sed 's/\\/\\\\/g;s/"/\\"/g')" - lf -remote "send $id cd \"$res\"" + res=$(zsh -c "source $HOME/.zshrc && find_global d") + lf -remote "send $id cd \"$res\"" }} -map :jump +map :jump diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 61515ef..ae4f014 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -48,40 +48,11 @@ function cd_to() { zle reset-prompt } -# Use FZY instead of FZF for ctrl-t -function find_global_directories() { - 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="$(/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME ls-files | xargs -n 1 dirname | uniq | grep -v '^\.$' | parallel echo ~/{})" - search_dirs=( \ - ~/Workspace/ \ - /home/server/Storage/Thomas/ \ - ) - for i in $search_dirs ; do - if [ -d $i ]; then - PATHS="$PATHS\n$i" - PATHS="$PATHS\n$(fd . $i -t d -d 8)" - fi - done - echo -e $PATHS > $FZY_CACHE - fi - cd_to "$(cat $FZY_CACHE | fzy -l 20)" -} - function find_local_directories() { - zle -I cd_to "$(fd . -t d | fzy -l 20)" } function edit_local_files() { - zle -I file=$(fd . -t f | fzy -l 20) if [ -z "$file" ]; then return 0 @@ -89,32 +60,45 @@ function edit_local_files() { nvim "$file" } -function edit_global_files() { - zle -I - FZY_CACHE=~/.cache/fzy_file_paths +function find_global() { + file_type=$1 + FZY_CACHE=~/.cache/fzy_paths_$file_type if [ -f $FZY_CACHE ]; then - # Check if cache is older than 1 day - if [ $(($(date +%s) - $(date -r $FZY_CACHE +%s))) -gt 86400 ]; 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="$(/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME ls-files | parallel echo ~/{})" - search_dirs=(~/Workspace/ ) - for i in $search_dirs ; do + PATHS="$(/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME ls-files)" + if [ "$file_type" = "d" ]; then + PATHS="$(echo -e $PATHS | xargs -n 1 dirname | uniq | grep -v '^\.$' | parallel echo ~/{})" + else + PATHS="$(echo -e $PATHS | parallel echo ~/{})" + fi + search_dirs=(~/Workspace/ ~/Containers/ /home/server/Storage/Thomas/) + for i in "$search_dirs[@]"; do if [ -d $i ]; then - PATHS="$PATHS\n$(fd . $i -t f)" + PATHS="$PATHS$i\n" + PATHS+="$(fd . $i -t $file_type -d 8)" fi done - echo -e $PATHS > $FZY_CACHE + echo -e "$PATHS" > $FZY_CACHE fi - file=$(cat $FZY_CACHE | fzy -l 20) + file="$(cat $FZY_CACHE | fzy -l 20)" + echo $file +} + +function find_global_directories() { + cd_to "$(find_global d)" +} + +function edit_global_files() { + file="$(find_global f)" if [ -z "$file" ]; then return 0 fi cd_to "$(dirname $file)" nvim "$file" - } function zvm_after_init() {