From: Alexander Barton Date: Sat, 15 Apr 2017 22:41:34 +0000 (+0200) Subject: 30_hostname: Validate SHORT_HOST variable X-Git-Url: https://arthur.barton.de/gitweb/?p=ax-zsh.git;a=commitdiff_plain;h=d7c38658ad0e6ae03a6ca63c7cb80c44092ff357 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. --- 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