viconf is now significantly faster

This commit is contained in:
2024-11-17 03:44:21 -05:00
parent ff7d6dcadc
commit 287281907b

View File

@@ -3,47 +3,42 @@ pkgs.writeShellApplication {
name = "viconf"; name = "viconf";
runtimeInputs = with pkgs; [ coreutils fd ripgrep fzf ]; runtimeInputs = with pkgs; [ coreutils fd ripgrep fzf ];
text = '' text = ''
set -- "''${1:-}" open_file() {
if [ ! $# -lt 1 ]; then file="$1"
results=$(find "$FLAKEPATH" -exec find {} \; | sort | uniq | rg '\.nix$') if grep -Pq "[^\x00-\x7F]" "$file"; then
numresults=$(echo "$results" | wc -l) NIXD_FLAGS="--semantic-tokens=false" nvim "$file"
else
results=$(find "$FLAKEPATH" -wholename "*$1*" -exec find {} \; | sort | uniq | rg '\.nix$')
numresults=$(echo "$results" | wc -l)
fi
[ "$numresults" -eq 0 ] && echo "$1 not found in \$FLAKEPATH" && exit 1
if [ "$numresults" -gt 1 ]; then
# cut up the paths to give shorter path names to fuzzy finder
results_prefix=$(echo "$results" | tail -n 1 | cut -d'/' -f-3)
results=$(echo "$results" | cut -d'/' -f4-)
if [ -n "$1" ]; then
results=$(echo "$results" | grep "$1")
fi
file=$(echo "$results" | tr ' ' '\n' | fzf)
if [ -n "$file" ]; then
file="$results_prefix/$file"
else
exit 1
fi
# Check if the file contains any non-UTF-8 characters
if grep --color='auto' -P -q "[^\x00-\x7F]" "$file"; then
NIXD_FLAGS="--semantic-tokens=false" nvim "$results_prefix"/"$file"
else else
nvim "$file" nvim "$file"
fi fi
}
if [ $# -eq 1 ]; then
results=$(find "$FLAKEPATH" -type f -name '*.nix' -path "*$1*")
else else
# Check if the file contains any non-UTF-8 characters results=$(find "$FLAKEPATH" -type f -name '*.nix')
if grep --color='auto' -P -q "[^\x00-\x7F]" "$results"; then
NIXD_FLAGS="--semantic-tokens=false" nvim "$results"
else
nvim "$results"
fi fi
numresults=$(echo "$results" | grep -c '^')
if [ "$numresults" -eq 0 ]; then
echo "$1 not found in \$FLAKEPATH"
exit 1
elif [ "$numresults" -eq 1 ]; then
file="$results"
open_file "$file"
exit 0
fi
# Handle multiple results
results_prefix=$(echo "$results" | head -n 1 | cut -d'/' -f-4)
results=$(echo "$results" | cut -d'/' -f5- | grep "$1")
file=$(echo "$results" | fzf)
if [ -n "$file" ]; then
file="$results_prefix/$file"
open_file "$file"
else
exit 1
fi fi
''; '';
} }