【问题标题】:Bash Folder-File coloring in msysgit on Windows?Windows 上 msysgit 中的 Bash 文件夹文件着色?
【发布时间】:2013-03-17 15:34:10
【问题描述】:

我在 Windows 中使用 msys Git。我已经通过在 .bashrc 中设置 PS1 变量为我的提示着色。

但是 - 我也希望获得标准的 bash 着色 - 例如,当我执行“ls”时,文件与目录的颜色不同。有谁知道如何做到这一点?

【问题讨论】:

    标签: git bash msysgit


    【解决方案1】:

    我发现您必须为每个命令实际设置 --color 标志。我将此添加到 .bash-rc for ls 以:显示着色(--color=auto),显示隐藏文件(-a),显示列表(-l),显示人类可读大小(-h),并按扩展名排序以便首先显示目录(-X):

    alias ls='ls --color=auto -alhX'
    

    如果有任何方法可以为所有命令全局启用着色,而无需为每个命令单独创建别名,请告诉我。

    【讨论】:

    • -X 标志实际上不会首先对所有目录进行排序。
    • @Cupcake 是对的。我正在使用 Git 1.9.4 和 Git Bash,并且标志 -X 首先对目录进行排序,但例如忽略 .git 文件夹。
    【解决方案2】:

    这是我发现的作品。假设您定义了颜色。

     # tell ls to be colourful
        export PS1="${GREEN}\u ${YELLOW}\w ${BLUE}\W ${CYAN}\$(dev_info)${WHITE}\$ "
        export CLICOLOR=1
        export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
    

    这是我的全部代码

    export PATH=/usr/local/bin:$PATH
    export PATH=/usr/local/share/npm/bin:$PATH
    export PATH=${PATH}:/var/lib/gems/1.8/bin/
    export PATH=${PATH}:/var/lib/gems/
    
    
    export PATH=~/bin:$PATH
    export PATH=/opt/subversion/bin:$PATH
    export PATH="$PATH:/Users/bentonrr/Sites/Amex/trunk/www/lib/Cake/Console"
    export NODE_PATH=/usr/local/lib/node_modules:/usr/local/lib/node
    
    
    
    alias ls="ls -H"
    alias ll="ls -lh"
    alias l="ll"
    alias lll="ll"
    alias la="ll -a"
    alias lla="ll -a"
    alias lsa="ls -a"
    alias lt='ll -t'
    alias lrt='ll -rt'
    alias lart="ll -lart"
    alias lsd="ls -d */"
    alias lld="ll -d */"
    
    alias git+st="git status"
    
    
    function detect_git_dirty {
      local git_status=$(git status 2>&1 | tail -n1)
      [[ $git_status != "fatal: Not a git repository (or any of the parent
      directories): .git" ]] && [[ $git_status != "nothing to commit (working
      directory clean)" ]] && echo "*"
    }
    
    function detect_git_branch {
      git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
    }
    function dev_info {
      echo "[$(detect_git_branch)$(detect_git_dirty)]"
    }
    
    # quick commands
    alias tails='tail -f /Applications/MAMP/logs/apache_error.log'
    alias ebash='vim ~/.bash_profile'
    alias rebash='. ~/.bash_profile'
    alias ehosts='sudo mvim /etc/hosts'
    alias tmamp='tail -f /Applications/MAMP/logs/*';
    alias tache='tail -f /var/log/apache2/*';
    alias vimrc='vim ~/.vimrc'
    alias gvimrc='vim ~/.gvimrc'
    alias rmlogs="sudo rm -f /private/var/log/asl/*.asl"
    alias ephp="sudo vim /etc/php.ini"
    alias apr="sudo apachectl restart"
    alias iphone="open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app"
    
    
     BLACK="\[\033[0;30m\]"
     RED="\[\033[0;31m\]"
     GREEN="\[\033[1;32m\]"
     YELLOW="\[\033[1;33m\]"
     BLUE="\[\033[0;34m\]"
     PURPLE="\[\033[0;35m\]"
     CYAN="\[\033[0;36m\]"
     WHITE="\[\033[0;37m\]"
    
    export PS1="${GREEN}\u ${YELLOW}\w ${BLUE}\W ${CYAN}\$(dev_info)${WHITE}\$ "
    # tell ls to be colourful
    export CLICOLOR=1
    export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
    
    # Set git autocompletion and PS1 integration
    if [ -f /usr/local/git/contrib/completion/git-completion.bash ]; then
      . /usr/local/git/contrib/completion/git-completion.bash
    fi
    if [ -f /opt/local/share/doc/git-core/contrib/completion/git-prompt.sh ]; then
        . /opt/local/share/doc/git-core/contrib/completion/git-prompt.sh
    fi
    GIT_PS1_SHOWDIRTYSTATE=true
    
    if [ -f /opt/local/etc/bash_completion ]; then
        . /opt/local/etc/bash_completion
    fi
    

    【讨论】:

    • 我尝试了您发布的 .bashrc 的完整代码 - 它为提示着色但不着色 ls 的输出。似乎有必要用“--color = auto”为ls创建别名。
    • hmmm 这很奇怪,因为我在添加“--color=auto”时出错了。
    • 嘿,试试这个:export CLICOLOR=1 export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
    • 仅供参考,这些都不适合我。唯一有效的是使用“--color = auto”将别名添加到ls,如我上面的第二篇文章所示。谢谢。
    • @robertcollier4 你确定你正在编辑正确的文件,例如 .bash_profile vs .bashrc?
    猜你喜欢
    • 2011-06-11
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    • 2021-04-05
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多