Trust but verify 'scutil' to return ComputerName

Apparently, it is possible to set up a Mac such that
`scutil --get ComputerName` hasn't been set.

This change checks if that fails and falls back to the original
mechanism.

Closes #2155
Closes #2183
This commit is contained in:
Christian Höltje 2014-04-23 09:41:09 -04:00 committed by Christian Höltje
parent 207b6a1e33
commit 00b21d5ac3

View File

@ -38,9 +38,9 @@ for plugin ($plugins); do
done
# Figure out the SHORT hostname
if [ -n "$commands[scutil]" ]; then
# OS X
SHORT_HOST=$(scutil --get ComputerName)
if [[ "$OSTYPE" = darwin* ]]; then
# OS X's $HOST changes with dhcp, etc. Use ComputerName if possible.
SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST=${HOST/.*/}
else
SHORT_HOST=${HOST/.*/}
fi