Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fixes "ComputerName: not set" issue #2155 #2183

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
7 participants

As already mentioned in #2155 ComputerName has to be set before, otherwise you get ComputerName: not set on startup. I think hostname -s is more common/global way to get short host name.

Tested on OS X 10.8.5 and Ubuntu 12.10

Owner

robbyrussell commented Dec 3, 2013

Don't think hostname -s works on all environments though.

Well I've checked unix/linux and bsd man pages and they are all including -s option.

JoahG commented Dec 3, 2013

I can vouch for OS X 10.9 - works fine 👍

Collaborator

mcornella commented Feb 28, 2014

Here on debian jessie: hostname is installed by default in /bin/hostname, version 3.15
with argument -s meaning "short host".
Looks good to me, but I guess you can always keep scutil just in case. Redirecting stderr to /dev/null might be a good idea too.

Contributor

docwhat commented Apr 23, 2014

This is the first system I've seen that scutil --get ComputerName doesn't work on... I didn't think you could skip naming the computer on OS X...

The reason to use it is that hostname -s and its variants change if you use a laptop on various networks. This can make things jump around (e.g. the name of the $ZSH_COMPDUMP).

Does ubuntu have scutil? That's new... Maybe the check should be [ $OSTYPE = darwin* && -n "$commands[scutil]" ]?

Contributor

ncanceill commented Apr 23, 2014

scutil is a Mac tool.

@ismailasci, as @docwhat mentioned, Mac will dynamically change the value of hostname -s according to DHCP, which is why scutil is used here.

I think the proper fix would be first to check -n "$commands[scutil]" and then check if the output is not blank, eg:

if [ -n "$commands[scutil]" ]; then
  SHORT_HOST=$(scutil --get ComputerName)
  if [[ $(echo -n $SHORT_HOST | wc -c) -gt 0 ]]; then
    SHORT_HOST=$(hostname -s)
  fi
else
Contributor

docwhat commented Apr 23, 2014

If someone who has this problem can confirm that the error is put out on stderr, that'd be great.

Contributor

ncanceill commented Apr 23, 2014

Ah OK, the scutil command itself spits out the error. So yes, I confirm that the error goes to stderr and not stdout.

New version:

if [ -n "$commands[scutil]" ]; then
  SHORT_HOST=$(scutil --get ComputerName 2>/dev/null)
  if [[ $(echo -n $SHORT_HOST | wc -c) -lt 1 ]]; then
    SHORT_HOST=$(hostname -s)
  fi
else
Contributor

docwhat commented Apr 23, 2014

Btw: hostname -s does not work on all versions of unix. The old $HOST check is the best alternative.

Contributor

ncanceill commented Apr 23, 2014

Yes, but in the first part of the if statement (the one I reproduced) we know we are on Mac OS.

The end should remain:

else
  SHORT_HOST=${HOST/.*/}
fi
Contributor

docwhat commented Apr 23, 2014

Good point. But the results should be identical and using variables instead of a command is faster.

docwhat pushed a commit to docwhat/oh-my-zsh that referenced this pull request Apr 23, 2014

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

docwhat added a commit to docwhat/oh-my-zsh that referenced this pull request Jul 23, 2014

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

hoggarth added a commit to hoggarth/oh-my-zsh that referenced this pull request Sep 4, 2014

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

swanandp added a commit to swanandp/oh-my-zsh that referenced this pull request Sep 15, 2014

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

ArjenSchwarz added a commit to ArjenSchwarz/oh-my-zsh that referenced this pull request Sep 16, 2014

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

Stibbons added a commit to Stibbons/oh-my-zsh that referenced this pull request Sep 17, 2014

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

mohitsethi added a commit to mohitsethi/oh-my-zsh that referenced this pull request Oct 2, 2014

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

noj added a commit to noj/oh-my-zsh that referenced this pull request Nov 4, 2014

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

benjaoming added a commit to benjaoming/oh-my-zsh that referenced this pull request Nov 28, 2014

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

kenton added a commit to kenton/oh-my-zsh that referenced this pull request Jan 9, 2015

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

hbpoison added a commit to hbpoison/oh-my-zsh that referenced this pull request Aug 14, 2015

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

NobbZ added a commit to NobbZ/oh-my-zsh that referenced this pull request May 15, 2016

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment