Skip to content

Instantly share code, notes, and snippets.

@fanlushuai
Last active January 17, 2021 21:53
Show Gist options
  • Save fanlushuai/80bb143cb698b84e0f2e145d8ec5f85c to your computer and use it in GitHub Desktop.
Save fanlushuai/80bb143cb698b84e0f2e145d8ec5f85c to your computer and use it in GitHub Desktop.
wsl2默认的dircolor非常亮眼,难受。可以修改一下。
#!/usr/bin/bash
set -euxo pipefail
cd ~/
dircolors_file='.dircolors'
dircolors -p > ${dircolors_file}
sed -i \
-e "s/^STICKY_OTHER_WRITABLE.*$/#&\\nSTICKY_OTHER_WRITABLE 30;46/" \
-e "s/^OTHER_WRITABLE.*$/#&\\nOTHER_WRITABLE 30;46/" \
${dircolors_file}
@fanlushuai
Copy link
Author

脑子坏了。直接一条命令就行了:

 dircolors -p > ~/.dircolors && sed -i -e "s/^STICKY_OTHER_WRITABLE.*$/#&\\nSTICKY_OTHER_WRITABLE 30;46/" -e "s/^OTHER_WRITABLE.*$/#&\\nOTHER_WRITABLE 30;46/" ~/.dircolors

@fanlushuai
Copy link
Author

值得一提的是,.dircolors 是给shell读取的。
如果使用bash或者zsh。一定检查一下,rc文件是否有读取行为。要不然,这种是不能生效的。
如果未添加,加上如下代码:

 if [ -x /usr/bin/dircolors ]; then
     test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
     alias ls='ls --color=auto'
     #alias dir='dir --color=auto'
     #alias vdir='vdir --color=auto'

     alias grep='grep --color=auto'
     alias fgrep='fgrep --color=auto'
     alias egrep='egrep --color=auto'
 fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment