diff options
Diffstat (limited to 'source/comp')
-rw-r--r-- | source/comp/ssh.d | 22 |
1 files changed, 22 insertions, 0 deletions
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; +} |