X-Git-Url: https://arthur.barton.de/gitweb/?p=ax-zsh.git;a=blobdiff_plain;f=core%2F11_terminal%2F11_terminal.zshrc;h=3990129368f10b44c800fbb280b9e49f5cfabef8;hp=86974038b9a8644ffb54160a98a1d3537470cdda;hb=7228c618f80ebee4956fc52247651ab0eb583673;hpb=9f867f58d9ed6a21831b664f1846c6a3ff66a122;ds=sidebyside diff --git a/core/11_terminal/11_terminal.zshrc b/core/11_terminal/11_terminal.zshrc index 8697403..3990129 100644 --- a/core/11_terminal/11_terminal.zshrc +++ b/core/11_terminal/11_terminal.zshrc @@ -23,8 +23,18 @@ alias isutfenv=axzsh_is_utf_terminal # Check if terminal supports "wide" characters. # +typeset -g _axzsh_is_widechar_terminal_cache function axzsh_is_widechar_terminal { + if [[ -z "$_axzsh_is_widechar_terminal_cache" ]]; then + # No cached result, call test function ... + _axzsh_is_widechar_terminal + _axzsh_is_widechar_terminal_cache=$? + fi + return $_axzsh_is_widechar_terminal_cache +} +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 @@ -36,10 +46,11 @@ function axzsh_is_widechar_terminal { # Test for "modern" terminal function axzsh_is_modern_terminal { + [[ "$TERM" = cygwin ]] && return 0 + [[ "$TERM" = putty* ]] && return 0 [[ "$TERM" = screen* ]] && return 0 [[ "$TERM" = tmux* ]] && return 0 [[ "$TERM" = xterm* ]] && return 0 - [[ "$TERM" = cygwin ]] && return 0 return 1 } @@ -72,14 +83,14 @@ 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' + axzsh_terminal_set_window_title '' if [[ "$TERM_PROGRAM" == "Apple_Terminal" && "$TERM" != "screen"* ]]; then - axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST" + axzsh_terminal_set_icon_title "$LOGNAME@$SHORT_HOST" # Update CWD in Terminal.app local url=$(echo "file://$HOSTNAME$PWD" | sed -e 's| |%20|g') printf '\e]7;%s\a' "$url" else - axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST:$PWD" + axzsh_terminal_set_icon_title "$LOGNAME@$SHORT_HOST:$PWD" fi } @@ -104,42 +115,96 @@ function axzsh_terminal_title_preexec { printf '\e]7;%s\a' '' fi fi - if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then - # iTerm.app ... - [[ -n "$cmd" ]] && TITLE_ADD=" – $cmd" - fi - axzsh_terminal_set_icon_title "$cmd" + if [[ -n "$cmd" ]]; then + # Add the command to the title + TITLE_ADD=" – $cmd" + fi if [[ -z "$remote" ]]; then - axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST$TITLE_ADD" + axzsh_terminal_set_icon_title "$LOGNAME@$SHORT_HOST$TITLE_ADD" else - axzsh_terminal_set_window_title "$1" + axzsh_terminal_set_icon_title "$1" fi } preexec_functions+=(axzsh_terminal_title_preexec) +alias axttyinfo="zsh \"\$AXZSH/bin/axttyinfo\"" + axzsh_is_dumb_terminal && return 0 # Colors +# See , for exmaple. autoload -Uz colors colors -# Text effects (FX) +if axzsh_is_modern_terminal; then + fg[default]="\e[39m" + bg[default]="\e[49m" +else + fg[default]="\e[37m" + bg[default]="\e[47m" +fi + +# Foreground (FG) and background (BG) colors. +typeset -Ag FG BG +case "$TERM" in + *-256color) + TERM_COLORS=255 + for color in {000..$TERM_COLORS}; do + FG[$color]="%{\e[38;5;${color}m%}" + BG[$color]="%{\e[48;5;${color}m%}" + done + ;; + *) + TERM_COLORS=15 + typeset -i c + for color in {000..$TERM_COLORS}; do + c=$color + if [[ $c -ge 8 ]]; then + c=$c-8 + p="1;" + fi + FG[$color]="%{\e[${p}3${c}m%}" + BG[$color]="%{\e[${p}4${c}m%}" + done + unset c p +esac +export TERM_COLORS -typeset -Ag fx -fx=( - reset "\e[00m" - bold "\e[01m" - no-bold "\e[22m" - italic "\e[03m" - no-italic "\e[23m" - underline "\e[04m" - no-underline "\e[24m" - blink "\e[05m" - no-blink "\e[25m" - reverse "\e[07m" - no-reverse "\e[27m" +# Text effects (FX) +# See , for example. + +typeset -Ag FX +FX=( + reset "%{\e[0m%}" + bold "%{\e[1m%}" no-bold "%{\e[22m%}" + italic "%{\e[3m%}" no-italic "%{\e[23m%}" + underline "%{\e[4m%}" no-underline "%{\e[24m%}" + blink "%{\e[5m%}" no-blink "%{\e[25m%}" + reverse "%{\e[7m%}" no-reverse "%{\e[27m%}" ) + +ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-The quick brown fox jumps over the lazy dog} + +# Show all 256 foreground colors with color number +function spectrum_ls() { + for code in {000..$TERM_COLORS}; do + print -P -- "$code: $FG[$code]$ZSH_SPECTRUM_TEXT$FX[reset]" + done +} + +# Show all 256 background colors with color number +function spectrum_bls() { + for code in {000..$TERM_COLORS}; do + print -P -- "$code: $BG[$code]$ZSH_SPECTRUM_TEXT$FX[reset]" + done +} + +# NOTE for FG, BG and FX arrays, and spectrum_ls() and spectrum_bls() functions: +# Based on a script to make using 256 colors in zsh less painful, written by +# P.C. Shyamshankar . +# Copied from OhMyZsh https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/spectrum.zsh +# which was copied from https://github.com/sykora/etc/blob/master/zsh/functions/spectrum/ :-)