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$'
  • 相关阅读:
    C库函数中字符串处理函数集合(转)
    浅谈C++底层机制
    vc2008快捷键
    Delphi格式输出的用法
    Devenv 命令行开关
    DX皮肤控制
    C#格式化
    linq查询DataView
    WCF中的session用法
    VS2012clickonce发布问题
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/10892725.html
Copyright © 2011-2022 走看看