From 25224cea4ddbfbe3945dcdcddc0f14af7b67aa03 Mon Sep 17 00:00:00 2001 From: Lev Velykoivanenko Date: Tue, 30 Mar 2021 13:12:55 +0200 Subject: [PATCH 1/2] Replace external tools with fish builtins Fix issue #22 Fix issue #21 Replace use of external tools (grep and perl) with fish builtin string. --- conf.d/__fasd_run.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf.d/__fasd_run.fish b/conf.d/__fasd_run.fish index b047077..d16eb23 100755 --- a/conf.d/__fasd_run.fish +++ b/conf.d/__fasd_run.fish @@ -1,10 +1,10 @@ function __fasd_expand_vars -d "Expands only the first occurance of a variable in the passed string without evaluating the string" - set -lx vars (echo -n $argv | grep -oP '(?!\\\\)\$\K([A-z_][A-z0-9_]*?)([^A-z0-9_]|\b|\n)' | perl -pe 's/(.+?)(?:[^A-z0-9_]|\b)$/\1\n/' | sort -u) + set -lx vars (string match -a -r '(?!\\\\)\$\K([A-z_][A-z0-9_]*?)(?:[^A-z0-9_]|\b|\n)' "$argv" | string replace -r '(.+?)(?:[^A-z0-9_]|\b)$' '$1' | sort -u) for var in $vars # Only replace if the variable is defined if set -q $var # Replacing the variable once is enough - set argv (string replace -r '([^\\\\]|\b)\$'"$var" '$1'"$$var" "$argv") + set argv (string replace -r '([^\\\\]|\b)\$'"$var" '${1}'"$$var" "$argv") end end # The following pipe does the same thing as fasd --sanitize From 2e2dd585ae68e4a9c3650509a0d241d412a5d70e Mon Sep 17 00:00:00 2001 From: Lev Velykoivanenko Date: Mon, 24 May 2021 09:44:50 +0200 Subject: [PATCH 2/2] Fix bug triggering exit warning in __fasd_run If the 'exit' command was part of the command line, then fish would give a warning and not exit due to how the fasd command was running in the background. Adding a disown after it will stop it from throwing this error. Fix small issue with printf formatting in __fasd_expand_vars --- conf.d/__fasd_run.fish | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conf.d/__fasd_run.fish b/conf.d/__fasd_run.fish index d16eb23..3f85d9b 100755 --- a/conf.d/__fasd_run.fish +++ b/conf.d/__fasd_run.fish @@ -8,12 +8,12 @@ function __fasd_expand_vars -d "Expands only the first occurance of a variable i end end # The following pipe does the same thing as fasd --sanitize - printf '%s\\n' "$argv" | sed -e 's/\([^\]\)$( *[^ ]* *\([^)]*\)))*/\1\2/g' -e 's/\([^\]\)[|&;<>$`{}]\{1,\}/\1 /g' | tr -s " " \n + printf %s\n $argv | sed -e 's/\([^\]\)$( *[^ ]* *\([^)]*\)))*/\1\2/g' -e 's/\([^\]\)[|&;<>$`{}]\{1,\}/\1 /g' | tr -s " " \n end function __fasd_run -e fish_postexec -d "fasd records the directories changed into" - set -lx RETVAL $status - if test $RETVAL -eq 0 # if there was no error + if test $status -eq 0 # if there was no error command fasd --proc (__fasd_expand_vars $argv) > "/dev/null" 2>&1 & + disown end end