lnlidawei

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

[shell]  zsh -- PROMPT

 

 

 

 

一、PS1  核心配置(zsh)

# Set prompts
#[[ "$PROMPT" = "%m%# " ]] && PROMPT='[%n@%m]%~%# '    # default prompt
#[[ "$PROMPT" = "%m%# " ]] && PROMPT='[%n@%m:%~]# '    # change time 1 prompt


[[ "$PROMPT" = "%m%# " ]] && PROMPT='[%n@%m:%1d]# '    # using prompt


#RPROMPT=' %~'     # prompt for right side of screen

 

 

 

 

二、PS1  配置(zsh)

                                                                                                                                               
[root@rocky:tmp]# zsh  --version
zsh 5.8 (x86_64-redhat-linux-gnu)
[root@rocky:tmp]# 
[root@rocky:tmp]# 
[root@rocky:tmp]# cat  /etc/zshrc 
#
# /etc/zshrc is sourced in interactive shells.  It
# should contain commands to set up aliases, functions,
# options, key bindings, etc.
#

## shell functions
#setenv() { export $1=$2 }  # csh compatibility

# Set prompts
#[[ "$PROMPT" = "%m%# " ]] && PROMPT='[%n@%m]%~%# '    # default prompt
#[[ "$PROMPT" = "%m%# " ]] && PROMPT='[%n@%m:%~]# '    # change time 1 prompt
[[ "$PROMPT" = "%m%# " ]] && PROMPT='[%n@%m:%1d]# '    # using prompt
#RPROMPT=' %~'     # prompt for right side of screen

# bindkey -v             # vi key bindings
# bindkey -e             # emacs key bindings
bindkey ' ' magic-space  # also do history expansion on space

# Provide pathmunge for /etc/profile.d scripts
pathmunge()
{
    if ! echo $PATH | /bin/grep -qE "(^|:)$1($|:)" ; then
        if [ "$2" = "after" ] ; then
            PATH=$PATH:$1
        else
            PATH=$1:$PATH
        fi
    fi
}

_src_etc_profile_d()
{
    #  Make the *.sh things happier, and have possible ~/.zshenv options like
    # NOMATCH ignored.
    emulate -L ksh


    # from bashrc, with zsh fixes
    if [[ ! -o login ]]; then # We're not a login shell
        for i in /etc/profile.d/*.sh; do
            if [ -r "$i" ]; then
                . $i
            fi
        done
        unset i
    fi
}
_src_etc_profile_d

unset -f pathmunge _src_etc_profile_d

[root@rocky:tmp]# 
[root@rocky:tmp]# 

 

 

 

 

三、参考资料:

 

  1、  zsh 自定义命令提示符(PS1/ prompt)  --  https://blog.csdn.net/u014218108/article/details/51195582

 

  2、  13 Prompt Expansion  --  https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html

 

posted on 2024-05-04 00:46  lnlidawei  阅读(52)  评论(0编辑  收藏  举报