If your sshd is not providing useful variables, you could use
ps -p $PPID
or some other random ps trick (if your shell doesn't set $PPID
) to see if the shell's parent process is your remote-login-process or not. Then if parent-is-remote-thingie switch $PS1. And then download OpenSSH and use geekosaur/Caleb's suggestions because your ssh server is junk. ;)
Or, you can use the output of "who am i", grab the last field (ie, $( who am i | awk '$0=$NF')
), and check to see if the host is a remote one or local to decide if you logged in locally or remotely.
Or you can switch on the output of $(hostname)
to have your shell use the appropriate $PS1 on specific hosts.
Or, let's really go nuts.
If you're using a modern shell - like bash, ksh93, or zsh, you can take advantage of the fact that $PS1 is reevaluated upon execution. So, you could include an inline conditional block to do the crazy git stuff if your cwd is within the repository, and something else outside. For example, here I'm making my prompt change depending on the directory I'm in by using [[ conditional ]] && $( echo "whatever it should be if true) || $( echo "whatever should be the if-not-true prompt" )
, basically.
default prompt$ PS1='$(id -un) @ $(hostname)$( [[ $(pwd) = /tmp ]] && echo " [I am in /tmp]" || echo " /not/in/tmp")$ '
myname @ host /not/in/tmp$ cd /tmp
myname @ host [I am in /tmp]$ cd /etc
myname @ host /not/in/tmp$
Sure, the $PS1 definition will look crazy in your profile, but you then only get super-colorful-git-stuff when you're actually in the git repository, while you ahve regular colors elsewhere. :) Note that you have to use single quotes around the PS1 assignment. You do not want the variables expanded when PS1 is assigned; you want them expanded when $PS1 is evaluated later. So, single-quotes.