Add ssh component
This commit is contained in:
parent
0dbb3cee34
commit
6a5e11bf18
@ -14,7 +14,7 @@ Opts defaultOpts() {
|
||||
Opts opts;
|
||||
|
||||
opts.pathlen = 3;
|
||||
opts.pchar = "|>";
|
||||
opts.pchar = "*";
|
||||
|
||||
return opts;
|
||||
}
|
||||
|
22
source/comp/ssh.d
Normal file
22
source/comp/ssh.d
Normal 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;
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user