3

I'm trying to get my Chinese computer name/machine name to display in a zsh prompt i.e. 飞碟. PROMPT='%{$fg[green]%}%m%. The normal Mac Sharing prefs displays the computer name in Chinese, but shell ends up changing it to the roman characters (pinyin) that represent that Chinese i.e. feidie. Is there any way to get machine names in other languages to display in a shell or will it always default to English since the local host name is always forced to English as well?

Here is the output of uname -n | od -tx1 -tc

0000000    66  65  69  64  69  65  2e  6c  6f  63  61  6c  0a            
            f   e   i   d   i   e   .   l   o   c   a   l  \n
6
  • It looks like the hostname is feidie, but 飞碟 is the computer description (some text setting that is specific to macOS, so you'd need to find the right macOS API to query that string) Mar 13 '17 at 11:36
  • According to How do I find my "computer description" in a Java application on Windows and/or Mac?, it looks like it's scutil --get computerName Mar 13 '17 at 11:39
  • Yes I've been to that page :) It's scutil --get ComputerName. It returns the Chinese properly. Which means that %m name is actually printing the localhost name (since the localhost name always defaults (is forced) to English). scutil --get LocalHostName returns feidie. scutil --get HostName returns "not set".
    – Edison
    Mar 13 '17 at 11:44
  • yes %m is the host name (same as output of uname -n) like on any other Unix-likes. While the output of scutil --get ComputerName is something that is macOS specific. Some other OS or OS software (like samba or avahi) can give some form or another of textual description of the computer, that's not what zsh uses there either. It can only reasonably rely on the standard host name which can be retrieved using a standard API. Mar 13 '17 at 11:52
  • 2
    just add a HOST_DESCRIPTION=$(scutil --get ComputerName) in your ~/.zshrc and use that $HOST_DESCRIPTION in your prompt. Or use $(scutil --get ComputerName) in the prompt though that would mean running that command at each prompt for something that hardly ever changes. Mar 13 '17 at 12:08
1

Thanks Stéphane for the HOST_DESCRIPTION swizzle🌀

# .zshrc
HOST_DESCRIPTION=$(scutil --get ComputerName)

# PROMPT
PROMPT='%F{yellow}${HOST_DESCRIPTION}%f'

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.