]> arthur.barton.de Git - ax-zsh.git/blobdiff - core/11_terminal/11_terminal.zshrc
Correctly test XDG_CACHE_HOME for writability for "stamp files"
[ax-zsh.git] / core / 11_terminal / 11_terminal.zshrc
index ac24c3be772dffacf151b73d5fb7feed775ffb87..ac5a1fc037ebfa904228c7c2ce2da462c902bad9 100644 (file)
@@ -1,5 +1,5 @@
 # AX-ZSH: Alex' Modular ZSH Configuration
-# 10_terminal.zshrc: Initialize terminal settings
+# 11_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.
@@ -21,7 +21,21 @@ function axzsh_is_utf_terminal {
 }
 alias isutfenv=axzsh_is_utf_terminal
 
-# Check if terminal supports "wide" characters.
+# Get the length of a string when shown on the terminal. The return code of the
+# function is the length in "cells". Note: Echo'ing the length to the terminal,
+# which looks cleaner at first, doesn't work: this command can't be called with
+# its stdin and/or stdout redirected, as it it must be able to interact with the
+# terminal (write to and read from it).
+function axzsh_get_displayed_length {
+       echo -ne "$*\033[6n"
+       read -s -d\[ garbage
+       read -s -d R pos
+       echo -ne "\033[1K\r"
+       return $((${pos#*;} - 1))
+}
+
+# Check if terminal correctly handles "wide" characters, which means, displays
+# them with the correct width (>1).
 # <https://unix.stackexchange.com/questions/184345/detect-how-much-of-unicode-my-terminal-supports-even-through-screen>
 typeset -g _axzsh_is_widechar_terminal_cache
 function axzsh_is_widechar_terminal {
@@ -36,12 +50,8 @@ function _axzsh_is_widechar_terminal {
        [[ -t 1 ]] || return 1
        [[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 1
        axzsh_is_utf_terminal || return 1
-       echo -ne "🍀\033[6n"
-       read -s -d\[ garbage
-       read -s -d R pos
-       echo -ne "\033[1K\r"
-       [[ "${pos#*;}" -eq 2 ]] || return 1
-       return 0
+       axzsh_get_displayed_length "🍀"
+       [[ $? -eq 2 ]] && return 0 || return 1
 }
 
 # Test for "modern" terminal
@@ -87,7 +97,7 @@ function axzsh_terminal_title_precmd {
        if [[ "$TERM_PROGRAM" == "Apple_Terminal" && "$TERM" != "screen"* ]]; then
                axzsh_terminal_set_icon_title "$LOGNAME@$SHORT_HOST"
                # Update CWD in Terminal.app
-               local url=$(echo "file://$HOSTNAME$PWD" | sed -e 's| |%20|g')
+               local url=$(echo "file://$HOST$PWD" | sed -e 's| |%20|g')
                printf '\e]7;%s\a' "$url"
        else
                axzsh_terminal_set_icon_title "$LOGNAME@$SHORT_HOST:$PWD"
@@ -130,7 +140,7 @@ function axzsh_terminal_title_preexec {
 
 preexec_functions+=(axzsh_terminal_title_preexec)
 
-alias axttyinfo="nocorrect zsh $AXZSH/bin/axttyinfo"
+alias axttyinfo="zsh \"\$AXZSH/bin/axttyinfo\""
 
 axzsh_is_dumb_terminal && return 0