From d7c38658ad0e6ae03a6ca63c7cb80c44092ff357 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Sun, 16 Apr 2017 00:41:34 +0200 Subject: [PATCH] 30_hostname: Validate SHORT_HOST variable Old(er) versions of hostnamectl(1) don't support the "--pretty" parameter but output verbose text showing all information. So validate the SHORT_HOST variable afterwards and unset it again when it contains ":" characters: then the fallback is used. Tested with hostnamectl(1) of systemd 204. --- core/30_hostname/30_hostname.zprofile | 1 + 1 file changed, 1 insertion(+) diff --git a/core/30_hostname/30_hostname.zprofile b/core/30_hostname/30_hostname.zprofile index a976ecd..5b2dbd3 100644 --- a/core/30_hostname/30_hostname.zprofile +++ b/core/30_hostname/30_hostname.zprofile @@ -10,6 +10,7 @@ if (( $+commands[scutil] )); then SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) elif (( $+commands[hostnamectl] )); then SHORT_HOST=$(hostnamectl --pretty 2>/dev/null) + [[ "$SHORT_HOST" =~ : ]] && unset SHORT_HOST fi [[ -z "$SHORT_HOST" ]] && SHORT_HOST=${HOST/.*/} export SHORT_HOST -- 2.39.2