]> arthur.barton.de Git - ax-zsh.git/commitdiff
30_hostname: Validate SHORT_HOST variable
authorAlexander Barton <alex@barton.de>
Sat, 15 Apr 2017 22:41:34 +0000 (00:41 +0200)
committerAlexander Barton <alex@barton.de>
Sat, 15 Apr 2017 22:41:34 +0000 (00:41 +0200)
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

index a976ecd1bd95db059f68406788e1a6775cdc8800..5b2dbd3faa15899af1295095b6f2cfd451f0bdf1 100644 (file)
@@ -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