Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace external tools with fish builtins #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions conf.d/__fasd_run.fish
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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
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