Skip to content

Commit

Permalink
Replace external tools with fish builtins
Browse files Browse the repository at this point in the history
Fix issue fishgretel#22
Fix issue fishgretel#21

Replace use of external tools (grep and perl) with fish builtin string.
  • Loading branch information
AbysmalBiscuit committed Mar 30, 2021
1 parent 98fb387 commit 25224ce
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions conf.d/__fasd_run.fish
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 25224ce

Please sign in to comment.