2013-03-17 63 views

回答

1

我發現你必須爲每個命令實際設置--color標誌。我爲ls添加了這個.bash-rc來顯示着色(--color = auto),顯示隱藏文件(-a),顯示列表(-l),顯示可讀大小(-h)和按擴展名排序使目錄顯示第一(X):

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

如果有任何的方式來打開全球着色所有的命令,而不必單獨創建別名爲每個命令,讓我知道。

+1

的'-X'標誌不會首先實際上排序的所有目錄。 – 2013-07-06 21:00:09

+0

@Cupcake是對的。我使用Git 1.9.4和Git Bash,並且標記'-X'首先排序目錄,但忽略'.git'文件夾。 – thiagobraga 2015-04-02 00:59:03

0

這是我發現的作品。假設你已經定義了你的顏色。

# 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 
+0

我試過你發佈的.bashrc的完整代碼 - 它爲提示着色,但不着色ls的輸出。似乎需要使用「--color = auto」爲ls製作別名。 – robertcollier4 2013-03-17 16:02:40

+0

嗯它的奇怪,因爲我有一個錯誤,當我添加「--color = auto」我的。 – 2013-03-17 17:29:27

+0

嘿居然試試這個:export CLICOLOR = 1 export LSCOLORS = gxBxhxDxfxhxhxhxhxcxcx – 2013-03-17 23:03:46

相關問題