Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trust but verify 'scutil' to return ComputerName #2743

Merged
merged 1 commit into from Sep 3, 2014

Conversation

docwhat
Copy link
Contributor

@docwhat docwhat commented Apr 23, 2014

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
Copy link
Contributor Author

docwhat commented Jul 21, 2014

ping?

@mcornella
Copy link
Member

👍

SHORT_HOST=$(scutil --get ComputerName)
if [[ "$OSTYPE" = darwin* ]]; then
# OS X's $HOST changes with dhcp, etc. Use ComputerName if possible.
SHORT_HOST=$(/usr/sbin/scutil --get ComputerName 2>/dev/null) || SHORT_HOST=${HOST/.*/}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scutil should continue being used without absolute path. Also, on #2183 they use `$(hostname -s)', is that better than using $HOST?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are three reasons to continue to use $HOST:

  1. Even if $OSTYPE equals darwin* that doesn't mean they are running a full OS X environment (e.g. just running the darwin kernel on a bsd or gnu system). hostname -s doesn't work on all unixes.
  2. $HOST is faster since it doesn't have to fork/exec.
  3. It matches what happens on non-OSX systems.

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 ohmyzsh#2155
Closes ohmyzsh#2183
@docwhat
Copy link
Contributor Author

docwhat commented Jul 23, 2014

I removed the scutil absolute path.

@mcornella
Copy link
Member

Perfect, I support this change (bonus points for using $OSTYPE)
:shipit:

@docwhat
Copy link
Contributor Author

docwhat commented Jul 23, 2014

If you want more $OSTYPE goodness, see #2744

@mcornella and @ncanceill -- Should I resubmit this and #2744 to https://github.com/ncanceill/oh-my-zsh/tree/easymerge ?

@mcornella
Copy link
Member

/cc @robbyrussell

robbyrussell added a commit that referenced this pull request Sep 3, 2014
Trust but verify 'scutil' to return ComputerName
@robbyrussell robbyrussell merged commit dd644a1 into ohmyzsh:master Sep 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"ComputerName: not set" message on startup
3 participants