ZSH Agnoster Theme showing machine name
ShellUbuntuZshDigital OceanOh My-ZshShell Problem Overview
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.
Shell Solutions
Solution 1 - Shell
It is the feature according to this; when we are ssh
ing, 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 () { }
Solution 2 - Shell
Here is my version from first two answers. They explain very clearly. I will merge again.
-
step 1. open your
.zshrc
file byvim .zshrc
-
step 2. go to end of your file.
-
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 :)
Solution 3 - Shell
I'm using agnoster theme too.
Edit agnoster.zsh-theme
and find $user@%m
and delete @%m
.
Image sample:
Solution 4 - Shell
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.
Solution 5 - Shell
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]} "
}
Solution 6 - Shell
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.
Solution 7 - Shell
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.
Solution 8 - Shell
open ~/.zshrc
add line:
DEFAULT_USER=whoami
or export DEFAULT_USER= myusername (mac os x)
open ~/.oh-my-zsh/themes/agnoster.zsh-theme files.
find ## Main prompt add # for prompt_context line.
Solution 9 - Shell
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.
Solution 10 - Shell
Related to the context: Sometimes sourcing the zshrc by "source ~/.zshrc" might not work. Start a new terminal to see the updated changes.
Solution 11 - Shell
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).
- Go to your
~/.oh-my-zsh/custom/themes
folder - Create a file called
agnoster.zsh-theme
- Add your customization and save (for example, here, redefine the
prompt_context()
so it does nothing):
prompt_context() {}
- Update your terminal with your changes:
source ~/.zshrc