1

I'm using TERM='xterm-256color' on my laptop but have to use TERM='xterm' on a remote server where xterm-256color is not available and breaks down a few things.

So far I can do export TERM='xterm'; ssh -X 123.45.678.90, which works fine. But putting the previous line in an (zsh) alias (alias sshx="export TERM='xterm'; ssh -X 123.45.678.90") doesn't seem to work. E.g., if I insert a echo $TERM between the export and the ssh, doing everything in the command line echoes xterm, but the alias gives xterm-256color.

And of course, optimally, the TERM would be set back to its initial value after the ssh.

Is there a way to achieve this?

Thanks.

antony
  • 2,877
  • 4
  • 31
  • 43
  • 1
    `.678.` is definitely not a valid IP address part. – ZyX Jun 27 '11 at 21:35
  • It may be an old zsh bug: with `alias abc='export ABC="$(date)" ; zsh -c "echo \$ABC"'` I do not observe this behavior. Zsh version is 4.3.11. – ZyX Jun 27 '11 at 21:37

1 Answers1

3

It is normally solved by

alias sshx='TERM=xterm ssh -X 123.45.67.89'

without exporting anything. In other case you will probably have to create a function.

ZyX
  • 52,536
  • 7
  • 114
  • 135
  • So how do I know when I have to export? – antony Jun 28 '11 at 18:08
  • @antony It is obvious: you have to export only when you are going to run a sequence of commands. To export only for the time when current function is active you can use `local -x`, thus you could limit the scope where variable is changed: try `export ABC="ghi" ; (){ local -x ABC="def" ; zsh -c 'echo $ABC' } ; zsh -c 'echo $ABC'` (this uses anonymous function, requires at least zsh-4.3.11 if I am not mistaking). – ZyX Jun 29 '11 at 03:35
  • There is also a patch that will allow you to do something like `alias sshx='() { local -x TERM=xterm ; ssh -X 123.45.67.89 $@ }'`: it will be allowed to pass arguments to anonymous functions (though I suggest to create normal functions in this case). – ZyX Jun 29 '11 at 03:40