agnoster / agnoster-zsh-theme

A ZSH theme designed to disclose information contextually, with a powerline aesthetic
3.95k stars 583 forks source link

How do I hide the “user@hostname” info #39

Open elbrinke opened 7 years ago

elbrinke commented 7 years ago

It is said to do the following: Optionally set DEFAULT_USER to your regular username followed by prompt_context(){} in ~/.zshrc to hide the “user@hostname” info when you’re logged in as yourself on your local machine.

What does that look like?

itsmehemant123 commented 7 years ago

Open your .zshrc and paste this at the bottom:

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

This makes only your username to appear. If you don't want that too, just comment out this line prompt_segment black default "%(!.%{%F{yellow}%}.)$USER"

Picked this up from here

MichaelAquilina commented 7 years ago

This PR will help: https://github.com/agnoster/agnoster-zsh-theme/pull/40

grmat commented 6 years ago

May I ask why the DEFAULT_USER query is there at all?

Perhaps I miss something, but it seems like a double-check, when SSH_CLIENT is already being queried. It's an extra step required when working on different machines with different users, or when sharing or adapting dotfiles. It potentially also leads to disclosure of people's local usernames in their public dotfiles.

ghost commented 6 years ago

How to set agnoster theme in termux please tell me

kud commented 5 years ago

In my .zshrc I did:

# change prompt
prompt_context() {
  prompt_segment $PRIMARY_FG default  "  🌈  "
}

prompt_dir() {
  prompt_segment blue $PRIMARY_FG ' %c '
}

:)

biigpongsatorn commented 5 years ago

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

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

image

carloza commented 5 years ago

@itsmehemant123 ty so much

LukaszBielsko commented 4 years ago

In my .zshrc I did:

# change prompt
prompt_context() {
  prompt_segment $PRIMARY_FG default  "  🌈  "
}

prompt_dir() {
  prompt_segment blue $PRIMARY_FG ' %c '
}

:)

thanks for that!

apjanke commented 4 years ago

May I ask why the DEFAULT_USER query is there at all?

I think this is in case you're su-ing or logging in as an unusual user on your local machine, or you have a typical "regular" account you use on multiple machines.

TheLandolorien commented 4 years ago

Similar to @kud, but modified my prompt to work in agnoster.

I updated the prompt_context in ~/.oh-my-zsh/themes/agnoster.zsh-theme (because it was being overwritten) and used the agnoster background variable (CURRENT_BG):

prompt_context() {
  prompt_segment $CURRENT_BG default  "  🌈  "
}
MuhaddiMu commented 4 years ago

Simply add DEFAULT_USER=$USER in .zshrc

awshumway commented 4 years ago

@itsmehemant123 's solution didn't quite work for me.
I want to recommend changing this in your theme, rather than your .zshrc like @TheLandoCal , I updated the prompt_context in ~/.oh-my-zsh/themes/agnoster.zsh-theme.

For me, I just wanted to show my username, without my '@ hostname'.

Original agnoster.zsh-theme:

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

I just removed @%m from line 92.

Updated agnoster.zsh-theme:

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

wow, nothing helped. I'm using bira theme.

asterisk-ragavan commented 3 years ago

Iam using oh my zsh and ur theme is listed there how can I install ur theme, pls tell me

iruslanalexan commented 3 years ago

On MacOS 10.15 Catalina in 2021 year

Open the file /private/etc/zshrc in a text editor
Locate the comment: # Default prompt
Modify the line that looks like this: PS1="%n@%m~ %& # "
Save the file. You will be prompted to enter a password to save it.
Load a new Terminal window.

For example, you can:

Remove "%n@%m" to get rid of both the username and computer name
Remove "%n" to get rid of the user name
Remove "%m" to get rid of the machine name

Source https://stackoverflow.com/a/59944342/10991361

AtomicNess123 commented 2 years ago

How to hide the owner and group names when doing listings (ls -la) for instance?

renatojobal commented 2 years ago

Make sure you add this line to the ~/.zshrc file:

export DEFAULT_USER="$(whoami)"
AtomicNess123 commented 2 years ago

Thanks! The last thing would be how to hide or change the user name on the top of the Terminal window?

Mr-Vipi commented 2 years ago

Thanks! The last thing would be how to hide or change the user name on the top of the Terminal window?

In order to achieve what you want, in the ~/.zshrc file:

First uncomment DISABLE_AUTO_TITLE="true" and after

add this line precmd () { print -Pn "\e]2; %~\a" } # title bar prompt at the end of the file:

Source https://superuser.com/questions/79972/set-the-title-of-the-terminal-window-to-the-current-directory

mauriciabad commented 2 years ago

In ~/.oh-my-zsh/themes/agnoster.zsh-theme change the prompt_context function to not do anything. Like this:

prompt_context() {}
jangandibantingg commented 4 months ago

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

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

image

woooo tankyou bro