Reputation: 6872
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.
Upvotes: 56
Views: 53898
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
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).
~/.oh-my-zsh/custom/themes
folderagnoster.zsh-theme
prompt_context()
so it does nothing): prompt_context() {}
source ~/.zshrc
Upvotes: 1
Reputation: 161
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
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
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
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
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
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
Reputation: 30284
Here is my version from first two answers. They explain very clearly. I will merge again.
step 1. open your .zshrc
file by vim .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 :)
Upvotes: 75
Reputation: 1030
I'm using agnoster theme too.
Edit agnoster.zsh-theme
and find $user@%m
and delete @%m
.
Image sample:
Upvotes: 32
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
Reputation: 5339
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 () { }
Upvotes: 100