zoukankan      html  css  js  c++  java
  • Shell命令行提示定制

    /*******************************************************************************
     *                          Shell命令行提示定制
     * 说明:
     *     Shell命令行提示太长也是一种痛苦,只显示当前目录名,或者最后两三个父目录一般
     * 足够了,没必要那么长。
     *
     *                                          2019-5-20 深圳 宝安西乡 曾剑锋
     ******************************************************************************/
    
     一、参考文档
        1. How to display directory in the prompt?
            https://unix.stackexchange.com/questions/448318/how-to-display-directory-in-the-prompt
        2. Show only current and parent directory in bash prompt
            https://unix.stackexchange.com/questions/216953/show-only-current-and-parent-directory-in-bash-prompt
        3. linux shell 字符串操作详解 (长度,读取,替换,截取,连接,对比,删除,位置 )
            https://blog.csdn.net/dongwuming/article/details/50605911
    
    二、处理方法
        1. 修改文件:~/.bashrc
        2. PROMPT_COMMAND: If set, the value is interpreted as a command to execute before the printing of each primary prompt ($PS1).
        3. PROMPT_COMMAND处理方法:
            PROMPT_COMMAND='case $PWD in
                    $HOME) HPWD="~";;
                    $HOME/*/*) HPWD="${PWD#"${PWD%/*/*}/"}";;       # %表示从后往前剔除,#表示从前往后剔除
                    $HOME/*) HPWD="~/${PWD##*/}";;
                    /*/*/*) HPWD="${PWD#"${PWD%/*/*}/"}";;
                    *) HPWD="$PWD";;
                esac'
            PS1='${debian_chroot:+($debian_chroot)}u@h:$HPWD$'
        4. 只显示当前目录:PS1='${debian_chroot:+($debian_chroot)}u@h:W$'
  • 相关阅读:
    CSS选择器
    基础DOS命令
    超链接a标签
    vscode使用技巧
    pc端页面添加meta标签:X-UA-Compatible meta标签
    提问的智慧
    Zepto核心模块源代码分析
    远程调试工具weinre使用教程
    HTML标签marquee实现滚动效果
    git 学习教程
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/10892725.html
Copyright © 2011-2022 走看看