I started to ask this question but answered it while I had it open. I'm going to post this question, follow it up with my solution and leave it open to other potential solutions.<backstory>I'm a tmux and vim user. I like remote vim work as I don't have to worry about Ubuntu development machines kirking out when a flash movie gives me a kernel panic. Running tmux means that open files are waiting for me after I reboot and I can carry on from where I left off. I've had problems with vim running in a tmux session when I connect like so:ssh example.com -t 'tmux attach'UTF-8 issues crop up that don't crop up when shelling in normally and just attaching to a tmux session manually.</backstory>So I want a reusable method of starting something on ssh login, that doesn't affect any of the other things I have configured in my .zshrc (or your .bashrc if you still use bash) that may be required for my development environment, that doesn't appear when I'm occasionally working locally on the very said machine.
How can I run a script immediately after connecting via SSH?
ssh;environment variables;tmux
When you run ssh example.com, the ssh daemon starts a login shell for you, and the login shell reads your ~/.profile (or ~/.bash_profile or ~/.zprofile or ~/.login depending on your login shell). When you specify a command to run remotely (with or without -t), the ssh daemon starts an ordinary shell, so your .profile is not read. Remedy:ssh example.com -t '. /etc/profile; . ~/.profile; tmux attach'Most ssh daemons are configured to refuse transmitting environment variables except for LC_*. If the ssh daemon on example.com allows it, you can abuse a custom LC_* variable to start tmux automatically  put this in your ~/.profile:if [ -n $LC_tmux_session ] && tmux has -t $LC_tmux_session; then  exec tmux attach -t $LC_tmux_sessionelif [ -n ${LC_tmux_session+1} ] && tmux has; then  exec tmux attachfithen log in with LC_tmux_session= ssh example.com or LC_tmux_session=session_name ssh example.com.This answer has more information about passing environment variables over ssh.