Improved introspection logic in shell config

This commit is contained in:
2026-01-23 10:29:47 -07:00
parent e44618391b
commit cfe932bf4a
3 changed files with 19 additions and 16 deletions

View File

@@ -52,7 +52,7 @@ refresh-system-info() {
fi
# Parse detailed system info from hostnamectl, or synthesize what we can from /etc/machine-info and static and transient hostnames.
if type hostnamectl &>/dev/null; then
if type hostnamectl &>/dev/null && (( $(hostnamectl --version | head -n 1 | cut -d' ' -f2) >= 252 )); then
# We can get all relevant data from hostnamectl, so lets do that.
eval $(hostnamectl --json=short | jq -r 'to_entries | .[] | select((.value | type) != "array" and (.value | type) != "object" and (.value | type) != "null") | "SYSTEM_INFO[\(.key)]=\(.value | @sh)"')
INTRO_STATE[SYSTEM_INFO]=full

View File

@@ -37,12 +37,12 @@ function random-xkcd() {
curl $(echo $html | (echo "https:"$(xmllint --html --xpath 'string(//html/body/div[@id="middleContainer"]/div[@id="comic"]/img/@src)' - 2>/dev/null))) 2>/dev/null | feh -
}
if [[ $(hostnamectl chassis) == "container" ]]; then
DEFAULT_WINDOW_NAME="Container Connection: [ ${SYSTEM_INFO[PrettyHostname]:-${SYSTEM_INFO[Hostname]}} Console ]"
if [[ ${SYSTEM_INFO[Chassis]} == "container" ]]; then
DEFAULT_WINDOW_NAME="[ Container Connection ] ${SYSTEM_INFO[PrettyHostname]:-${SYSTEM_INFO[Hostname]}} Console"
elif [[ -z "${SSH_CONNECTION+x}" ]]; then
DEFAULT_WINDOW_NAME="${SYSTEM_INFO[PrettyHostname]:-${SYSTEM_INFO[Hostname]}} Console"
else
DEFAULT_WINDOW_NAME="Remote Connection: [ ${SYSTEM_INFO[PrettyHostname]:-${SYSTEM_INFO[Hostname]}} Console ]"
DEFAULT_WINDOW_NAME="[ Remote Connection ] ${SYSTEM_INFO[PrettyHostname]:-${SYSTEM_INFO[Hostname]}} Console"
fi
function _rename_window() {
@@ -138,14 +138,16 @@ function bwunlock() {
}
function su {
local user
user=$1
if [[ $user == '' ]]; then
user=root
fi
machinectl -q shell "${user}@"
}
if type machinectl &>/dev/null; then
function su {
local user
user=$1
if [[ $user == '' ]]; then
user=root
fi
machinectl -q shell "${user}@"
}
fi
alias relog='exec machinectl -q shell "${USER}@"'
@@ -202,6 +204,7 @@ function ssh-copy-shell {
ssh -p ${port} ${host} mkdir -p .config .local/lib
# Deploy files
sftp -P ${port} ${host} <<SFTP
lcd ~
put -R .config/zsh .config
put -R .local/lib/zsh .local/lib
put .zshrc

View File

@@ -26,7 +26,7 @@ precmd_kernel_info() {
# if message has been set, don't check again, since a reboot
# is required to clear the message
if [[ -n ${kernel_info_msg_0_} ]]; then
if [[ ${kernel_info_msg_0_+x} == "x" ]]; then
return
fi
if [[ ${OS_RELEASE[Id]} == "arch" ]] || [[ ${OS_RELEASE[IdLike]} == "arch" ]]; then
@@ -34,7 +34,7 @@ precmd_kernel_info() {
# just check to see if /usr/lib/modules/$(uname -r)/vmlinuz exists
if ! [[ -f /usr/lib/modules/$(uname -r)/vmlinuz ]]; then
# kernel update available
kernel_info_msg_0_="%F{red} reboot required %f"
kernel_info_msg_0_="%F{red}%B󱄋%b%f"
fi
fi
}
@@ -55,9 +55,9 @@ if [[ ${SYSTEM_INFO[Chassis]} != "container" ]] && [[ ${OS_RELEASE[IdLike]:-${OS
fi
prompt_list=(
'$kernel_info_msg_0_' $'\n'
$'\n'
"%F{cyan}[%f " ${prompt_elements[deployment]} ${prompt_elements[host]} ${prompt_elements[privilege]} " %F{cyan}]%f" ${prompt_elements[console]} ${prompt_elements[pyenv]} ' ' ${prompt_elements[pwd]} ${prompt_elements[groups]}
" " ${prompt_elements[prompt]}
'$kernel_info_msg_0_ ' ${prompt_elements[prompt]}
)
rprompt_list=(
${prompt_elements[vcs]} ${prompt_elements[retcode]}