Created
December 21, 2024 09:49
-
-
Save withakay/ae1a760271091ff0a9a017ac42f10fd4 to your computer and use it in GitHub Desktop.
dircolors generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# A 'theme' generator for dircolors, tested on macOS Sequoia 15.1 and bash 5, should work elsewhere by YMMV | |
# On macOS you will need gdirecolors and a modern bash, installed via brew | |
# | |
# brew install coreutils | |
# brew install bash | |
# | |
# Adjust the colors below and run ./dircolors.sh > ~/.dircolors to create a dircolors 'theme' | |
# in your .zshrc (probably .bashrc too) you can eval this file (also export CLICOLOR=1) | |
# | |
# export CLICOLOR=1 | |
# eval $(gdircolors ~/.dircolors) | |
# | |
# I also aliased ls to gls (from coreutils): | |
# | |
# alias ls="gls -G --color=auto" | |
# alias ll="gls -laG --color=auto" | |
# | |
# Color definitions for different file type groups optimized for dark backgrounds | |
# Format: 00;38;5;COLOR_NUMBER where COLOR_NUMBER is 0-255 | |
# | |
# There is a list of all the xterm-256 colors here: | |
# https://www.ditig.com/publications/256-colors-cheat-sheet | |
# Core system colors | |
DIR_COLOR="75" # Bright blue for directories | |
LINK_COLOR="120" # Bright green for symlinks | |
SPECIAL_FILE_COLOR="214" # Bright orange for special files | |
EXEC_COLOR="84" # Light green for executables | |
# Development and content colors | |
CODE_COLOR="213" # Bright magenta for source code | |
BUILD_COLOR="180" # Light brown for build files | |
CONFIG_COLOR="147" # Light purple for config files | |
DOC_COLOR="153" # Cyan-ish for documentation | |
TEST_COLOR="217" # Light pink for test files | |
DATA_COLOR="195" # Light blue for data files | |
WEB_COLOR="219" # Pink-ish for web files | |
# Media colors | |
ARCHIVE_COLOR="143" # Olive for archives | |
IMAGE_COLOR="157" # Light sea green for images | |
AUDIO_COLOR="183" # Light purple for audio | |
VIDEO_COLOR="156" # Another sea green variant for video | |
# System files | |
TEMP_COLOR="242" # Dark gray for temporary files | |
LOG_COLOR="245" # Light gray for logs | |
CACHE_COLOR="240" # Darker gray for cache | |
# Start generating the dircolors file | |
cat << EOF | |
# Generated dircolors configuration | |
# Optimized for dark terminal backgrounds | |
# Term Section | |
TERM Eterm | |
TERM alacritty | |
TERM ansi | |
TERM color-xterm | |
TERM console | |
TERM cygwin | |
TERM gnome | |
TERM gnome-256color | |
TERM konsole | |
TERM linux | |
TERM putty | |
TERM rxvt | |
TERM screen | |
TERM screen-256color | |
TERM tmux-256color | |
TERM xterm | |
TERM xterm-256color | |
# Core file types | |
NORMAL 00 | |
FILE 00 | |
RESET 0 | |
DIR 00;38;5;${DIR_COLOR} | |
LINK 00;38;5;${LINK_COLOR} | |
MULTIHARDLINK 00 | |
FIFO 48;5;230;38;5;${SPECIAL_FILE_COLOR};01 | |
SOCK 48;5;230;38;5;${SPECIAL_FILE_COLOR};01 | |
DOOR 48;5;230;38;5;${SPECIAL_FILE_COLOR};01 | |
BLK 48;5;230;38;5;244;01 | |
CHR 48;5;230;38;5;244;01 | |
ORPHAN 48;5;235;38;5;160 | |
SETUID 48;5;160;38;5;230 | |
SETGID 48;5;136;38;5;230 | |
CAPABILITY 30;41 | |
STICKY_OTHER_WRITABLE 48;5;64;38;5;230 | |
OTHER_WRITABLE 48;5;235;38;5;33 | |
STICKY 48;5;33;38;5;230 | |
EXEC 00;38;5;${EXEC_COLOR} | |
# Source code files | |
EOF | |
# Programming languages | |
code_files=( | |
# Systems programming | |
"c" "h" "cpp" "hpp" "cc" "cxx" "rs" "go" "zig" "nim" "d" | |
# Web development | |
"js" "mjs" "cjs" "ts" "jsx" "tsx" "vue" "svelte" | |
# Scripting languages | |
"py" "rb" "php" "lua" "tcl" "pl" "pm" "t" "sh" "bash" "zsh" "fish" | |
# JVM languages | |
"java" "scala" "kt" "groovy" "clj" "gradle" | |
# .NET languages | |
"cs" "fs" "vb" | |
# Systems configuration | |
"nix" "dhall" | |
) | |
for ext in "${code_files[@]}"; do | |
echo ".${ext} 00;38;5;${CODE_COLOR}" | |
done | |
# Build and compilation files | |
echo -e "\n# Build and compilation files" | |
build_files=( | |
"Makefile" "makefile" "Rakefile" "Dockerfile" "dockerfile" | |
"CMakeLists.txt" "package.json" "composer.json" "Cargo.toml" "Cargo.lock" | |
"pom.xml" "build.gradle" "build.sbt" "WORKSPACE" ".bazelrc" | |
) | |
for file in "${build_files[@]}"; do | |
echo ".${file} 00;38;5;${BUILD_COLOR}" | |
done | |
# Configuration files | |
echo -e "\n# Configuration files" | |
config_files=( | |
# General config | |
"conf" "config" "cfg" "ini" "properties" | |
# YAML and friends | |
"yml" "yaml" "toml" "json" "jsonc" "json5" "jsonnet" | |
# Environment and runtime | |
"env" "envrc" "direnv" "pythonversion" | |
# Git | |
"gitignore" "gitattributes" "gitmodules" "gitkeep" | |
# Editor and IDE | |
"editorconfig" "sublime-project" "sublime-workspace" | |
"code-workspace" "iml" | |
# Linters and formatters | |
"eslintrc" "prettierrc" "stylelintrc" "lint" | |
# Shell | |
"profile" "bashrc" "zshrc" "zshenv" "zprofile" "bash_profile" | |
) | |
for file in "${config_files[@]}"; do | |
echo ".${file} 00;38;5;${CONFIG_COLOR}" | |
done | |
# Documentation files | |
echo -e "\n# Documentation files" | |
doc_files=( | |
# Markdown and text | |
"md" "mkd" "markdown" "txt" "text" "README" "LICENSE" | |
"doc" "docx" "odt" "pdf" "epub" "rtf" | |
# Manual pages | |
"1" "2" "3" "4" "5" "6" "7" "8" "9" "man" "mdoc" | |
# API documentation | |
"raml" "swagger" "openapi" "apib" | |
# TeX and friends | |
"tex" "texi" "latex" "sty" "cls" "bib" | |
) | |
for file in "${doc_files[@]}"; do | |
echo ".${file} 00;38;5;${DOC_COLOR}" | |
done | |
# Test files | |
echo -e "\n# Test files" | |
test_files=( | |
"spec" "test" "t" | |
) | |
for file in "${test_files[@]}"; do | |
echo ".${file} 00;38;5;${TEST_COLOR}" | |
done | |
# Data files | |
echo -e "\n# Data files" | |
data_files=( | |
# Structured data | |
"csv" "tsv" "psv" "xml" "xsl" "xslt" "xsd" | |
"rdf" "owl" "ttl" "n3" "nt" "jsonld" | |
# Database | |
"sql" "sqlite" "db" "mdb" "pdb" | |
# Excel and spreadsheets | |
"xls" "xlsx" "ods" | |
) | |
for file in "${data_files[@]}"; do | |
echo ".${file} 00;38;5;${DATA_COLOR}" | |
done | |
# Web files | |
echo -e "\n# Web files" | |
web_files=( | |
# Markup and styling | |
"html" "htm" "xhtml" "css" "sass" "scss" "less" "styl" | |
# Templates | |
"ejs" "hbs" "mustache" "twig" "liquid" "erb" "haml" "slim" | |
"jade" "pug" "jinja" "jinja2" | |
# Web assets | |
"woff" "woff2" "ttf" "eot" "otf" | |
) | |
for file in "${web_files[@]}"; do | |
echo ".${file} 00;38;5;${WEB_COLOR}" | |
done | |
# Archives and compressed files | |
echo -e "\n# Archives" | |
archive_types=( | |
# Common archives | |
"tar" "tgz" "arj" "taz" "lzh" "lzma" "tlz" "txz" "zip" "z" "Z" "dz" | |
"gz" "lz" "xz" "bz2" "bz" "tbz" "tbz2" "tz" "deb" "rpm" "jar" "war" | |
"ear" "sar" "rar" "alz" "ace" "zoo" "cpio" "7z" "rz" "cab" "wim" | |
# Disk images | |
"iso" "img" "dmg" "vhd" "vhdx" "vmdk" | |
# Package manager archives | |
"apk" "gem" "egg" "whl" "pkg" "msi" | |
) | |
for ext in "${archive_types[@]}"; do | |
echo ".${ext} 00;38;5;${ARCHIVE_COLOR}" | |
done | |
# Image files | |
echo -e "\n# Image formats" | |
image_types=( | |
# Common formats | |
"jpg" "jpeg" "gif" "bmp" "png" "webp" "avif" "heic" | |
# Vector and design | |
"svg" "svgz" "eps" "ai" "psd" "psb" "xcf" "sketch" "fig" | |
# Raw formats | |
"raw" "cr2" "nef" "nrw" "arw" "orf" "rw2" "dng" | |
# Other | |
"tga" "tiff" "ico" "icns" "bpg" "mng" "pcx" "xpm" "ppm" "pbm" "pgm" | |
) | |
for ext in "${image_types[@]}"; do | |
echo ".${ext} 00;38;5;${IMAGE_COLOR}" | |
echo ".${ext^^} 00;38;5;${IMAGE_COLOR}" # Add uppercase variants | |
done | |
# Audio formats | |
echo -e "\n# Audio formats" | |
audio_types=( | |
# Common formats | |
"mp3" "m4a" "aac" "ogg" "oga" "flac" "wav" "wma" "aiff" "opus" | |
# Tracker and MIDI | |
"mod" "it" "s3m" "xm" "mid" "midi" | |
# Playlist formats | |
"m3u" "m3u8" "pls" "cue" | |
# Other | |
"au" "ra" "rm" "mka" "wv" "ape" "spx" "sid" | |
) | |
for ext in "${audio_types[@]}"; do | |
echo ".${ext} 00;38;5;${AUDIO_COLOR}" | |
done | |
# Video formats | |
echo -e "\n# Video formats" | |
video_types=( | |
# Common formats | |
"mp4" "m4v" "mkv" "webm" "mov" "avi" "wmv" "mpg" "mpeg" "m2v" | |
"flv" "vob" "ogv" "gifv" "rmvb" "m2ts" "mts" "ts" "3gp" | |
# Professional formats | |
"mxf" "r3d" "braw" "prproj" "aep" | |
) | |
for ext in "${video_types[@]}"; do | |
echo ".${ext} 00;38;5;${VIDEO_COLOR}" | |
echo ".${ext^^} 00;38;5;${VIDEO_COLOR}" # Add uppercase variants | |
done | |
# Temporary and unimportant files | |
echo -e "\n# Temporary files" | |
temp_files=( | |
# Temporary and backup | |
"tmp" "temp" "bak" "old" "orig" "swp" "swo" | |
"save" | |
# Build artifacts | |
"o" "lo" "mo" "pyc" "class" "dll" "so" "dylib" | |
"exe" "out" "app" "beam" "hi" | |
) | |
for file in "${temp_files[@]}"; do | |
echo ".${file} 00;38;5;${TEMP_COLOR}" | |
done | |
# Log files | |
echo -e "\n# Log files" | |
log_files=( | |
"log" "logs" "err" "error" "debug" | |
# LaTeX auxiliary files | |
"aux" "lof" "lot" "fls" "out" "toc" "fmt" "fot" "cb" | |
"cb2" "lb" "bbl" "bcf" "blg" | |
) | |
for file in "${log_files[@]}"; do | |
echo ".${file} 00;38;5;${LOG_COLOR}" | |
done | |
# Cache files | |
echo -e "\n# Cache files" | |
cache_files=( | |
"cache" "zwc" | |
) | |
for file in "${cache_files[@]}"; do | |
echo ".${file} 00;38;5;${CACHE_COLOR}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment