summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xprimbin1384817 -> 2618401 bytes
-rw-r--r--source/app.d12
-rw-r--r--source/opt.d2
-rw-r--r--source/prompt/rps1.d27
-rw-r--r--source/style/package.d2
5 files changed, 37 insertions, 6 deletions
diff --git a/prim b/prim
index 9d75862..eec52df 100755
--- a/prim
+++ b/prim
Binary files differ
diff --git a/source/app.d b/source/app.d
index d1b18b9..60542d6 100644
--- a/source/app.d
+++ b/source/app.d
@@ -10,9 +10,17 @@ import prompt.preexec;
import style;
import style.color;
-void main(string[] argv) {
+Opts defaultOpts() {
Opts opts;
+ opts.pathlen = 3;
+
+ return opts;
+}
+
+void main(string[] argv) {
+ Opts opts = defaultOpts();
+
GetoptResult args = getopt(
argv,
std.getopt.config.bundling,
@@ -28,6 +36,8 @@ void main(string[] argv) {
std.getopt.config.required,
"status", "previous command exit code", &opts.status,
+
+ "pathlen", "set length of displayed path", &opts.pathlen,
);
if (args.helpWanted) {
diff --git a/source/opt.d b/source/opt.d
index 1236ac9..3c8c706 100644
--- a/source/opt.d
+++ b/source/opt.d
@@ -5,6 +5,8 @@ struct Opts {
bool rps1;
bool preexec;
+ int pathlen;
+
int col;
int row;
diff --git a/source/prompt/rps1.d b/source/prompt/rps1.d
index 5ee5d2c..9ec5ac7 100644
--- a/source/prompt/rps1.d
+++ b/source/prompt/rps1.d
@@ -1,6 +1,12 @@
module prompt.rps1;
import std.conv;
+import std.regex;
+import std.array;
+
+import std.file : getcwd;
+import std.path : expandTilde;
+import std.algorithm : reverse;
import prim.opt;
@@ -11,9 +17,22 @@ import style.font;
string rps1(Opts opt) {
string ps;
- // previous command status
- ps ~= ("(" ~ to!string(opt.status) ~ ") ").set(Color.black);
+ string home = expandTilde("~");
+ string path = replaceFirst(getcwd(), regex(home), "~");
- return ps;
-}
+ string[] splitPath = path.split("/").reverse();
+
+ string[] revSplitPath;
+ for (int i = 0; i < opt.pathlen; i++) {
+ if (i >= splitPath.length)
+ break;
+
+ revSplitPath ~= splitPath[i];
+ }
+ splitPath = revSplitPath.reverse();
+
+ ps ~= splitPath.join("/");
+
+ return ps.set(Font.italic).set(Color.yellow);
+}
diff --git a/source/style/package.d b/source/style/package.d
index 76aa044..57e87c2 100644
--- a/source/style/package.d
+++ b/source/style/package.d
@@ -5,5 +5,5 @@ import std.conv;
import style.color;
string set(string s, int code) {
- return ("%{\x1b[" ~ to!string(code) ~ "m%}") ~ s ~ ("%{\x1b[0m%}");
+ return ("%{\x1b[" ~ to!string(code) ~ "m%}") ~ s ~ ("%{\x1b[" ~ to!string((Color.reset + 0)) ~ "m%}");
}