我刚刚转到 zsh
从 bash
在我的MacOS 10.14.6上,我想知道如何让文件夹的内容输出(例如,当键入 ls
命令)以不同的颜色
例如,如果我输入
[mymac@Documents]$ls
Folder1
File1.txt
@stuff
我想让3个输出项目有3种不同的颜色。我怎样才能编辑 .zshrc
文件相应的?
编辑
我尝试了下面的命令,得到了相应的错误输出。
$ ls --color=auto
ls: illegal option -- -
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
同样的情况发生在 $ alias ls='ls --color=always'
用下面的命令就可以了,但是文件夹的颜色是深蓝色的,因此很难看。
alias ls='ls -G'
我也看到了那2个其他的链接,但是没有用。所以,问题是...
有办法手动定义颜色吗?
EDIT 2我找到了这段对我有用的代码(来自于 那里)
COLOR_RED="\033[0;31m"
COLOR_YELLOW="\033[0;33m"
COLOR_GREEN="\033[0;32m"
COLOR_OCHRE="\033[38;5;95m"
COLOR_BLUE="\033[0;34m"
COLOR_WHITE="\033[0;37m"
COLOR_RESET="\033[0m"
#git_color
function git_color {
local git_status="$(git status 2> /dev/null)"
if [[ ! $git_status =~ "working directory clean" ]]; then
echo -e $COLOR_RED
elif [[ $git_status =~ "Your branch is ahead of" ]]; then
echo -e $COLOR_YELLOW
elif [[ $git_status =~ "nothing to commit" ]]; then
echo -e $COLOR_GREEN
else
echo -e $COLOR_OCHRE
fi
}
#git_branch
function git_branch {
local git_status="$(git status 2> /dev/null)"
local on_branch="On branch ([^${IFS}]*)"
local on_commit="HEAD detached at ([^${IFS}]*)"
if [[ $git_status =~ $on_branch ]]; then
local branch=${BASH_REMATCH[1]}
echo "($branch)"
elif [[ $git_status =~ $on_commit ]]; then
local commit=${BASH_REMATCH[1]}
echo "($commit)"
fi
}
#PS1='\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]'
#PS1+="\[\$(git_color)\]" # colors git status
#PS1+="\$(git_branch)" # prints current branch
#PS1+="\[$COLOR_BLUE\]\[$COLOR_RESET\]\$ "
#export PS1
export LC_ALL=en_US.UTF-8
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx