Created
March 1, 2017 14:29
-
-
Save dpastoor/89acd053edf21563940c32b22280ab7b to your computer and use it in GitHub Desktop.
tilde expansion go https://github.com/mattn/go-zglob/blob/95345c4e1c0ebc9d16a3284177f09360f4d20fab/zglob.go#L39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if n == 0 && i == "~" { | |
if runtime.GOOS == "windows" { | |
i = os.Getenv("USERPROFILE") | |
} else { | |
i = os.Getenv("HOME") | |
} | |
} | |
for n, i := range strings.Split(filepath.ToSlash(pattern), "/") { | |
if root == "" && strings.Index(i, "*") != -1 { | |
if globmask == "" { | |
root = "." | |
} else { | |
root = filepath.ToSlash(globmask) | |
} | |
} | |
if n == 0 && i == "~" { | |
if runtime.GOOS == "windows" { | |
i = os.Getenv("USERPROFILE") | |
} else { | |
i = os.Getenv("HOME") | |
} | |
} | |
if envre.MatchString(i) { | |
i = strings.Trim(strings.Trim(os.Getenv(i[1:]), "()"), `"`) | |
} | |
globmask = filepath.Join(globmask, i) | |
if n == 0 { | |
if runtime.GOOS == "windows" && filepath.VolumeName(i) != "" { | |
globmask = i + "/" | |
} else if len(globmask) == 0 { | |
globmask = "/" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment