Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
elbrinke opened this issue Jun 6, 2017 · 21 comments
Open

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

elbrinke opened this issue Jun 6, 2017 · 21 comments

Comments

@elbrinke
Copy link

elbrinke commented Jun 6, 2017

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
Copy link

itsmehemant123 commented Jun 9, 2017

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
Copy link
Contributor

This PR will help: #40

@grmat
Copy link

grmat commented Jan 31, 2018

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
Copy link

ghost commented Apr 18, 2018

How to set agnoster theme in termux please tell me

@kud
Copy link

kud commented Nov 28, 2018

In my .zshrc I did:

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

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

:)

@biigpongsatorn
Copy link

biigpongsatorn commented Mar 7, 2019

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
Copy link

carloza commented Jun 4, 2019

@itsmehemant123 ty so much

@LukaszBielsko
Copy link

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
Copy link
Collaborator

apjanke commented Jan 4, 2020

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
Copy link

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
Copy link

Simply add DEFAULT_USER=$USER in .zshrc

@awshumway
Copy link

@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
Copy link

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

@asterisk-ragavan
Copy link

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

@iruslanalexan
Copy link

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
Copy link

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

@renatojobal
Copy link

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

export DEFAULT_USER="$(whoami)"

@AtomicNess123
Copy link

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

@Mr-Vipi
Copy link

Mr-Vipi commented Oct 8, 2021

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
Copy link

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

prompt_context() {}

@jangandibantingg
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests