#!/bin/bash

# File: install-ls-colors.sh
# Project: macos-ls-colors
# File Created: 2026-01-13 10:30:00 am
# Author: wcs (cs@jsait.com)
# -----
# Last Modified: 2026-02-03 10:00:00 am
# Modified By: wcs (cs@jsait.com)
# -----
# Copyright (c) 2026 JS@

# 检查是否安装了 Homebrew
if ! command -v brew &> /dev/null; then
    echo "安装 Homebrew..."
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi

# 安装 GNU coreutils
echo "安装 GNU coreutils..."
brew install coreutils

# 写入配置到 ~/.zshrc
echo "配置 LS_COLORS..."

cat >> ~/.zshrc << 'EOF'

# ========== LS 颜色配置 ==========
# 启用颜色
export CLICOLOR=1
export LSCOLORS="gxfxcxdxbxegedabagacad"

# 别名
alias ls="gls --color=auto --group-directories-first"
alias ll="gls -lh --color=auto --group-directories-first"
alias la="gls -lha --color=auto --group-directories-first"
alias l="gls -CF --color=auto --group-directories-first"

# GNU ls 颜色配置
export LS_COLORS="di=1;34:ln=1;36:so=1;31:pi=1;33:ex=1;32:bd=1;33;41:cd=1;33;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:*.tar=31:*.tgz=31:*.arc=31:*.arj=31:*.taz=31:*.lha=31:*.lz4=31:*.lzh=31:*.lzma=31:*.tlz=31:*.txz=31:*.tzo=31:*.t7z=31:*.zip=31:*.z=31:*.dz=31:*.gz=31:*.lrz=31:*.lz=31:*.lzo=31:*.xz=31:*.zst=31:*.tzst=31:*.bz2=31:*.bz=31:*.tbz=31:*.tbz2=31:*.tz=31:*.deb=31:*.rpm=31:*.jar=31:*.war=31:*.ear=31:*.sar=31:*.rar=31:*.alz=31:*.ace=31:*.zoo=31:*.cpio=31:*.7z=31:*.rz=31:*.cab=31:*.wim=31:*.swm=31:*.dwm=31:*.esd=31:*.jpg=35:*.jpeg=35:*.mjpg=35:*.mjpeg=35:*.gif=35:*.bmp=35:*.pbm=35:*.pgm=35:*.ppm=35:*.tga=35:*.xbm=35:*.xpm=35:*.tif=35:*.tiff=35:*.png=35:*.svg=35:*.svgz=35:*.mng=35:*.pcx=35:*.mov=35:*.mpg=35:*.mpeg=35:*.m2v=35:*.mkv=35:*.webm=35:*.ogm=35:*.mp4=35:*.m4v=35:*.mp4v=35:*.vob=35:*.qt=35:*.nuv=35:*.wmv=35:*.asf=35:*.rm=35:*.rmvb=35:*.flc=35:*.avi=35:*.fli=35:*.flv=35:*.gl=35:*.dl=35:*.xcf=35:*.xwd=35:*.yuv=35:*.cgm=35:*.emf=35:*.ogv=35:*.ogx=35:*.aac=36:*.au=36:*.flac=36:*.m4a=36:*.mid=36:*.midi=36:*.mka=36:*.mp3=36:*.mpc=36:*.ogg=36:*.ra=36:*.wav=36:*.oga=36:*.opus=36:*.spx=36:*.xspf=36:*.pdf=33:*.doc=33:*.docx=33:*.odt=33:*.rtf=33:*.txt=37:*.md=37:*.org=37:*.py=32:*.sh=32:*.pl=32:*.rb=32:*.js=32:*.ts=32:*.html=32:*.css=32:*.scss=32:*.sass=32:*.json=32:*.yml=32:*.yaml=32:*.xml=32:*.java=32:*.c=32:*.cpp=32:*.h=32:*.hpp=32:*.go=32:*.rs=32:*.swift=32:*.kt=32:*.kts=32:*.sql=32:*.php=32"
EOF

echo "配置完成！请重启终端或运行: source ~/.zshrc"
