xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

How to change Linux Terminal display username All In One

How to change Linux Terminal display username

如何更改 Linux Terminal 显示的用户名

(base) ➜  ~ whoami
xgqfrms-mbp
(base) ➜  ~ pwd
/Users/xgqfrms-mbp
(base) ➜  ~ 

terminal change username base bug ❌

after install Anaconda navigator, terminal change username bug

(conda)

Anaconda 水蟒

conda base bug ❌

solution ✅

https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#change-command-prompt-changeps1

vscode

$ code .zshrc


# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/xgqfrms-mbp/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/xgqfrms-mbp/opt/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/xgqfrms-mbp/opt/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/xgqfrms-mbp/opt/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<


(base) ➜  ~ code .zshrc 
(base) ➜  ~ conda deactivate
(/Users/xgqfrms-mbp/anaconda3) ➜  ~ code ~/.condarc

ssl_verify: true
channels:
  - defaults

ssl_verify: true
channels:
  - defaults
changeps1: False

OK ✅

demos

Raspberry Pi 4B

$ hostname -I
192.168.18.168 fd80:eae6:1258:0:3e37:1ab6:357c:1dba

$PS1

$ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w \$\[\033[00m\]

https://www.cnblogs.com/xgqfrms/p/17267344.html

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

~/.bashrc & ~/.zshrc

问题的源头,那就是aconda自动加入了命令到 .bashrc中, 在我们打开终端的时候自动 执行了 conda activate base 命令

https://askubuntu.com/questions/1026383/why-does-base-appear-in-front-of-my-terminal-prompt

https://apple.stackexchange.com/questions/371727/how-do-i-remove-the-source-base-from-my-terminal

https://stackoverflow.com/questions/55171696/how-to-remove-base-from-terminal-prompt-after-updating-conda

Linux $PS1

PS1 (Prompt String 1)

$ echo $PS1

https://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html

https://www.linuxnix.com/linuxunix-shell-ps1-prompt-explained-in-detail/

https://linuxconfig.org/bash-prompt-basics

PS1

https://zhuanlan.zhihu.com/p/140892886

set & unset

       set [ {+|-}options | {+|-}o [ option_name ] ] ... [ {+|-}A [ name ] ]
           [ arg ... ]
              Set the options for the shell and/or set the positional
              parameters, or declare and set an array.  If the -s option is
              given, it causes the specified arguments to be sorted before
              assigning them to the positional parameters (or to the array
              name if -A is used).  With +s sort arguments in descending
              order.  For the meaning of the other flags, see zshoptions(1).
              Flags may be specified by name using the -o option. If no option
              name is supplied with -o, the current option states are printed:
              see the description of setopt below for more information on the
              format.  With +o they are printed in a form that can be used as
              input to the shell.

              If the -A flag is specified, name is set to an array containing
              the given args; if no name is specified, all arrays are printed
              together with their values.

              If +A is used and name is an array, the given arguments will
              replace the initial elements of that array; if no name is
              specified, all arrays are printed without their values.

              The behaviour of arguments after -A name or +A name depends on
              whether the option KSH_ARRAYS is set.  If it is not set, all
              arguments following name are treated as values for the array,
              regardless of their form.  If the option is set, normal option
              processing continues at that point; only regular arguments are
              treated as values for the array.  This means that

                     set -A array -x -- foo

              sets array to `-x -- foo' if KSH_ARRAYS is not set, but sets the
              array to foo and turns on the option `-x' if it is set.

              If the -A flag is not present, but there are arguments beyond
              the options, the positional parameters are set.  If the option
              list (if any) is terminated by `--', and there are no further
              arguments, the positional parameters will be unset.

              If no arguments and no `--' are given, then the names and values
              of all parameters are printed on the standard output.  If the
              only argument is `+', the names of all parameters are printed.

              For historical reasons, `set -' is treated as `set +xv' and `set
              - args' as `set +xv -- args' when in any other emulation mode
              than zsh's native mode.


$ man zshbuiltins
# $ man zshbuiltins | grep set

# Unknown locale, assuming C
$ locale
LANG=""
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

# fix
$ export LANG="en_US.UTF-8"
$ locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=

https://stackoverflow.com/questions/77058657/why-both-the-set-and-unset-commands-dont-work-as-expected-in-my-macos-terminal#comment135847407_77058657

https://pubs.opengroup.org/onlinepubs/007904875/utilities/set.html

       unset [ -fmv ] name ...
              Each named parameter is unset.  Local parameters remain local
              even if unset; they appear unset within scope, but the previous
              value will still reappear when the scope ends.

              Individual elements of associative array parameters may be unset
              by using subscript syntax on name, which should be quoted (or
              the entire command prefixed with noglob) to protect the
              subscript from filename generation.

              If the -m flag is specified the arguments are taken as patterns
              (should be quoted) and all parameters with matching names are
              unset.  Note that this cannot be used when unsetting associative
              array elements, as the subscript will be treated as part of the
              pattern.

              The -v flag specifies that name refers to parameters. This is
              the default behaviour.

              unset -f is equivalent to unfunction.

https://pubs.opengroup.org/onlinepubs/007904875/utilities/unset.html

refs

https://www.jianshu.com/p/6cdc9713c4ed

https://linux.cn/article-9192-1.html

https://www.cnblogs.com/tdcqma/p/6714492.html

https://www.jianshu.com/p/6ef9e8a4d789

https://cloud.tencent.com/developer/ask/50791

https://www.cnblogs.com/devilmaycry812839668/p/10349602.html



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2020-08-05 13:04  xgqfrms  阅读(339)  评论(4编辑  收藏  举报