Skip to content

Commit

Permalink
Fix __fasd_run.fish eval bug
Browse files Browse the repository at this point in the history
Fix eval bug causing unexpected behaviour with pipes, redirections,
and variable expansion.
  • Loading branch information
AbysmalBiscuit committed Mar 7, 2021
1 parent 2c15e16 commit 98fb387
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions conf.d/__fasd_run.fish
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
function __fasd_run -e fish_postexec -d "fasd takes record of the directories changed into"
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)
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")
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
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
command fasd --proc (command fasd --sanitize (eval echo "$argv") | tr -s " " \n) > "/dev/null" 2>&1 &
command fasd --proc (__fasd_expand_vars $argv) > "/dev/null" 2>&1 &
end
end

0 comments on commit 98fb387

Please sign in to comment.