From 00b21d5ac322178b9b9e397b0b6178a3d7f4e9ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ho=CC=88ltje?= Date: Wed, 23 Apr 2014 09:41:09 -0400 Subject: [PATCH] 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 --- oh-my-zsh.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index c217b91bb..8ce29ff38 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -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