Compare commits

...

3 Commits

Author SHA1 Message Date
Ben Grande
ebe96406fb
fix: qubes statistics table
- CPU sum converted to average;
- Table is redrawed on terminal resize;
- Screen is saved before being drawn to;
- Works without sensors package; and
- Queries all relevant sensors.
2025-01-27 15:56:32 +01:00
Ben Grande
8a6cdd5096
fix: unset global variables 2025-01-24 16:22:36 +01:00
Ben Grande
a7d2876bb4
fix: standardize shell escape character to octal
URxvt requires octal for keysym while others do not and querying a
single one is easier.
2025-01-22 17:42:01 +01:00
12 changed files with 183 additions and 139 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# SPDX-FileCopyrightText: 2018 Chris Laprise <https://github.com/tasket> # SPDX-FileCopyrightText: 2018 Chris Laprise <https://github.com/tasket>
# SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com> # SPDX-FileCopyrightText: 2023 - 2025 Benjamin Grande M. S. <ben.grande.b@gmail.com>
# #
# SPDX-License-Identifier: GPL-3.0-only # SPDX-License-Identifier: GPL-3.0-only
@ -9,57 +9,79 @@
## Credits: https://github.com/tasket/Qubes-scripts ## Credits: https://github.com/tasket/Qubes-scripts
set -eu set -eu
if ! command -v sensors >/dev/null; then
printf '%s\n' "Program not installed: sensors" >&2
exit 1
fi
if ! command -v xentop >/dev/null; then if ! command -v xentop >/dev/null; then
printf '%s\n' "Program not installed: xentop" >&2 printf '%s\n' "Program not installed: xentop" >&2
exit 1 exit 1
fi fi
sensors="1"
if ! command -v sensors >/dev/null; then
sensors="0"
fi
sensors_stats () { redraw(){
# shellcheck disable=SC2312 stty size </dev/null 2>&1 >&2 | read -r LINES COLUMNS
sensors | grep -E -e "^(${sensor_lines})" tput ed home
} }
delay=5 do_tui(){
sortcol=3 stty -echo -icanon
sensor_lines='Package id 0|fan1|CPU' tput smcup civis home
}
undo_tui(){
stty echo icanon
tput cnorm rmcup
}
trap 'undo_tui' HUP INT QUIT ABRT TERM EXIT
trap 'redraw' WINCH
do_tui
get_header(){
cpusum=0
memsum=0
table=""
if test "${sensors}" != "0"; then
sensors | grep -E -e "^(fan[1-9]+|[C|G]PU|temp[1-9]+):" |
grep -v -e "0 RPM" -e "+0\.0.C" |
tr -s "\t" " " | tr "\n" "\t" | sed "s/\s\+$/\n/"
fi
printf '%s%-40s %-6s %6s %8s%s\n' "${bold}" 'Qube' 'State' 'CPU(%)' \
'MEM(MiB)' "${nobold}"
}
table=""
delay=1
sortcol=1
newline=' newline='
' '
sumline="--------------------------------------------------------" bold="$(tput smso)"
header="\033[2K\nVM NAME STATE CPU(%) MEM(MB)" nobold="$(tput rmso)"
index=0
trap "tput reset" HUP INT QUIT ABRT TERM EXIT get_header
tput reset
sensors_stats
printf '%b\n' "${header}"
cpusum=0; memsum=0; table="${sumline}"
# shellcheck disable=SC2016,SC2312 # shellcheck disable=SC2016,SC2312
stdbuf -oL xentop -b -f -d "${delay}" | \ xentop -b -f -d "${delay}" | \
stdbuf -oL awk '{printf ("%-32s %5s %5d %7d\n", $1,$2,$4,$5/1000) }' | \ stdbuf -oL awk '{printf ("%-40s %-6s %6d %8d\n", $1,$2,$4,$5/1000) }' | \
( (
read -r ln read -r _
while true; do while true; do
if read -r -t 0.1 ln; then if read -r -t 0.1 line; then
table="${table}${newline}${ln}" table="${table:+${table}${newline}}${line}"
read -r _ _ cpu mem <<<"${ln}" read -r _ _ cpu mem <<<"${line}"
index=$((index+1))
cpusum=$((cpusum+cpu)) cpusum=$((cpusum+cpu))
memsum=$((memsum+mem)) memsum=$((memsum+mem))
cpuavg=$((cpusum/index))
else else
# End of list, print totals, make new page. index=0
sort -k "${sortcol}" -n -r <<<"${table}" sort -k "${sortcol}" -n <<<"${table}"
printf '%-32s %5s %5d %7d\033[J\033[H' " " " " "${cpusum}" \ printf '%s%-s %-34s %-6s %6d %8d%s' "${bold}" "Total" "" "" \
"${memsum}" "${cpuavg}" "${memsum}" "${nobold}"
read -r ln tput ed home
cpusum=0; memsum=0 read -r _
table="${sumline}" get_header
#clear
#sensors |grep -E "^(${sensor_lines})"
sensors_stats
printf '%b\n' "\033[2K${header}\n"
fi fi
done done
) )

View File

@ -38,4 +38,4 @@ fi
description="$(printf '%s\n' "$3" | cut -c 1-80)" description="$(printf '%s\n' "$3" | cut -c 1-80)"
test_description description "${description}" test_description description "${description}"
printf '%s\n' "${description}" | tee "${description_file}" printf '%s\n' "${description}" | tee -- "${description_file}"

View File

@ -43,7 +43,11 @@ _reset_line() {
esac esac
## Credit: Can't find the source, posted on StackExchange or alike. ## Credit: Can't find the source, posted on StackExchange or alike.
## Does not work well on Bash 5.0 and older. ## Does not work well on Bash 5.0 and older.
bash_version_clean="$(printf '%s\n' "${BASH_VERSION%.*}" | tr -d ".")" bash_version_clean="${BASH_VERSION%.*}"
bash_version_clean="${bash_version_clean//\./}"
if [[ ! ${bash_version_clean} =~ ^[0-9]+$ ]]; then
return
fi
if test "${bash_version_clean}" -lt 51; then if test "${bash_version_clean}" -lt 51; then
unset bash_version_clean unset bash_version_clean
return return
@ -62,7 +66,7 @@ _reset_line() {
unset cur_y unset cur_y
## Print line ending char with reversed video and end with newline. ## Print line ending char with reversed video and end with newline.
if test "${color_prompt-}" = "yes"; then if test "${color_prompt-}" = "yes"; then
printf '%b' "\033[41m\033[0m\033[7m%\033[m\n\r" printf '%b' "\033[41m\033[0m\033[7m%\033[0m\n\r"
else else
printf '%b' "%\n\r" printf '%b' "%\n\r"
fi fi
@ -76,6 +80,7 @@ _print_ec(){
else else
printf '%s' "(${_ec_ps1})" printf '%s' "(${_ec_ps1})"
fi fi
unset _ec_ps1
} }
_save_ec() { _ec_ps1=$?; } _save_ec() { _ec_ps1=$?; }
@ -100,7 +105,7 @@ fi
case "${TERM-}" in case "${TERM-}" in
screen*|xterm*|rxvt*) screen*|xterm*|rxvt*)
## Set window title ## Set window title
PS1="\[\e]0;${debian_chroot:+(${debian_chroot})}\u@\h: \w\a\]${PS1}" PS1="\[\033]0;${debian_chroot:+(${debian_chroot})}\u@\h: \w\a\]${PS1}"
;; ;;
*) ;; *) ;;
esac esac
@ -112,14 +117,14 @@ case "${TERM-}" in
*) *)
## Reset cursor to steady block after command input and before execution. ## Reset cursor to steady block after command input and before execution.
# shellcheck disable=SC2034 # shellcheck disable=SC2034
PS0="\e[2 q\2" PS0="\033[2 q\2"
;; ;;
esac esac
if ! shopt -oq posix; then if ! shopt -oq posix; then
source_readable /usr/share/bash-completion/bash_completion source_readable /usr/share/bash-completion/bash_completion
fi fi
unset newline ps1_symbol unset newline ps1_symbol dircolor reset_color usercolor
## }}} ## }}}
## {{{ Plugins ## {{{ Plugins
if has zoxide; then if has zoxide; then

View File

@ -20,13 +20,13 @@ set editing-mode emacs
set show-mode-in-prompt on set show-mode-in-prompt on
$if term=linux $if term=linux
set emacs-mode-string "\1\e[?0c\2" set emacs-mode-string "\1\033[?0c\2"
set vi-ins-mode-string "\1\e[?0c\2" set vi-ins-mode-string "\1\033[?0c\2"
set vi-cmd-mode-string "\1\e[?8c\2" set vi-cmd-mode-string "\1\033[?8c\2"
$else $else
set emacs-mode-string "\1\e[5 q\2" set emacs-mode-string "\1\033[5 q\2"
set vi-ins-mode-string "\1\e[5 q\2" set vi-ins-mode-string "\1\033[5 q\2"
set vi-cmd-mode-string "\1\e[2 q\2" set vi-cmd-mode-string "\1\033[2 q\2"
$endif $endif
$if term='' $if term=''
@ -59,8 +59,8 @@ $if mode=emacs
set keymap emacs-ctlx set keymap emacs-ctlx
v: vi-editing-mode v: vi-editing-mode
Control-v: "\C-xv\e" Control-v: "\C-xv\033"
Esc: "\C-xv\e" Esc: "\C-xv\033"
set keymap emacs set keymap emacs
$else $else
@ -117,46 +117,46 @@ $endif
## Home ## Home
"\e[1~": beginning-of-line "\033[1~": beginning-of-line
"\e[H": beginning-of-line "\033[H": beginning-of-line
"\eOH": beginning-of-line "\033OH": beginning-of-line
## End ## End
"\e[4~": end-of-line "\033[4~": end-of-line
"\e[F": end-of-line "\033[F": end-of-line
"\eOF": end-of-line "\033OF": end-of-line
## Delete ## Delete
"\e[3~": delete-char "\033[3~": delete-char
"\e[P": delete-char "\033[P": delete-char
"\eOP": delete-char "\033OP": delete-char
## Insert ## Insert
"\e[2~": quoted-insert "\033[2~": quoted-insert
"\e[L": quoted-insert "\033[L": quoted-insert
## PgUp ## PgUp
"\e[5~": beginning-of-history "\033[5~": beginning-of-history
"\e[I": beginning-of-history "\033[I": beginning-of-history
## PgDown ## PgDown
"\e[6~": end-of-history "\033[6~": end-of-history
"\e[G": end-of-history "\033[G": end-of-history
## Ctrl+RighArrow ## Ctrl+RighArrow
"\e[1;5C": forward-word "\033[1;5C": forward-word
"\e[5C": forward-word "\033[5C": forward-word
"\e\e[C": forward-word "\033\033[C": forward-word
## Ctrl+LeftArrow ## Ctrl+LeftArrow
"\e[1;5D": backward-word "\033[1;5D": backward-word
"\e[5D": backward-word "\033[5D": backward-word
"\e\e[D": backward-word "\033\033[D": backward-word
## Terminal ## Terminal
$if term=rxvt $if term=rxvt
"\e[7~": beginning-of-line "\033[7~": beginning-of-line
"\e[8~": end-of-line "\033[8~": end-of-line
"\eOc": forward-word "\033Oc": forward-word
"\eOd": backward-word "\033Od": backward-word
$endif $endif

View File

@ -18,4 +18,4 @@ i toggle-option i
^F right ^F right
^N down ^N down
^P up ^P up
\ef word-right \033f word-right

View File

@ -10,7 +10,7 @@
# shellcheck disable=SC2312 # shellcheck disable=SC2312
: "${USER:=$(id -un || printf '%s' "${HOME##*/}")}" : "${USER:=$(id -un || printf '%s' "${HOME##*/}")}"
# shellcheck disable=SC2312 # shellcheck disable=SC2312
: "${UID:=$(id -u || awk -F ":" -v user="${USER}" -- '/^user:/{print $3}' \ : "${UID:=$(id -u || awk -F ":" -v user="${USER}" -- '$1 == user {print $3}' \
/etc/passwd)}" /etc/passwd)}"
# shellcheck disable=SC2312 # shellcheck disable=SC2312
: "${HOSTNAME:=$(hostname)}" : "${HOSTNAME:=$(hostname)}"
@ -28,6 +28,7 @@ mkdir -p -- "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" "${XDG_DATA_HOME}" \
xdg_dirs="$(awk -- '/^[ ]*XDG_[A-Z]*_DIR=/{print "export " $1}' \ xdg_dirs="$(awk -- '/^[ ]*XDG_[A-Z]*_DIR=/{print "export " $1}' \
"${XDG_CONFIG_HOME}/user-dirs.dirs")" "${XDG_CONFIG_HOME}/user-dirs.dirs")"
eval "${xdg_dirs}" eval "${xdg_dirs}"
unset xdg_dirs
## Set directory to be used for coding. ## Set directory to be used for coding.
CODEDIR="${HOME}/src" CODEDIR="${HOME}/src"
@ -156,7 +157,7 @@ if test -z "${SSH_AUTH_SOCK-}" && has ssh-agent; then
ssh_agent_env="$(ssh-agent -s -a "${ssh_agent_sock}")" ssh_agent_env="$(ssh-agent -s -a "${ssh_agent_sock}")"
eval "${ssh_agent_env}" >/dev/null eval "${ssh_agent_env}" >/dev/null
unset ssh_agent_env unset ssh_agent_env
printf '%s\n' "${SSH_AGENT_PID}" | tee "${ssh_agent_pid}" >/dev/null printf '%s\n' "${SSH_AGENT_PID}" | tee -- "${ssh_agent_pid}" >/dev/null
fi fi
fi fi
unset ssh_agent_dir ssh_agent_sock ssh_agent_pid unset ssh_agent_dir ssh_agent_sock ssh_agent_pid
@ -170,6 +171,7 @@ for f in "${XDG_CONFIG_HOME}/sh/profile.d"/*.sh; do
# shellcheck disable=SC1090,SC1091 # shellcheck disable=SC1090,SC1091
! test -r "${f}" || . "${f}" ! test -r "${f}" || . "${f}"
done done
unset f
## Source local profile. ## Source local profile.
# shellcheck disable=SC1090,SC1091 # shellcheck disable=SC1090,SC1091

View File

@ -34,9 +34,10 @@ alias cp="cp -i"
alias mv="mv -i" alias mv="mv -i"
alias ls="ls -hF --group-directories-first --color=auto" alias ls="ls -hF --group-directories-first --color=auto"
if has lsblk; then if has lsblk; then
_lsblk_options="NAME,FSTYPE,LABEL,SIZE,FSAVAIL,FSUSE%,MOUNTPOINT" lsblk_options="NAME,FSTYPE,LABEL,SIZE,FSAVAIL,FSUSE%,MOUNTPOINT"
alias lsblk='lsblk -o ${_lsblk_options}' alias lsblk='lsblk -o ${lsblk_options}'
alias lsblku='lsblk -o ${_lsblk_options},UUID,PARTUUID' alias lsblku='lsblk -o ${lsblk_options},UUID,PARTUUID'
unset lsblk_options
fi fi
if ! grep --color 2>&1 | grep -qE -e "(unrecognized|unknown) option" && if ! grep --color 2>&1 | grep -qE -e "(unrecognized|unknown) option" &&
! grep --exclude 2>&1 | grep -qE -e "(unrecognized|unknown) option" ! grep --exclude 2>&1 | grep -qE -e "(unrecognized|unknown) option"
@ -110,7 +111,7 @@ has qubesctl && {
alias qctlu="qctl --skip-dom0 --targets" alias qctlu="qctl --skip-dom0 --targets"
qctlus(){ qctlus(){
test -n "${2-}" || return 1 test -n "${2-}" || return 1
qubesctl --skip-dom0 --targets "${1}" state.apply "${2}" qubesctl --skip-dom0 --targets "${1}" state.apply "${@}"
} }
} }
has gpg && alias gpgs="gpg --show-keys" has gpg && alias gpgs="gpg --show-keys"
@ -124,9 +125,10 @@ has tmux && {
alias tcl="clear && t clear-history" # clear buffer cus memory alias tcl="clear && t clear-history" # clear buffer cus memory
tcla(){ tcla(){
## Clear all the panes of the current session. ## Clear all the panes of the current session.
for _t_pane in $(tmux list-panes -s -F '#{pane_id}'); do for t_pane in $(tmux list-panes -s -F '#{pane_id}'); do
tmux clear-history -t "${_t_pane}" tmux clear-history -t "${t_pane}"
done done
unset t_pane
} }
} }
## }}} ## }}}
@ -149,7 +151,7 @@ then
# shellcheck disable=SC2139,SC2140 # shellcheck disable=SC2139,SC2140
alias "g${key}"="git ${key}" alias "g${key}"="git ${key}"
done done
unset g_alias unset key g_alias
fi fi
## }}} ## }}}
## }}} ## }}}
@ -176,7 +178,7 @@ if test "${color_prompt-}" = "yes"; then
if has dircolors; then if has dircolors; then
## Use dircolors if available. ## Use dircolors if available.
if test -r "${XDG_CONFIG_HOME}/dircolors/dircolors"; then if test -r "${XDG_CONFIG_HOME}/dircolors/dircolors"; then
dircolors="$(dircolors -b "${XDG_CONFIG_HOME}/dircolors/dircolors")" dircolors="$(dircolors -b -- "${XDG_CONFIG_HOME}/dircolors/dircolors")"
eval "${dircolors}" eval "${dircolors}"
else else
dircolors="$(dircolors -b)" dircolors="$(dircolors -b)"
@ -223,9 +225,10 @@ fi
_get_prompt_time(){ _get_prompt_time(){
test -n "${SECONDS:-}" || return test -n "${SECONDS:-}" || return
# shellcheck disable=SC2154 # shellcheck disable=SC2154
_ptime="$((SECONDS-_saved_prompt_time))" ptime="$((SECONDS-_saved_prompt_time))"
printf '%02d:%02d:%02d' \ printf '%02d:%02d:%02d' \
"$((_ptime/3600))" "$(((_ptime%3600)/60))" "$((_ptime%60))" "$((ptime/3600))" "$(((ptime%3600)/60))" "$((ptime%60))"
unset ptime
} }
_git_prompt_info(){ _git_prompt_info(){
@ -241,19 +244,19 @@ _git_prompt_info(){
test "${ref-}" || return test "${ref-}" || return
# shellcheck disable=2039,3003 # shellcheck disable=2039,3003
case "${TERM-}" in case "${TERM-}" in
*-256color|xterm-kitty) branchcolor=$'\e[38;5;31m' ;; *-256color|xterm-kitty) branchcolor=$'\033[38;5;31m' ;;
*-88color|rxvt-unicode) branchcolor=$'\e[38;5;22m' ;; *-88color|rxvt-unicode) branchcolor=$'\033[38;5;22m' ;;
*) branchcolor=$'\e[00;94m' ;; *) branchcolor=$'\033[0;94m' ;;
esac esac
if test -n "${ZSH_VERSION-}"; then if test -n "${ZSH_VERSION-}"; then
# shellcheck disable=2016 # shellcheck disable=2016
if test "${color_prompt}" = "yes"; then if test "${color_prompt-}" = "yes"; then
print -Pn '(%%{${branchcolor}%%}%20>...>${ref}%<<%%{\e[00m%%})' print -Pn '(%%{${branchcolor}%%}%20>...>${ref}%<<%%{\033[0m%%})'
else else
print -Pn '(%20>...>${ref}%<<)' print -Pn '(%20>...>${ref}%<<)'
fi fi
else else
if test "${color_prompt}" = "yes"; then if test "${color_prompt-}" = "yes"; then
printf '%s' "(${branchcolor}${ref}${reset_color})" printf '%s' "(${branchcolor}${ref}${reset_color})"
else else
printf '%s' "(${ref})" printf '%s' "(${ref})"
@ -263,22 +266,22 @@ _git_prompt_info(){
} }
# shellcheck disable=SC2034 # shellcheck disable=SC2034
reset_color="$(printf '%b' '\e[00m')" reset_color="$(printf '%b' '\033[0m')"
# shellcheck disable=SC2034 # shellcheck disable=SC2034
## Use echotc Co? Only available by default for zsh, not bash. ## Use echotc Co? Only available by default for zsh, not bash.
case "${TERM-}" in case "${TERM-}" in
*-256color|xterm-kitty) *-256color|xterm-kitty)
usercolor="$(printf '%b' "\e[38;5;184m")" usercolor="$(printf '%b' "\033[38;5;184m")"
dircolor="$(printf '%b' "\e[38;5;27m")" dircolor="$(printf '%b' "\033[38;5;27m")"
;; ;;
*-88color|rxvt-unicode) *-88color|rxvt-unicode)
usercolor="$(printf '%b' "\e[38;5;56m")" usercolor="$(printf '%b' "\033[38;5;56m")"
dircolor="$(printf '%b' "\e[38;5;23m")" dircolor="$(printf '%b' "\033[38;5;23m")"
;; ;;
*) *)
usercolor="$(printf '%b' "\e[00;93m")" usercolor="$(printf '%b' "\033[0;93m")"
dircolor="$(printf '%b' "\e[01;34m")" dircolor="$(printf '%b' "\033[1;34m")"
;; ;;
esac esac
@ -290,7 +293,7 @@ esac
# shellcheck disable=SC2034 # shellcheck disable=SC2034
uid="$(id -u)" uid="$(id -u)"
if test "${uid}" = "0"; then if test "${uid}" = "0"; then
usercolor="$(printf '%b' "\e[00;97m")" usercolor="$(printf '%b' "\033[0;97m")"
ps1_symbol="#" ps1_symbol="#"
fi fi
unset uid unset uid
@ -303,6 +306,8 @@ if test "${color_prompt-}" = "yes"; then
else else
PS1="${user}@$(hostname -s)${ps1_symbol} " PS1="${user}@$(hostname -s)${ps1_symbol} "
fi fi
unset user uid
## }}} ## }}}
## {{{ External Functions ## {{{ External Functions
@ -313,6 +318,7 @@ source_readable(){
# shellcheck disable=SC1090 # shellcheck disable=SC1090
! test -r "${_file}" || . "${_file}" ! test -r "${_file}" || . "${_file}"
done done
unset _file
} }
_fzf_comprun() { _fzf_comprun() {
@ -338,6 +344,7 @@ _fzf_comprun() {
fzf --preview 'test -d {} || cat -- {}' "${@}" fzf --preview 'test -d {} || cat -- {}' "${@}"
;; ;;
esac esac
unset _fzf_command
} }
## }}} ## }}}

View File

@ -77,7 +77,7 @@ if test "${color_prompt-}" = "yes"; then
PS1="\$(resize-terminal)%F{magenta}[%{$usercolor%}%n@%m%F{reset_color%}" PS1="\$(resize-terminal)%F{magenta}[%{$usercolor%}%n@%m%F{reset_color%}"
PS1="${PS1} %{$dircolor%}%50<...<%~%<<%F{reset_color%}\$(_git_prompt_info)" PS1="${PS1} %{$dircolor%}%50<...<%~%<<%F{reset_color%}\$(_git_prompt_info)"
PS1="${PS1}%F{magenta}]%F{reset_color}${newline-}${ps1_symbol} " PS1="${PS1}%F{magenta}]%F{reset_color}${newline-}${ps1_symbol} "
RPS1="%(?..(%{"$'\e[31m'"%}%?%{$reset_color%}%)%<<)" RPS1="%(?..(%{"$'\033[31m'"%}%?%{$reset_color%}%)%<<)"
else else
PS1="\$(resize-terminal)[%n@%M %~\$(_git_prompt_info)]${newline}" PS1="\$(resize-terminal)[%n@%M %~\$(_git_prompt_info)]${newline}"
PS1="${PS1}${ps1_symbol} " PS1="${PS1}${ps1_symbol} "
@ -90,8 +90,8 @@ _set_title() {
*install*) *install*)
hash -r ;; hash -r ;;
esac esac
print -Pn '\e]1;%l@%m${1+*}\a' print -Pn '\033]1;%l@%m${1+*}\a'
print -Pn '\e]2;%n@%m:%~' print -Pn '\033]2;%n@%m:%~'
if test -n "${1:-}"; then if test -n "${1:-}"; then
print -Pnr ' (%24>..>$1%>>)' | tr '\0-\037' '?' print -Pnr ' (%24>..>$1%>>)' | tr '\0-\037' '?'
fi fi
@ -103,20 +103,20 @@ case "${TERM-}" in
precmd() { precmd() {
_set_title "$@" _set_title "$@"
if [ "${STY:-}" -o "${TMUX:-}" ]; then if [ "${STY:-}" -o "${TMUX:-}" ]; then
# print -Pn "\e]1;\a\e]1;@%m\a" # print -Pn "\033]1;\a\033]1;@%m\a"
print -Pn '\ek@\e\\' print -Pn '\033k@\033\\'
else else
print -Pn '\ek@%m\e\\' print -Pn '\033k@%m\033\\'
fi fi
} }
preexec() { preexec() {
_set_title "$@" _set_title "$@"
print -n "\ek" print -n "\033k"
print -Pnr '%10>..>$1' | tr '\0-\037' '?' print -Pnr '%10>..>$1' | tr '\0-\037' '?'
if [ "${STY:-}" -o "${TMUX:-}" ]; then if [ "${STY:-}" -o "${TMUX:-}" ]; then
print -Pn '@\e\\' print -Pn '@\033\\'
else else
print -Pn '@%m\e\\' print -Pn '@%m\033\\'
fi fi
} }
;; ;;
@ -134,8 +134,8 @@ case "${TERM-}" in
;; ;;
esac esac
unset hostcolor hostletter hostcode dircolor usercolor usercode reset_color unset hostcolor hostletter hostcode dircolor usercolor usercode reset_color \
unset newline newline ps1_symbol
## }}} ## }}}
## {{{ Completions ## {{{ Completions
@ -301,10 +301,10 @@ function clear-screen-and-scrollback() {
esac esac
test -n "${TTY-}" || return test -n "${TTY-}" || return
echoti civis >"${TTY-}" echoti civis >"${TTY-}"
printf '%b' "\e[H\e[2J" >"${TTY-}" printf '%b' "\033[H\033[2J" >"${TTY-}"
zle .reset-prompt zle .reset-prompt
zle -R zle -R
printf '%b' "\e[3J" >"${TTY-}" printf '%b' "\033[3J" >"${TTY-}"
echoti cnorm >"${TTY-}" echoti cnorm >"${TTY-}"
} }
zle -N clear-screen-and-scrollback zle -N clear-screen-and-scrollback
@ -340,9 +340,9 @@ case "${TERM-}" in
""|dumb|linux*|vt100*|vt220*) ;; ""|dumb|linux*|vt100*|vt220*) ;;
*) *)
zle-keymap-select zle-line-init() { zle-keymap-select zle-line-init() {
case $KEYMAP in case "${KEYMAP:-}" in
vicmd) print -n -- "\e[2 q";; vicmd) print -n -- "\033[2 q";;
viins|main) print -n -- "\e[5 q";; viins|main) print -n -- "\033[5 q";;
esac esac
zle reset-prompt zle reset-prompt
@ -350,7 +350,7 @@ case "${TERM-}" in
} }
zle-line-finish() { zle-line-finish() {
print -n -- "\e[2 q" print -n -- "\033[2 q"
} }
zle -N zle-line-init zle -N zle-line-init
@ -420,56 +420,56 @@ bindkey -M menuselect "^M" accept-line
## https://invisible-island.net/xterm/xterm-function-keys.html ## https://invisible-island.net/xterm/xterm-function-keys.html
## ##
## Shit+Tab ## Shit+Tab
bindkey-multi emacs viins menuselect -- "\E[Z" "${terminfo[kcbt]}" \ bindkey-multi emacs viins menuselect -- "\033[Z" "${terminfo[kcbt]}" \
-- reverse-menu-complete -- reverse-menu-complete
## Backspace ## Backspace
bindkey-multi emacs viins vicmd menuselect -- "^H" "^?" "${terminfo[kbs]}" \ bindkey-multi emacs viins vicmd menuselect -- "^H" "^?" "${terminfo[kbs]}" \
-- backward-delete-char -- backward-delete-char
## Home ## Home
bindkey-multi emacs viins vicmd -- "\E[1~" "\E[7~" "\E[H" "\EOH" \ bindkey-multi emacs viins vicmd -- "\033[1~" "\033[7~" "\033[H" "\033OH" \
"${terminfo[khome]}" \ "${terminfo[khome]}" \
-- beginning-of-line -- beginning-of-line
## Insert ## Insert
bindkey-multi emacs viins vicmd -- "\E[2~" "\E[L" "${terminfo[kich1]}" \ bindkey-multi emacs viins vicmd -- "\033[2~" "\033[L" "${terminfo[kich1]}" \
-- overwrite-mode -- overwrite-mode
## Delete ## Delete
bindkey-multi emacs viins vicmd -- "\E[3~" "\E[P" "\EOP" \ bindkey-multi emacs viins vicmd -- "\033[3~" "\033[P" "\033OP" \
"${terminfo[kdch1]}" \ "${terminfo[kdch1]}" \
-- vi-delete-char -- vi-delete-char
## End ## End
bindkey-multi emacs viins vicmd -- "\E[4~" "\E[8~" "\E[F" "\EOF" \ bindkey-multi emacs viins vicmd -- "\033[4~" "\033[8~" "\033[F" "\033OF" \
"${terminfo[kend]}" \ "${terminfo[kend]}" \
-- end-of-line -- end-of-line
## PgUp ## PgUp
bindkey-multi emacs viins -- "\E[5~" "\E[I" "${terminfo[kpp]}" \ bindkey-multi emacs viins -- "\033[5~" "\033[I" "${terminfo[kpp]}" \
-- beginning-of-buffer-or-history -- beginning-of-buffer-or-history
## PgDown ## PgDown
bindkey-multi emacs viins -- "\E[6~" "\E[G" "${terminfo[knp]}" \ bindkey-multi emacs viins -- "\033[6~" "\033[G" "${terminfo[knp]}" \
-- end-of-buffer-or-history -- end-of-buffer-or-history
## Up arrow ## Up arrow
bindkey-multi emacs viins vicmd -- "\E[A" "\EOA" "${terminfo[kcuu1]}" \ bindkey-multi emacs viins vicmd -- "\033[A" "\033OA" "${terminfo[kcuu1]}" \
-- up-line-or-history -- up-line-or-history
## Down arrow ## Down arrow
bindkey-multi emacs viins vicmd -- "\E[B" "\EOB" "${terminfo[kcud1]}" \ bindkey-multi emacs viins vicmd -- "\033[B" "\033OB" "${terminfo[kcud1]}" \
-- down-line-or-history -- down-line-or-history
## Right arrow ## Right arrow
bindkey-multi emacs viins vicmd -- "\E[1C" "\E[C" "\EOC" \ bindkey-multi emacs viins vicmd -- "\033[1C" "\033[C" "\033OC" \
"${terminfo[kcuf1]}" \ "${terminfo[kcuf1]}" \
-- forward-char -- forward-char
## Left arrow ## Left arrow
bindkey-multi emacs viins vicmd -- "\E[D" "\EOD" "${terminfo[kcub1]}" \ bindkey-multi emacs viins vicmd -- "\033[D" "\033OD" "${terminfo[kcub1]}" \
-- backward-char -- backward-char
## Ctrl-Delete ## Ctrl-Delete
bindkey-multi emacs viins vicmd -- "\E[3;5~" "\E[3\^" "${terminfo[kDC5]}" \ bindkey-multi emacs viins vicmd -- "\033[3;5~" "\033[3\^" "${terminfo[kDC5]}" \
-- kill-word -- kill-word
## Ctrl-RightArrow ## Ctrl-RightArrow
bindkey-multi emacs viins vicmd -- "\E[1;5C" "\E0c" "${terminfo[kRIT5]}" \ bindkey-multi emacs viins vicmd -- "\033[1;5C" "\0330c" "${terminfo[kRIT5]}" \
-- forward-word -- forward-word
## Ctrl-LeftArrow ## Ctrl-LeftArrow
bindkey-multi emacs viins vicmd -- "\E[1;5D" "\E0d" "${terminfo[kLFT5]}" \ bindkey-multi emacs viins vicmd -- "\033[1;5D" "\0330d" "${terminfo[kLFT5]}" \
-- backward-word -- backward-word
## F11 ## F11
bindkey-multi emacs viins -- "\E[23~" "${terminfo[kf11]}" -- new-screen bindkey-multi emacs viins -- "\033[23~" "${terminfo[kf11]}" -- new-screen
autoload -Uz edit-command-line autoload -Uz edit-command-line
zle -N edit-command-line zle -N edit-command-line
@ -477,7 +477,7 @@ bindkey -M emacs "^[e" edit-command-line
bindkey -M emacs "^X^E" edit-command-line bindkey -M emacs "^X^E" edit-command-line
bindkey -M vicmd "^E" edit-command-line bindkey -M vicmd "^E" edit-command-line
bindkey -M emacs "\ea" change-first-word bindkey -M emacs "\033a" change-first-word
bindkey -M emacs "^XD" describe-key-briefly bindkey -M emacs "^XD" describe-key-briefly
for binding in ${(f)$(bindkey -M emacs|grep -e '^"\^X')}; do for binding in ${(f)$(bindkey -M emacs|grep -e '^"\^X')}; do

View File

@ -29,7 +29,7 @@ for prog in "${@}"; do
test -x "${cmd}" || continue test -x "${cmd}" || continue
case "${action-}" in case "${action-}" in
show) printf '%s\n' "${cmd}"; exit 0;; show) printf '%s\n' "${cmd}"; unset cmd; exit 0;;
*) exit 0;; *) exit 0;;
esac esac
done done

View File

@ -67,7 +67,7 @@ fi
## Non-POSIX compliant and fast. ## Non-POSIX compliant and fast.
stty -echo stty -echo
printf '\e7\e[r\033[99999;99999H\e[6n\e8' >/dev/tty printf '\0337\033[r\033[99999;99999H\033[6n\0338' >/dev/tty
# shellcheck disable=3045,SC2034 # shellcheck disable=3045,SC2034
IFS='[;R' read -r -t 1 -s -d R _ rows cols _ </dev/tty || { IFS='[;R' read -r -t 1 -s -d R _ rows cols _ </dev/tty || {
printf '%s\n' "${msg_unsupported}" >&2 printf '%s\n' "${msg_unsupported}" >&2

View File

@ -53,7 +53,7 @@ set-option -g status-right-length '40'
set-option -g status-right-style 'fg=brightcyan,bg=black' set-option -g status-right-style 'fg=brightcyan,bg=black'
## Terminal capabilities and update environment ## Terminal capabilities and update environment
set-option -g terminal-overrides '*256color:Tc,xterm*:XT:Cc=\E]12;%p1%s\007:Cr=\E]112\007:Cs=\E[%p1%d q,rxvt-unicode*:XT:sitm@:ritm@' set-option -g terminal-overrides '*256color:Tc,xterm*:XT:Cc=\033]12;%p1%s\007:Cr=\033]112\007:Cs=\033[%p1%d q,rxvt-unicode*:XT:sitm@:ritm@'
set-option -g update-environment "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP" set-option -g update-environment "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP"
set-environment -gu DBUS_SESSION_BUS_ADDRESS set-environment -gu DBUS_SESSION_BUS_ADDRESS

View File

@ -19,7 +19,9 @@ fi
## If running normal OS or Qubes: Dom0, apply settings. ## If running normal OS or Qubes: Dom0, apply settings.
# shellcheck disable=3028 # shellcheck disable=3028
hostname="${HOSTNAME:-$(hostname)}" hostname="${HOSTNAME:-$(hostname)}"
if ! command -v qubesdb-read >/dev/null || test "${hostname}" = "dom0"; then if ! command -v qubesdb-read >/dev/null || test "${hostname}" = "dom0" ||
test -f /var/run/qubes-service/guivm
then
## Decrease key repeat delay to X ms. ## Decrease key repeat delay to X ms.
## Increase key repeat rate to Y per second. ## Increase key repeat rate to Y per second.
xset r rate 275 60 xset r rate 275 60
@ -32,6 +34,7 @@ if ! command -v qubesdb-read >/dev/null || test "${hostname}" = "dom0"; then
#qvm-prefs dom0 keyboard_layout "us+dvorak+grp:win_space_toggle,ctrl:nocaps" #qvm-prefs dom0 keyboard_layout "us+dvorak+grp:win_space_toggle,ctrl:nocaps"
fi fi
unset hostname
## Autostart desktop applications if the WM does not. ## Autostart desktop applications if the WM does not.
desktop_autostart(){ desktop_autostart(){
@ -50,6 +53,7 @@ desktop_autostart(){
command -v "${autostart_exec%% *}" >/dev/null || continue command -v "${autostart_exec%% *}" >/dev/null || continue
${autostart_exec} & ${autostart_exec} &
done done
unset f
} }
## Source Xorg profiles. ## Source Xorg profiles.
@ -59,6 +63,7 @@ if test -r "${HOME}/.xprofile.local"; then
# shellcheck disable=SC1090,SC1091 # shellcheck disable=SC1090,SC1091
! test -r "${x11_profile}" || . "${x11_profile}" ! test -r "${x11_profile}" || . "${x11_profile}"
done done
unset x11_profile
fi fi
: "${wm_list:="dwm"}" : "${wm_list:="dwm"}"
@ -69,6 +74,7 @@ for wm in ${wm_list}; do
while true; do while true; do
xroot_name="$(display-statusbar)" xroot_name="$(display-statusbar)"
xsetroot -name "${xroot_name}" xsetroot -name "${xroot_name}"
unset xroot_name
sleep 60 sleep 60
done & done &
fi fi
@ -76,5 +82,7 @@ for wm in ${wm_list}; do
${wm} & ${wm} &
wm_pid="${!}" wm_pid="${!}"
done done
unset wm
test -z "${wm_pid:-}" || wait "${wm_pid}" test -z "${wm_pid:-}" || wait "${wm_pid}"
unset wm_pid