mirror of https://github.com/ericonr/ep.git
Fix hostname printing.
ssh doesn't set HOSTNAME in env, that has to be determined separately. What indicates a ssh session are some SSH_* env vars.
This commit is contained in:
parent
1f1adc1663
commit
815fdf1294
2
Makefile
2
Makefile
|
@ -13,7 +13,7 @@ bindir = $(PREFIX)/bin
|
||||||
|
|
||||||
all: ep
|
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: ep
|
||||||
install -m755 $< $(bindir)/ep
|
install -m755 $< $(bindir)/ep
|
||||||
|
|
6
ep.c
6
ep.c
|
@ -71,13 +71,9 @@ int main(int argc, char **argv)
|
||||||
p("[chroot] ");
|
p("[chroot] ");
|
||||||
|
|
||||||
const char *home = getenv("HOME");
|
const char *home = getenv("HOME");
|
||||||
const char *hostname = getenv("HOSTNAME");
|
|
||||||
|
|
||||||
/* show we are on a different machine */
|
/* show we are on a different machine */
|
||||||
if (hostname) {
|
print_ssh();
|
||||||
p(hostname);
|
|
||||||
p(" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
print_pwd(home);
|
print_pwd(home);
|
||||||
|
|
||||||
|
|
3
ep.h
3
ep.h
|
@ -35,4 +35,7 @@ void print_git(void);
|
||||||
void *lang_thread(void *);
|
void *lang_thread(void *);
|
||||||
void print_lang(uint64_t);
|
void print_lang(uint64_t);
|
||||||
|
|
||||||
|
/* from ssh.c */
|
||||||
|
void print_ssh(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
|
#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(") ");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue