]> arthur.barton.de Git - ax-zsh.git/blobdiff - core/10_terminal/10_terminal.zshrc
ssh_macos: Don't error out when no SSH agent is available
[ax-zsh.git] / core / 10_terminal / 10_terminal.zshrc
index fa27ed7f5919502d092e1015f08fca2b8b75a67c..b90fbc531305557675c2edf2696a1d6fef0f2c6f 100644 (file)
@@ -1,6 +1,47 @@
 # AX-ZSH: Alex' Modular ZSH Configuration
 # 10_terminal.zshrc: Initialize terminal settings
 
+# Fix up TERM. Do this here (and not in zprofile), because terminal emulators
+# often don't start a new login shell but "only" a new interactive shell.
+
+# VTE based terminals (like GNOME Terminal) support 256 colors, but old(er)
+# versions of GNOME Terminal (at least) set TERM=xterm ...
+[[ "$TERM" = "xterm" && "$VTE_VERSION" != "" ]] && TERM="xterm-256color"
+
+# 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
+}
+
+# Test for "dumb" terminal
+function axzsh_is_dumb_terminal {
+       axzsh_is_modern_terminal && return 1
+       [[ "$TERM" = dumb* ]] && return 0
+       [[ "$TERM" = "vt52" ]] && 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 +57,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,10 +73,13 @@ 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"*|"ssh"*|"telnet"*)
+         "mosh"*|"root"*|"ssh"*|"telnet"*)
                remote=1
                ;;
        esac
@@ -59,6 +104,8 @@ function axzsh_terminal_title_preexec {
 
 preexec_functions+=(axzsh_terminal_title_preexec)
 
+axzsh_is_dumb_terminal && return 0
+
 # Colors
 
 autoload -Uz colors