]> arthur.barton.de Git - ax-zsh.git/blobdiff - core/10_terminal/10_terminal.zshrc
10_terminal: Implement "axzsh_resize_terminal COLUMNS LINES"
[ax-zsh.git] / core / 10_terminal / 10_terminal.zshrc
index 56de7c0fbd29984ed94e58b8d9929acfffd39c3b..e7c1eecfcb2b41404015c789e6da19217ae7b61f 100644 (file)
@@ -1,6 +1,32 @@
 # AX-ZSH: Alex' Modular ZSH Configuration
 # 10_terminal.zshrc: Initialize terminal settings
 
+# Common helper functions
+
+# Check if terminal supports Unicode.
+# <https://wiki.grml.org/doku.php?id=utf8>
+function axzsh_is_utf_terminal {
+       case "$LANG $CHARSET $LANGUAGE" in
+               (*utf*) return 0 ;;
+               (*UTF*) return 0 ;;
+               (*) return 1 ;;
+       esac
+}
+alias isutfenv=axzsh_is_utf_terminal
+
+# Test for "modern" terminal
+function axzsh_is_modern_terminal {
+       [[ "$TERM" = screen* ]] && return 0
+       [[ "$TERM" = tmux* ]] && return 0
+       [[ "$TERM" = xterm* ]] && return 0
+       return 1
+}
+
+# Resize terminal window (when possible)
+function axzsh_resize_terminal {
+       printf '\e[8;%d;%dt' "$2" "$1"
+}
+
 # Set terminal title
 
 # Set terminal "hardstatus" and "icon title"
@@ -16,6 +42,7 @@ function axzsh_terminal_set_window_title {
 
 # Update terminal titles befor echoing the shell prompt
 function axzsh_terminal_title_precmd {
+       axzsh_is_modern_terminal || return
        axzsh_terminal_set_icon_title 'zsh'
        if [[ "$TERM_PROGRAM" == "Apple_Terminal" && "$TERM" != "screen"* ]]; then
                axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST"
@@ -31,25 +58,40 @@ precmd_functions+=(axzsh_terminal_title_precmd)
 
 # Update terminal titles befor executing a command
 function axzsh_terminal_title_preexec {
+       axzsh_is_modern_terminal || return
+
        local cmd="${1[(w)1]}"
+       local remote=""
+
+       case "$cmd" in
+         "mosh"*|"root"*|"ssh"*|"telnet"*)
+               remote=1
+               ;;
+       esac
        if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then
                # Apple Terminal.app ...
-               case "$cmd" in
-                 "mosh"*|"ssh"*|"telnet"*)
+               if [[ -n "$remote" ]]; then
                        # Reset CWD for remote commands
                        printf '\e]7;%s\a' ''
-                       ;;
-               esac
+               fi
        fi
+       if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
+               # iTerm.app ...
+               [[ -n "$cmd" ]] && TITLE_ADD=" – $cmd"
+       fi
+
        axzsh_terminal_set_icon_title "$cmd"
-       axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST"
+
+       [[ -z "$remote" ]] \
+               && axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST$TITLE_ADD" \
+               || axzsh_terminal_set_window_title "$1"
 }
 
 preexec_functions+=(axzsh_terminal_title_preexec)
 
 # Colors
 
-autoload -U colors
+autoload -Uz colors
 colors
 
 # Text effects (FX)