fix: unset global variables

This commit is contained in:
Ben Grande 2025-01-24 16:22:36 +01:00
parent a7d2876bb4
commit 8a6cdd5096
No known key found for this signature in database
GPG Key ID: 00C64E14F51F9E56
7 changed files with 44 additions and 22 deletions

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
@ -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=$?; }
@ -119,7 +124,7 @@ 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

@ -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(){
@ -247,13 +250,13 @@ _git_prompt_info(){
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}%<<%%{\033[0m%%})' 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})"
@ -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

@ -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
@ -340,7 +340,7 @@ 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 -- "\033[2 q";; vicmd) print -n -- "\033[2 q";;
viins|main) print -n -- "\033[5 q";; viins|main) print -n -- "\033[5 q";;
esac esac

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

@ -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