]> arthur.barton.de Git - ax-zsh.git/commitdiff
30_hostname: Use hostnamectl(1) to get the "short" name when available
authorAlexander Barton <alex@barton.de>
Sun, 12 Mar 2017 16:32:03 +0000 (17:32 +0100)
committerAlexander Barton <alex@barton.de>
Sun, 12 Mar 2017 16:32:03 +0000 (17:32 +0100)
And don't test for the system type but the scutil(8) and hostnamectl(1)
command itself.

core/30_hostname/30_hostname.zprofile

index a4bba5da40e084e060165b1a0d533550c10b043d..a976ecd1bd95db059f68406788e1a6775cdc8800 100644 (file)
@@ -6,7 +6,10 @@
 export HOSTNAME
 
 # Setup "SHORT_HOST" variable
-[[ "$OSTYPE" = darwin* ]] \
-       && SHORT_HOST=$(scutil --get ComputerName 2>/dev/null)
+if (( $+commands[scutil] )); then
+       SHORT_HOST=$(scutil --get ComputerName 2>/dev/null)
+elif (( $+commands[hostnamectl] )); then
+       SHORT_HOST=$(hostnamectl --pretty 2>/dev/null)
+fi
 [[ -z "$SHORT_HOST" ]] && SHORT_HOST=${HOST/.*/}
 export SHORT_HOST