Use POSIX-compliant uname instead of hostname #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
shell_intergration scripts depends on hostname(1), assuming it's available on every host including remote ones (over SSH).
However that's not the case with some Linux environments.
For example, in Arch Linux you need install
inetutils
package.This leads to seeing the following error message every time I login to such hosts:
shell_integration/zsh:164: command not found: hostname
.Solution
This PR aims to fix the problem by simply replacing all hostname(1) calls to uname(1).
This makes two differences:
uname -n
is available on practically every UNIX-like system including FreeBSD, NetBSD, and OpenBSD.uname -n
is faster because it's simply invoking uname(2) syscall2. On the other hand,hostname -f
uses gethostbyname(3)3 which causes name server lookups every time.Discussion
This is my first contribution to your repository.
Please forgive me if it's not your taste; I'd appreciate if you can help improving this PR.
Thanks for this lovely product!
Footnotes
https://pubs.opengroup.org/onlinepubs/009695299/utilities/uname.html ↩
https://github.com/coreutils/coreutils/blob/9581c4b59d2e11cd090613cd300a833b4441d2b5/src/uname.c#L299-L305 ↩
https://git.savannah.gnu.org/cgit/inetutils.git/tree/src/hostname.c?id=c1b8d134d542e7e81c3dcd6adbd05305cb2c78df#n290 ↩