diff --git a/Makefile b/Makefile index 713c84a..e8f6dcc 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ bindir = $(PREFIX)/bin all: ep -ep: ep.c out.c path.c git.c lang.c $(LANGUAGE) +ep: ep.c out.c path.c git.c lang.c ssh.c $(LANGUAGE) install: ep install -m755 $< $(bindir)/ep diff --git a/ep.c b/ep.c index 6d2a50d..111471a 100644 --- a/ep.c +++ b/ep.c @@ -71,13 +71,9 @@ int main(int argc, char **argv) p("[chroot] "); const char *home = getenv("HOME"); - const char *hostname = getenv("HOSTNAME"); /* show we are on a different machine */ - if (hostname) { - p(hostname); - p(" "); - } + print_ssh(); print_pwd(home); diff --git a/ep.h b/ep.h index 9e8b20b..3336cd4 100644 --- a/ep.h +++ b/ep.h @@ -35,4 +35,7 @@ void print_git(void); void *lang_thread(void *); void print_lang(uint64_t); +/* from ssh.c */ +void print_ssh(void); + #endif diff --git a/ssh.c b/ssh.c new file mode 100644 index 0000000..b3bc12e --- /dev/null +++ b/ssh.c @@ -0,0 +1,21 @@ +#include +#include + +#include "ep.h" + +void print_ssh(void) +{ + /* expect ssh to have set these variables - we don't need to prompt if not using a tty */ + const char *sshcon = getenv("SSH_CONNECTION"), *sshtty = getenv("SSH_TTY"); + + if (sshcon && *sshcon && sshtty && *sshtty) { + struct utsname u; + /* don't print anything if uname fails or nodename is empty */ + if (uname(&u) || !u.nodename[0]) + return; + + p("("); + p(u.nodename); + p(") "); + } +}