00b21d5ac322178b9b9e397b0b6178a3d7f4e9ee

Author
Christian Höltje <choltje@us.ibm.com>
Committer
Christian Höltje <docwhat@gerf.org>
Date

Message

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

Diff

 1diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh
 2index c217b91bbb57493b91263dc196e75caaec81c5a5..8ce29ff38726ab2b9b3cdc222eff633a6fccc3be 100644
 3--- a/oh-my-zsh.sh
 4+++ b/oh-my-zsh.sh
 5@@ -38,9 +38,9 @@ for plugin ($plugins); do
 6 done
 7 
 8 # Figure out the SHORT hostname
 9-if [ -n "$commands[scutil]" ]; then
10-  # OS X
11-  SHORT_HOST=$(scutil --get ComputerName)
12+if [[ "$OSTYPE" = darwin* ]]; then
13+  # OS X's $HOST changes with dhcp, etc. Use ComputerName if possible.
14+  SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST=${HOST/.*/}
15 else
16   SHORT_HOST=${HOST/.*/}
17 fi