diff options
author | Shav Kinderlehrer <[email protected]> | 2023-08-10 10:44:06 -0400 |
---|---|---|
committer | Shav Kinderlehrer <[email protected]> | 2023-08-10 10:44:06 -0400 |
commit | 26ba41d08f86fc006edf9c0552205e2851a1060b (patch) | |
tree | 06446a566208b343edfd6ad8eec0258afa39ab73 /source/comp/path.d | |
parent | db53ee6c3bdd8d14c196f06b6377f2418779f82d (diff) | |
download | prim-26ba41d08f86fc006edf9c0552205e2851a1060b.tar.gz prim-26ba41d08f86fc006edf9c0552205e2851a1060b.zip |
Fix rendering issues + add git comp
Diffstat (limited to 'source/comp/path.d')
-rw-r--r-- | source/comp/path.d | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/source/comp/path.d b/source/comp/path.d new file mode 100644 index 0000000..b8f9914 --- /dev/null +++ b/source/comp/path.d @@ -0,0 +1,33 @@ +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 ~ "/"; + +} |