diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2015-03-20 19:15:46 +0000 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@googlemail.com> | 2015-03-20 19:15:46 +0000 |
commit | 880e39d12307809cb81ffcf4669a28527e9076f8 (patch) | |
tree | 8896d6b53c805a116eea2747584565d903c8f272 | |
parent | 7418227ebbbc826e388a43ee05f5b21f4cf7de20 (diff) | |
parent | 1320efcf90021fe8b60eb27cea046f837b15baa6 (diff) | |
download | Nim-880e39d12307809cb81ffcf4669a28527e9076f8.tar.gz |
Merge pull request #2358 from gradha/pr_expands_paths_in_find_exe
Expands tildes for entries in $PATH when looking for a binary.
-rw-r--r-- | lib/pure/os.nim | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 82d6177e1..f53abe81d 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -1863,16 +1863,21 @@ proc getFileSize*(file: string): BiggestInt {.rtl, extern: "nos$1", close(f) else: raiseOSError(osLastError()) +proc expandTilde*(path: string): string {.tags: [ReadEnvEffect].} + proc findExe*(exe: string): string {.tags: [ReadDirEffect, ReadEnvEffect].} = ## Searches for `exe` in the current working directory and then ## in directories listed in the ``PATH`` environment variable. ## Returns "" if the `exe` cannot be found. On DOS-like platforms, `exe` - ## is added an ``.exe`` file extension if it has no extension. + ## is added the `ExeExt <#ExeExt>`_ file extension if it has none. result = addFileExt(exe, os.ExeExt) if existsFile(result): return var path = string(os.getEnv("PATH")) for candidate in split(path, PathSep): - var x = candidate / result + when defined(windows): + var x = candidate / result + else: + var x = expandTilde(candidate) / result if existsFile(x): return x result = "" |