Add ssh component

This commit is contained in:
Shav Kinderlehrer 2023-09-26 09:00:14 -04:00
parent 0dbb3cee34
commit 6a5e11bf18
3 changed files with 25 additions and 1 deletions

View File

@ -14,7 +14,7 @@ Opts defaultOpts() {
Opts opts;
opts.pathlen = 3;
opts.pchar = "|>";
opts.pchar = "*";
return opts;
}

22
source/comp/ssh.d Normal file
View File

@ -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;
}

View File

@ -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