prim/source/prompt/rps1.d

39 lines
689 B
D
Raw Normal View History

2023-08-09 20:01:15 +00:00
module prompt.rps1;
import std.conv;
2023-08-09 20:33:14 +00:00
import std.regex;
import std.array;
import std.file : getcwd;
import std.path : expandTilde;
import std.algorithm : reverse;
2023-08-09 20:01:15 +00:00
import prim.opt;
import style;
import style.color;
import style.font;
string rps1(Opts opt) {
string ps;
2023-08-09 20:33:14 +00:00
string home = expandTilde("~");
string path = replaceFirst(getcwd(), regex(home), "~");
2023-08-09 20:01:15 +00:00
2023-08-09 20:33:14 +00:00
string[] splitPath = path.split("/").reverse();
string[] revSplitPath;
for (int i = 0; i < opt.pathlen; i++) {
if (i >= splitPath.length)
break;
revSplitPath ~= splitPath[i];
}
2023-08-09 20:01:15 +00:00
2023-08-09 20:33:14 +00:00
splitPath = revSplitPath.reverse();
ps ~= splitPath.join("/");
return ps.set(Font.italic).set(Color.yellow);
}