Drew
Drew

Reputation: 6872

ZSH Agnoster Theme showing machine name

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:

enter image description here

enter image description here

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.

enter image description here

Upvotes: 56

Views: 53898

Answers (12)

Rohith R Pai
Rohith R Pai

Reputation: 11

prompt_context() {
  # Custom (Random emoji)

  MINUTE_TRC=$(date +%M)
  emojis_1=("🐈" "🔥" "🚀" "💡" "😼" "😹" "🙀" "😻" "😽" "🇮🇳" "😺" "😸")
  emojis_2=("🙈" "🙉" "🙊" "🐵" "🦊" "🦁" "🐯" "🐮" "🐰" "🐼" "🧸" "🐿️")    

  if (($MINUTE_TRC % 2 != 0)); then
    RAND_EMOJI_N=$(( $RANDOM % ${#emojis_1[@]} + 1))
    prompt_segment black default "%(!.%F{red}.%F{red})%n%F{green}@%F{Blue}%m %F{reset} ${emojis_1[$RAND_EMOJI_N]} "
  else
    RAND_EMOJI_N=$(( $RANDOM % ${#emojis_2[@]} + 1))
    prompt_segment black default "%(!.%F{red}.%F{red})%n%F{green}@%F{green}%m %F{reset} ${emojis_2[$RAND_EMOJI_N]} "
  fi
}

Improvement on Pongsatorn Nitithammawoot config. This will make the emoji change every min.

Upvotes: 0

Arnaud Valle
Arnaud Valle

Reputation: 1861

Although the accepted answer is perfectly fine, I prefer to modify my .zshrc file as little as I can to keep things clean.

So, a slightly different approach would be to override the theme (as recommended on https://github.com/robbyrussell/oh-my-zsh/wiki/Customization#overriding-and-adding-themes).

  1. Go to your ~/.oh-my-zsh/custom/themes folder
  2. Create a file called agnoster.zsh-theme
  3. Add your customization and save (for example, here, redefine the prompt_context() so it does nothing):
prompt_context() {}
  1. Update your terminal with your changes:
source ~/.zshrc

Upvotes: 1

My config in ~/.oh-my-zsh/themes/agnoster.zsh-theme

prompt_context() {
  # Custom (Random emoji)
  emojis=("⚡️" "🔥" "💀" "👑" "😎" "🐸" "🐵" "🦄" "🌈" "🍻" "🚀" "💡" "🎉" "🔑" "🇹🇭" "🚦" "🌙")
  RAND_EMOJI_N=$(( $RANDOM % ${#emojis[@]} + 1))
  prompt_segment black default "${emojis[$RAND_EMOJI_N]} "
}

Upvotes: 16

Vigneshwar
Vigneshwar

Reputation: 125

Related to the context: Sometimes sourcing the zshrc by "source ~/.zshrc" might not work. Start a new terminal to see the updated changes.

Upvotes: 1

Joe Zhow
Joe Zhow

Reputation: 1019

We needn't edit agnoster.zsh-theme but append the code below at the end of .zshrc:

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

we can change export USER='' like export USER='john' to show what we want.

Upvotes: 1

William Leiby
William Leiby

Reputation: 31

Put this in your .zshrc file before the 'source $ZSH/oh-my-zsh.sh'

DEFAULT_USER=drewr

I use Agnoster as well, and this is what I put to take away the username from displaying.

Hope this helps.

Upvotes: 3

IAmKale
IAmKale

Reputation: 3426

If you're on macOS, the addition of a single line to your ~/.zshrc file is enough to hide the machine name in the Terminal:

# Where we specify the theme
ZSH_THEME="agnoster"
# Force yourself as the system's default user
DEFAULT_USER="$(whoami)"

This will negate the "$user" != "$DEFAULT_USER" check here, thereby hiding the machine name locally while still displaying it for SSH connections.

Upvotes: 10

David Pan
David Pan

Reputation: 9

1. open ~/.zshrc add line: DEFAULT_USER=whoami or export DEFAULT_USER= myusername (mac os x)

2. open ~/.oh-my-zsh/themes/agnoster.zsh-theme files.

find ## Main prompt add # for prompt_context line.

Upvotes: 1

hqt
hqt

Reputation: 30284

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 :)

Upvotes: 75

Rizqi N. Assyaufi
Rizqi N. Assyaufi

Reputation: 1030

I'm using agnoster theme too.

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

Image sample:

enter image description here

Upvotes: 32

SYD
SYD

Reputation: 979

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.

Upvotes: 14

hchbaw
hchbaw

Reputation: 5339

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 () { }

Upvotes: 100

Related Questions