summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2023-08-10 10:44:06 -0400
committerShav Kinderlehrer <[email protected]>2023-08-10 10:44:06 -0400
commit26ba41d08f86fc006edf9c0552205e2851a1060b (patch)
tree06446a566208b343edfd6ad8eec0258afa39ab73
parentdb53ee6c3bdd8d14c196f06b6377f2418779f82d (diff)
downloadprim-26ba41d08f86fc006edf9c0552205e2851a1060b.tar.gz
prim-26ba41d08f86fc006edf9c0552205e2851a1060b.zip
Fix rendering issues + add git comp
-rw-r--r--dub.json4
-rw-r--r--hook.zsh11
-rwxr-xr-xprimbin2618401 -> 2661185 bytes
-rw-r--r--source/app.d2
-rw-r--r--source/comp/git.d28
-rw-r--r--source/comp/hr.d2
-rw-r--r--source/comp/path.d33
-rw-r--r--source/prompt/preexec.d5
-rw-r--r--source/prompt/ps1.d13
-rw-r--r--source/prompt/rps1.d31
10 files changed, 88 insertions, 41 deletions
diff --git a/dub.json b/dub.json
index 52e2da0..49ed42b 100644
--- a/dub.json
+++ b/dub.json
@@ -3,7 +3,9 @@
"zerocool"
],
"copyright": "Copyright © 2023, zerocool",
+ "dependencies": {
+ },
"description": "A minimal D application.",
"license": "proprietary",
"name": "prim"
-} \ No newline at end of file
+}
diff --git a/hook.zsh b/hook.zsh
index 31aa142..9715796 100644
--- a/hook.zsh
+++ b/hook.zsh
@@ -1,13 +1,14 @@
-setopt promptsubst
-
prompt_precmd() {
- export PS1=`prim --ps1 --col $COLUMNS --row $LINES --status $?`
- export RPS1=`prim --rps1 --col $COLUMNS --row $LINES --status $?`
+ export PS1=$'`prim --ps1 --col $COLUMNS --row $LINES --status $?`'
+ export RPS1=$'`prim --rps1 --col $COLUMNS --row $LINES --status $?`'
}
prompt_preexec() {
- print -P `prim --preexec --col $COLUMNS --row $LINES --status $?`
+# print -P `prim --preexec --col $COLUMNS --row $LINES --status $?`
}
+autoload -Uz add-zsh-hook
+setopt promptsubst
+
add-zsh-hook precmd prompt_precmd
add-zsh-hook preexec prompt_preexec
diff --git a/prim b/prim
index eec52df..f7d980a 100755
--- a/prim
+++ b/prim
Binary files differ
diff --git a/source/app.d b/source/app.d
index 60542d6..68bf114 100644
--- a/source/app.d
+++ b/source/app.d
@@ -53,7 +53,7 @@ void dorun(Opts opts) {
}
if (opts.preexec) {
- preexec(opts.col).write();
+ // preexec(opts).write();
}
if (opts.rps1) {
diff --git a/source/comp/git.d b/source/comp/git.d
new file mode 100644
index 0000000..4f68e95
--- /dev/null
+++ b/source/comp/git.d
@@ -0,0 +1,28 @@
+module comp.git;
+
+import std.stdio;
+import std.file : dirEntries, SpanMode;
+import std.process;
+import std.string : strip;
+
+string gitBranch() {
+ auto result = execute(["git", "rev-parse", "--abbrev-ref", "HEAD"]);
+
+ if (result.status != 0)
+ return null;
+
+ return result.output.strip();
+}
+
+string gitStatus() {
+ auto result = execute(["git", "status", "--porcelain"]);
+
+ if (result.status != 0)
+ return null;
+
+ if (result.output.length >= 1) {
+ return "*";
+ }
+
+ return "";
+}
diff --git a/source/comp/hr.d b/source/comp/hr.d
index fa4d32b..76f7098 100644
--- a/source/comp/hr.d
+++ b/source/comp/hr.d
@@ -4,7 +4,7 @@ string hr(int col) {
string ps;
foreach (i; 0 .. col) {
- ps ~= '—';
+ ps ~= '─';
}
return ps;
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 ~ "/";
+
+}
diff --git a/source/prompt/preexec.d b/source/prompt/preexec.d
index 3904a2b..52a5cb2 100644
--- a/source/prompt/preexec.d
+++ b/source/prompt/preexec.d
@@ -1,10 +1,11 @@
module prompt.preexec;
+import prim.opt;
import comp.hr;
import style;
import style.color;
-string preexec(int col) {
- return hr(col).set(Color.black);
+string preexec(Opts opt) {
+ return "";
}
diff --git a/source/prompt/ps1.d b/source/prompt/ps1.d
index 5b8bafa..d1bc1b3 100644
--- a/source/prompt/ps1.d
+++ b/source/prompt/ps1.d
@@ -3,7 +3,9 @@ module prompt.ps1;
import std.conv;
import prim.opt;
+
import comp.hr;
+import comp.path;
import style;
import style.color;
@@ -12,14 +14,13 @@ import style.font;
string ps1(Opts opt) {
string ps;
- // divider
- ps ~= hr(opt.col).set(Color.black);
+ string pathstr = path(opt.pathlen);
- // previous command status
- ps ~= ("(" ~ to!string(opt.status) ~ ") ").set(Color.black);
+ ps ~= "\n";
+ ps ~= (",-(" ~ pathstr ~ ")").set(Color.black);
+ ps ~= "\n";
- // prompt char
+ ps ~= ("'-(" ~ to!string(opt.status) ~ ") ").set(Color.black); // prompt char
ps ~= "|> ".set(Font.bold).set(opt.status == 0 ? Color.green : Color.red);
-
return ps;
}
diff --git a/source/prompt/rps1.d b/source/prompt/rps1.d
index 9ec5ac7..075707e 100644
--- a/source/prompt/rps1.d
+++ b/source/prompt/rps1.d
@@ -1,15 +1,10 @@
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;
+import comp.path;
+import comp.git;
+
import style;
import style.color;
import style.font;
@@ -17,22 +12,8 @@ import style.font;
string rps1(Opts opt) {
string ps;
- string home = expandTilde("~");
- string path = replaceFirst(getcwd(), regex(home), "~");
-
- 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("/");
+ ps ~= (gitBranch()).set(Font.bold).set(Color.cyan);
+ ps ~= (gitStatus());
- return ps.set(Font.italic).set(Color.yellow);
+ return ps;
}