OSDN Git Service

completion/INIT: Consider $PATHEXT for Cygwin (#38878)
authormagicant <magicant@048f04df-13f5-43d7-8114-9f9ceecaec24>
Sat, 26 Jan 2019 07:44:47 +0000 (07:44 +0000)
committermagicant <magicant@048f04df-13f5-43d7-8114-9f9ceecaec24>
Sat, 26 Jan 2019 07:44:47 +0000 (07:44 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/yash/yash/trunk@3975 048f04df-13f5-43d7-8114-9f9ceecaec24

share/completion/INIT

index 0cebb9f..841b2c2 100644 (file)
@@ -1,4 +1,4 @@
-# (C) 2010-2012 magicant
+# (C) 2010-2019 magicant
 
 # This file is autoloaded when completion is first performed by the shell.
 # This file contains utility functions that are commonly used by many
@@ -567,29 +567,49 @@ function completion//reexecute {
                return
        fi
 
-       unset opt OPTIND extonly fallback
+       typeset compfunc= cmdbase
+       if ! command -f completion//findcompfunc "$1"; then
+               cmdbase="${1%.*}"
+               if [ "$cmdbase" != "$1" ] && [ "${PATHEXT:+set}" = set ] &&
+                       grep -iqx "${{PATHEXT//';'/'\|'}//'.'/'\.'}" <<< "${1#"$cmdbase"}" &&
+                       command -f completion//findcompfunc "$cmdbase" &&
+                       [ $OPTIND -gt $# ]; then
+                       WORDS=("$cmdbase" "${WORDS[2,-1]}")
+               fi
+       fi
+       set -- "$compfunc"
+       unset opt OPTIND extonly fallback compfunc cmdbase
+
+       if [ "$1" ]; then
+               command -f "$1"
+       else
+               complete -P "${PREFIX-}" -f
+       fi
 
-       # load the function if not yet loaded, and call the function
+}
+
+# $1 = command name
+# The result is set to the "compfunc" variable
+function completion//findcompfunc
        if command -vf "completion/$1" >/dev/null 2>&1; then
-               command -f "completion/$1"
+               compfunc="completion/$1"
        elif command -vf "completion/${1##*/}" >/dev/null 2>&1; then
-               command -f "completion/${1##*/}"
+               compfunc="completion/${1##*/}"
        elif . -AL "completion/$1" 2>/dev/null
                        command -vf "completion/$1" >/dev/null 2>&1; then
-               command -f "completion/$1"
+               compfunc="completion/$1"
        elif command -vf "completion/${1##*/}" >/dev/null 2>&1; then
-               command -f "completion/${1##*/}"
+               compfunc="completion/${1##*/}"
        elif . -AL "completion/${1##*/}" 2>/dev/null
                        command -vf "completion/$1" >/dev/null 2>&1; then
-               command -f "completion/$1"
+               compfunc="completion/$1"
        elif command -vf "completion/${1##*/}" >/dev/null 2>&1; then
-               command -f "completion/${1##*/}"
+               compfunc="completion/${1##*/}"
        else
-               complete -P "${PREFIX-}" -f
+               compfunc=
+               false
        fi
 
-}
-
 
 # Prints all commands in $PATH.
 # Given an argument, it is treated as a pattern that filters results.