]> arthur.barton.de Git - ax-zsh.git/commitdiff
axttyinfo: Tweak the tool a bit :-) github/master
authorAlexander Barton <alex@barton.de>
Sun, 25 Dec 2022 13:35:05 +0000 (14:35 +0100)
committerAlexander Barton <alex@barton.de>
Sun, 25 Dec 2022 13:35:05 +0000 (14:35 +0100)
- Show the terminal program and its version
- Show way more environment variables and enhance formatting
- Implement "one line" (-1) mode

bin/axttyinfo

index 74ed6ec90c133fa39ef720490e88a9867383c642..8097e37dc059f5ec749615be5d28e0ea4782f1f6 100755 (executable)
@@ -6,29 +6,77 @@
 
 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
 
-print -Pn -- "$fg[white]$FX[bold]$HOST$FX[no-bold] "
+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]"
-[[ -n "$LANG" ]] && print -Pn -- "; LANG=$LANG"
-[[ -n "$COLORTERM" ]] && print -Pn -- "; COLORTERM=$COLORTERM"
 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() {