34 lines
586 B
D
34 lines
586 B
D
module comp.path;
|
|
|
|
import std.conv;
|
|
import std.regex;
|
|
import std.array;
|
|
|
|
import std.file : getcwd;
|
|
import std.path : expandTilde;
|
|
import std.algorithm : reverse;
|
|
|
|
string path(int pathlen) {
|
|
string ps;
|
|
|
|
string home = expandTilde("~");
|
|
string path = replaceFirst(getcwd(), regex(home), "~");
|
|
|
|
string[] splitPath = path.split("/").reverse();
|
|
|
|
string[] revSplitPath;
|
|
for (int i = 0; i < pathlen; i++) {
|
|
if (i >= splitPath.length)
|
|
break;
|
|
|
|
revSplitPath ~= splitPath[i];
|
|
}
|
|
|
|
splitPath = revSplitPath.reverse();
|
|
|
|
ps ~= splitPath.join("/");
|
|
|
|
return ps ~ "/";
|
|
|
|
}
|