174
return path;
175
}
177
>
export function untildify(path: string, userHome: string): string {
178
return path.replace(/^~($|\/|\\)/, `${userHome}$1`);
179
}
181
>
/**
182
>
* Shortens the paths but keeps them easy to distinguish.
183
>
* Replaces not important parts with ellipsis.
184
>
* Every shorten path matches only one original path and vice versa.
185
>
*
186
>
* Algorithm for shortening paths is as follows:
187
>
* 1. For every path in list, find unique substring of that path.
188
>
* 2. Unique substring along with ellipsis is shortened path of that path.
189
>
* 3. To find unique substring of path, consider every segment of length from 1 to path.length of path from end of string
190
>
* and if present segment is not substring to any other paths then present segment is unique path,
191
>
* else check if it is not present as suffix of any other path and present segment is suffix of path itself,
192
>
* if it is true take present segment as unique path.
193
>
* 4. Apply ellipsis to unique segment according to whether segment is present at start/in-between/end of path.
194
>
*
195
>
* Example 1
196
>
* 1. consider 2 paths i.e. ['a\\b\\c\\d', 'a\\f\\b\\c\\d']
197
>
* 2. find unique path of first path,
198
>
* a. 'd' is present in path2 and is suffix of path2, hence not unique of present path.
199
>
* b. 'c' is present in path2 and 'c' is not suffix of present path, similarly for 'b' and 'a' also.
200
>
* c. 'd\\c' is suffix of path2.
201
>
* d. 'b\\c' is not suffix of present path.
202
>
* e. 'a\\b' is not present in path2, hence unique path is 'a\\b...'.
203
>
* 3. for path2, 'f' is not present in path1 hence unique is '...\\f\\...'.
204
>
*
205
>
* Example 2
206
>
* 1. consider 2 paths i.e. ['a\\b', 'a\\b\\c'].
207
>
* a. Even if 'b' is present in path2, as 'b' is suffix of path1 and is not suffix of path2, unique path will be '...\\b'.
208
>
* 2. for path2, 'c' is not present in path1 hence unique path is '..\\c'.
209
>
*/
210
>
const ellipsis = '\u2026';
211
>
const unc = '\\\\';
212
>
const urlSchemaRegexp = /^[^:/\\?#]+?:\/\//;
213
>
const home = '~';
214
>
export function shorten(paths: string[], defaultPathSeparator: string = sep): string[] {
215
const shortenedPaths: string[] = new Array(paths.length);
216