summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2023-09-26 09:00:14 -0400
committerShav Kinderlehrer <[email protected]>2023-09-26 09:00:14 -0400
commit6a5e11bf1887355910333045f195559d463b64bd (patch)
tree60c5a3e239a4905ce47529e806e18414aa0967ab
parent0dbb3cee345f8d3042736acfe6c8aa159862eeab (diff)
downloadprim-6a5e11bf1887355910333045f195559d463b64bd.tar.gz
prim-6a5e11bf1887355910333045f195559d463b64bd.zip
Add ssh componentHEADv0.2.0main
-rw-r--r--source/app.d2
-rw-r--r--source/comp/ssh.d22
-rw-r--r--source/prompt/ps1.d2
3 files changed, 25 insertions, 1 deletions
diff --git a/source/app.d b/source/app.d
index 76f64b5..25642c2 100644
--- a/source/app.d
+++ b/source/app.d
@@ -14,7 +14,7 @@ Opts defaultOpts() {
Opts opts;
opts.pathlen = 3;
- opts.pchar = "|>";
+ opts.pchar = "*";
return opts;
}
diff --git a/source/comp/ssh.d b/source/comp/ssh.d
new file mode 100644
index 0000000..bdac732
--- /dev/null
+++ b/source/comp/ssh.d
@@ -0,0 +1,22 @@
+module comp.ssh;
+
+import std.process : environment;
+import std.socket : Socket;
+
+string ssh() {
+ string ssh = environment.get("SSH_TTY");
+ string username = environment.get("USER");
+ username = username ? username : "";
+
+ if (!ssh) {
+ return "";
+ }
+
+ auto s = new Socket();
+ scope (exit)
+ s.close();
+
+ string hostname = s.hostName;
+
+ return username ~ "@" ~ hostname;
+}
diff --git a/source/prompt/ps1.d b/source/prompt/ps1.d
index 3b46bf2..3f22185 100644
--- a/source/prompt/ps1.d
+++ b/source/prompt/ps1.d
@@ -6,6 +6,7 @@ import prim.opt;
import comp.hr;
import comp.path;
+import comp.ssh;
import style;
import style.color;
@@ -18,6 +19,7 @@ string ps1(Opts opt) {
ps ~= "\n";
ps ~= (",-(" ~ pathstr ~ ")".set(Color.black)).set(Color.black);
+ ps ~= " " ~ ssh().set(Color.cyan);
ps ~= "\n";
ps ~= ("`-(" ~ to!string(opt.status).set(Color.yellow) ~ ") ".set(Color.black)).set(Color.black); // prompt char