找到你要的答案

Q:ZSH Agnoster Theme showing machine name

Q:zsh agnoster主题显示机器名

I have a development server hosted on Digital Ocean, using Ubuntu 14.04. I switched my shell to ZSH and decided to go with the Agnoster theme. In order to get user@hostname to stop showing, I set the DEFAULT_USER in my .zshrc file.

For some reason on the ubuntu server, that's not working. The hostname still shows, and will not go away. I'm doing the exact same thing on my Mac OSX, and it works fine.

Here are some screenshots:

Anyone know what's going on? I even tried DEFAULT_USER="$USER@$HOST" with no luck.

If I go back to the default, Robby Russell theme, it works just fine.

我有一个托管在数字海洋开发服务器,使用Ubuntu 14.04。我把我的壳中,决定用agnoster主题。为了让用户@主机名停止放映,我在我的default_user .zshrc文件。

因为某些原因,在Ubuntu服务器,这不是工作。主机还显示,并不会消失。我做同样的事情,在我的Mac OSX,和很好的工作。

这里有一些截图:

有人知道发生了什么事吗?我甚至想default_user =“用户名@主机美元”没有运气。

如果我回到默认,Robby Russell的主题,它工作得很好。

answer1: 回答1:

It is the feature according to this; when we are sshing, the hostname will be shown.

Overriding the function prompt_context or build_prompt on Agnoster theme will rescue. Putting below snippets at the very end of the ~/.zshrc for example.

# redefine prompt_context for hiding user@hostname
prompt_context () { }

它是根据这一特征;当我们sshing,主机将显示。

重写的函数prompt_context或build_prompt在agnoster主题将救援。把下面的~ /最后片段.zshrc例如。

# redefine prompt_context for hiding user@hostname
prompt_context () { }
answer2: 回答2:

I'm using agnoster theme too.

Edit agnoster.zsh-theme and find $user@%m and delete @%m.

Image sample:

我用agnoster主题太。

编辑agnoster.zsh-theme找到用户@ %美元M和删除“% M.

图像样本:

answer3: 回答3:

You can set DEFAULT_USER="[user name]" in your .zshrc file and it will stop showing the user@hostname in your terminal.

In order to get the [user name], type id -un in your terminal and it will output the [user name] value.

你可以设置default_user =“[用户名]“你.zshrc文件,它将停止显示用户@主机名在你的终端。

为了获得[用户名],键入ID -联合国在您的终端,它将输出[用户名]值。

answer4: 回答4:

Here is my version from first two answers. They explain very clearly. I will merge again.

  1. step 1. open your .zshrc file by vim .zshrc

  2. step 2. go to end of your file.

  3. Paste this code:

careful indent again your code

prompt_context() {
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
    prompt_segment black default "%(!.%{%F{yellow}%}.)$USER"
  fi
}

Reference link: agnoster theme code

Hope this help :)

这是我的前两个答案的版本。他们解释得很清楚。我将再次合并。

  1. 步骤1。打开你的文件,Vim zshrc .zshrc

  2. 步骤2。转到文件的结尾。

  3. 粘贴此代码:

小心你的代码缩进了

prompt_context() {
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
    prompt_segment black default "%(!.%{%F{yellow}%}.)$USER"
  fi
}

参考链接:agnoster主题代码

希望此帮助:

shell  ubuntu  zsh  digital-ocean  oh-my-zsh