From 5738a17688d341abc3f99ad3be2d32b344d38232 Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Sun, 15 Jun 2025 18:51:42 -0700 Subject: [PATCH] fix(init): use LocalHostName for SHORT_HOST on macos, fix zrecompile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Init on macos systems: determine SHORT_HOST from scutil's `LocalHostName` instead of `ComputerName`. This addresses an issue with zcompdump not being written on computers with unicode characters in the name. From `man scutil`: > Supported preferences include: > > ComputerName The user-friendly name for the system. > LocalHostName The local (Bonjour) host name. > HostName The name associated with hostname(1) and gethostname(3). `ComputerName` often contains spaces and special characters, while `LocalHostName` is generated from `ComputerName` (by default), and normalized to look like a normal host name. Example: ```sh-session $ scutil --get ComputerName Sergii’s Mac $ scutil --get LocalHostName Sergiis-Mac ``` When ComputerName is used, my zcompdump file looks like this: ```sh-session $ ls ~/.zcompdump* '/Users/sergii/.zcompdump-Sergii’s Mac-5.9' ``` Yes, it contains a unicode character: ```sh-session $ print -N "’" | od -tc -tu1 0000000 ’ ** ** \0 226 128 153 0 ``` Because of that, zrecompile fails to write the compdump. ```sh-session $ zrecompile -p .zcompdump-Sergii’s\ Mac-5.9 re-compiling .zcompdump-Sergii’s Mac-5.9.zwc: zrecompile:zcompile:133: can't write zwc file: .zcompdump-Sergii’s Mac-5.9.zwc re-compiling .zcompdump-Sergii’s Mac-5.9.zwc: failed $ cp .zcompdump-Sergii’s\ Mac-5.9 .zcompdump-stk $ zrecompile -p .zcompdump-stk re-compiling .zcompdump-stk.zwc: succeeded ``` --- oh-my-zsh.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 2e885219c..3e547d358 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -99,8 +99,8 @@ done # Figure out the SHORT hostname if [[ "$OSTYPE" = darwin* ]]; then - # macOS's $HOST changes with dhcp, etc. Use ComputerName if possible. - SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST="${HOST/.*/}" + # macOS's $HOST changes with dhcp, etc. Use LocalHostName if possible. + SHORT_HOST=$(scutil --get LocalHostName 2>/dev/null) || SHORT_HOST="${HOST/.*/}" else SHORT_HOST="${HOST/.*/}" fi