add the functions needed for some keybindings
[zsh.git] / .zsh / functions / ssh
1 # -*- mode:sh -*-
2
3 _jj_ssh() {
4 # TERM is one of the variables that is usually allowed to be
5 # transmitted to the remote session. The remote host should have the
6 # appropriate termcap or terminfo file to handle the TERM you
7 # provided. When connecting to random hosts, this may not be the
8 # case if your TERM is somewhat special. A good fallback is
9 # xterm. Most terminals are compatible with xterm and all hosts have
10 # a termcap or terminfo file to handle xterm. Therefore, for some
11 # values of TERM, we fallback to xterm.
12 #
13 # Now, you may connect to a host where your current TERM is fully
14 # supported and you will get xterm instead (which means 8 base
15 # colors only). There is no clean solution for this. You may want to
16 # reexport the appropriate TERM when logged on the remote host or
17 # use commands like this: ssh -t XXXXX env TERM=$TERM emacsclient -t
18 # -c
19 #
20 # If the remote host uses the same zshrc than this one, there is
21 # something in `$ZSH/rc/00-terminfo.zsh` to restore the appropriate
22 # terminal (saved in `LC__ORIGINALTERM`).
23 #
24 # The problem is quite similar for LANG and LC_MESSAGES. We reset
25 # them to C to avoid any problem with hosts not having your locally
26 # installed locales. See this post for more details on this:
27 # http://vincent.bernat.im/en/blog/2011-zsh-zshrc.html
28 #
29 # Also, when the same ZSH configuration is used on the remote host,
30 # the locale is reset with the help of 12-Locale.zsh
31 case "$TERM" in
32 rxvt-256color|rxvt-unicode)
33 LC__ORIGINALTERM=$TERM TERM=rxvt LANG=C LC_MESSAGES=C command ssh "$@"
34 ;;
35 *)
36 LANG=C LC_MESSAGES=C command ssh "$@"
37 ;;
38 esac
39 }
40
41 _jj_first_non_optional_arg() {
42 local args
43 args=( "$@" )
44 args=( ${(R)args:#-*} )
45 print -- $args[1]
46 }
47
48 # Alter window title
49 _jj_title () {
50 [ -t 1 ] || return
51 emulate -L zsh
52 local title
53 title=${@//[^[:alnum:]\/>< ._~:=?@-]/ }
54 case $TERM in
55 screen*)
56 print -n "\ek$title\e\\"
57 print -n "\e]1;$title\a"
58 print -n "\e]2;$title\a"
59 ;;
60 rxvt*|xterm*)
61 print -n "\e]1;$title\a"
62 print -n "\e]2;$title\a"
63 ;;
64 esac
65 }
66
67 _jj_title $(_jj_first_non_optional_arg "$@")
68 _jj_ssh "$@"