]> arthur.barton.de Git - ax-zsh.git/blobdiff - bin/axttyinfo
axttyinfo: Tweak the tool a bit :-)
[ax-zsh.git] / bin / axttyinfo
index e40c6b86265359b3f1e00b02a4ceb0a132aa0e31..8097e37dc059f5ec749615be5d28e0ea4782f1f6 100755 (executable)
@@ -1,41 +1,91 @@
 #!/usr/bin/env zsh
 #
 # AX-ZSH: Alex' Modular ZSH Configuration
-# Copyright (c) 2015-2017 Alexander Barton <alex@barton.de>
+# Copyright (c) 2015-2022 Alexander Barton <alex@barton.de>
 #
 
 source "$AXZSH/core/11_terminal/11_terminal.zshrc" || exit 1
 
-unset VERBOSE
+unset VERBOSE ONE_LINE
 
 while [[ $# -gt 0 ]]; do
        case "$1" in
+               "-1")
+                       ONE_LINE=1
+                       ;;
                "-v")
                        VERBOSE=1
                        ;;
                *)
-                       echo "Usage: ttyinfo [-v]" >&2
+                       echo "Usage: ttyinfo [-1] [-v]" >&2
                        exit 1
        esac
        shift
 done
 
-printf "$fg[white]$fx[bold]$(hostname)$fx[no-bold] "
-printf "$fg[yellow]$(tty)$fx[reset], "
-printf "$fg[green]$fx[underline]${TERM:-?}$fx[reset] "
-printf "(${COLUMNS:-?}x${LINES:-?}); "
-printf "$fg[white]LANG=${LANG:-?}$fx[reset]"
+print -Pn -- "$fg[white]$FX[bold]$SHORT_HOST$FX[no-bold] "
+print -Pn -- "$fg[yellow]$(tty)$FX[reset], "
+print -Pn -- "$fg[green]$FX[underline]${TERM:-?}$FX[reset] "
+print -Pn -- "(${COLUMNS:-?}x${LINES:-?})"
+[[ -n "$TERM_PROGRAM" ]] && print -Pn -- "; $fg[green]$TERM_PROGRAM$FX[reset]"
+[[ -n "$$TERM_PROGRAM_VERSION" ]] && print -Pn -- " $TERM_PROGRAM_VERSION"
+print -Pn -- "$FX[reset]"
 echo
 
+[[ -n "$ONE_LINE" ]] && return 0
+
+typeset -i max=${COLUMNS:-80}
+typeset -i col=0
+for key (
+       LANG
+       LC_ALL
+       LC_ADDRESS
+       LC_COLLATE
+       LC_CTYPE
+       LC_IDENTIFICATION
+       LC_MEASUREMENT
+       LC_MESSAGES
+       LC_MONETARY
+       LC_NAME
+       LC_NUMERIC
+       LC_PAPER
+       LC_TELEPHONE
+       LC_TIME
+       -
+       COLORTERM
+       CLICOLOR
+       TERM_COLORS
+       -
+       DISPLAY
+); do
+       if [[ $key == "-" ]]; then
+               [[ $col -gt 0 ]] && echo
+               col=0
+               continue
+       fi
+
+       [[ "${(P)key-UNSET}" = "UNSET" ]] && continue
+       val=${(P)key}
+
+       col=$(( $col + ${#key} + ${#val} + 5 ))
+       if [[ $col -gt $max ]]; then
+               echo
+               col=$(( ${#key} + ${#val} + 5 ))
+       fi
+
+       print -Pn -- "$key=\"$fg[cyan]$val$FX[reset]\"; "
+done
+[[ $col -gt 0 ]] && echo
+
 [[ -z "$VERBOSE" ]] && return 0
 
 check_function_result() {
        "$1"; r=$?
-       printf " - $fg[white]$1$fx[reset]() = "
+       print -Pn -- " - $fg[white]$1$FX[reset]() = "
        if [[ $r -eq 0 ]]; then
-               echo "$fg[green]yes$fx[reset]"
+               print -P -- "$fg[green]yes$FX[reset]"
        else
-               echo "$fg[red]NO$fx[reset]"
+               print -P -- "$fg[red]NO$FX[reset]"
        fi
        return $r
 }