]> arthur.barton.de Git - ax-zsh.git/blob - bin/axttyinfo
P10k: Read config after enabling instant prompt
[ax-zsh.git] / bin / axttyinfo
1 #!/usr/bin/env zsh
2 #
3 # AX-ZSH: Alex' Modular ZSH Configuration
4 # Copyright (c) 2015-2022 Alexander Barton <alex@barton.de>
5 #
6
7 source "$AXZSH/core/11_terminal/11_terminal.zshrc" || exit 1
8
9 unset VERBOSE ONE_LINE
10
11 while [[ $# -gt 0 ]]; do
12         case "$1" in
13                 "-1")
14                         ONE_LINE=1
15                         ;;
16                 "-v")
17                         VERBOSE=1
18                         ;;
19                 *)
20                         echo "Usage: ttyinfo [-1] [-v]" >&2
21                         exit 1
22         esac
23         shift
24 done
25
26 print -Pn -- "$fg[white]$FX[bold]$SHORT_HOST$FX[no-bold] "
27 print -Pn -- "$fg[yellow]$(tty)$FX[reset], "
28 print -Pn -- "$fg[green]$FX[underline]${TERM:-?}$FX[reset] "
29 print -Pn -- "(${COLUMNS:-?}x${LINES:-?})"
30 [[ -n "$TERM_PROGRAM" ]] && print -Pn -- "; $fg[green]$TERM_PROGRAM$FX[reset]"
31 [[ -n "$$TERM_PROGRAM_VERSION" ]] && print -Pn -- " $TERM_PROGRAM_VERSION"
32 print -Pn -- "$FX[reset]"
33 echo
34
35 [[ -n "$ONE_LINE" ]] && return 0
36
37 typeset -i max=${COLUMNS:-80}
38 typeset -i col=0
39 for key (
40         LANG
41         LC_ALL
42         LC_ADDRESS
43         LC_COLLATE
44         LC_CTYPE
45         LC_IDENTIFICATION
46         LC_MEASUREMENT
47         LC_MESSAGES
48         LC_MONETARY
49         LC_NAME
50         LC_NUMERIC
51         LC_PAPER
52         LC_TELEPHONE
53         LC_TIME
54         -
55         COLORTERM
56         CLICOLOR
57         TERM_COLORS
58         -
59         DISPLAY
60 ); do
61         if [[ $key == "-" ]]; then
62                 [[ $col -gt 0 ]] && echo
63                 col=0
64                 continue
65         fi
66
67         [[ "${(P)key-UNSET}" = "UNSET" ]] && continue
68         val=${(P)key}
69
70         col=$(( $col + ${#key} + ${#val} + 5 ))
71         if [[ $col -gt $max ]]; then
72                 echo
73                 col=$(( ${#key} + ${#val} + 5 ))
74         fi
75
76         print -Pn -- "$key=\"$fg[cyan]$val$FX[reset]\"; "
77 done
78 [[ $col -gt 0 ]] && echo
79
80 [[ -z "$VERBOSE" ]] && return 0
81
82 check_function_result() {
83         "$1"; r=$?
84         print -Pn -- " - $fg[white]$1$FX[reset]() = "
85         if [[ $r -eq 0 ]]; then
86                 print -P -- "$fg[green]yes$FX[reset]"
87         else
88                 print -P -- "$fg[red]NO$FX[reset]"
89         fi
90         return $r
91 }
92
93 echo
94 for f (
95         axzsh_is_dumb_terminal
96         axzsh_is_modern_terminal
97         axzsh_is_utf_terminal
98         axzsh_is_widechar_terminal
99 ); do
100         check_function_result "$f"
101 done
102 echo