File tree Expand file tree Collapse file tree 1 file changed +27
-3
lines changed Expand file tree Collapse file tree 1 file changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -127,14 +127,38 @@ proc expandTilde*(path: string): string {.
127
127
assert expandTilde("~/foo/bar") == getHomeDir() / "foo/bar"
128
128
assert expandTilde("/foo/bar") == "/foo/bar"
129
129
130
+ template tryGetHomeOrRet =
131
+ result = getHomeDir()
132
+ if result == "":
133
+ result = path
134
+ return
135
+
130
136
if len(path) == 0 or path[0] != '~':
131
137
result = path
132
138
elif len(path) == 1:
133
- result = getHomeDir()
139
+ tryGetHomeOrRet
134
140
elif (path[1] in {DirSep, AltSep}):
135
- result = getHomeDir() / path.substr(2)
141
+ tryGetHomeOrRet
142
+ result = result / path.substr(2)
143
+ elif compiles(getHomeDir("bob")):
144
+ # handle path beginning with `~bob` and `~bob/`
145
+ # which means home of bob
146
+ var i = path.find(DirSep, 1)
147
+ if i < 0:
148
+ i = len(path)
149
+
150
+ let
151
+ name = path[1..<i]
152
+ userhome = getHomeDir(name)
153
+
154
+ if userhome == "" and hostOS == "vsworks":
155
+ # XXX: As of the moment this line is written,
156
+ # hostOS won't be "vsworks" yet.
157
+ return path
158
+
159
+ result = userhome & path.substr(i)
160
+
136
161
else:
137
- # TODO: handle `~bob` and `~bob/` which means home of bob
138
162
result = path
139
163
140
164
proc quoteShellWindows*(s: string): string {.noSideEffect, rtl, extern: "nosp$1".} =
You can’t perform that action at this time.
0 commit comments