Skip to content

Commit 9a16edd

Browse files
authored
Merge pull request #20 from AbysmalBiscuit/master
Fix __fasd_run.fish eval bug
2 parents 2c15e16 + 98fb387 commit 9a16edd

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

conf.d/__fasd_run.fish

100644100755
+15-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
function __fasd_run -e fish_postexec -d "fasd takes record of the directories changed into"
1+
function __fasd_expand_vars -d "Expands only the first occurance of a variable in the passed string without evaluating the string"
2+
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)
3+
for var in $vars
4+
# Only replace if the variable is defined
5+
if set -q $var
6+
# Replacing the variable once is enough
7+
set argv (string replace -r '([^\\\\]|\b)\$'"$var" '$1'"$$var" "$argv")
8+
end
9+
end
10+
# The following pipe does the same thing as fasd --sanitize
11+
printf '%s\\n' "$argv" | sed -e 's/\([^\]\)$( *[^ ]* *\([^)]*\)))*/\1\2/g' -e 's/\([^\]\)[|&;<>$`{}]\{1,\}/\1 /g' | tr -s " " \n
12+
end
13+
14+
function __fasd_run -e fish_postexec -d "fasd records the directories changed into"
215
set -lx RETVAL $status
316
if test $RETVAL -eq 0 # if there was no error
4-
command fasd --proc (command fasd --sanitize (eval echo "$argv") | tr -s " " \n) > "/dev/null" 2>&1 &
17+
command fasd --proc (__fasd_expand_vars $argv) > "/dev/null" 2>&1 &
518
end
619
end

0 commit comments

Comments
 (0)