2025-05-05 16:06:10 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2025-05-05 23:54:03 +03:00
|
|
|
parse_git_branch() {
|
|
|
|
|
git rev-parse --abbrev-ref HEAD 2>/dev/null | sed 's/^/ /;s/$//'
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-05 16:06:10 +03:00
|
|
|
#config_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
2025-05-05 23:16:08 +03:00
|
|
|
config_dir="$HOME/.config/prompt-themes"
|
2025-05-05 16:06:10 +03:00
|
|
|
config_file="$config_dir/config.yaml"
|
|
|
|
|
shell_colors="$config_dir/dircolors"
|
|
|
|
|
|
|
|
|
|
# Accept theme as CLI arg, fallback to config
|
|
|
|
|
theme="$1"
|
|
|
|
|
|
|
|
|
|
# if no parameter given, look for default in config.yaml
|
|
|
|
|
# use 'yq' to parse the config.yaml file
|
|
|
|
|
|
|
|
|
|
# Ensure yq is installed
|
|
|
|
|
if ! command -v yq >/dev/null 2>&1; then
|
|
|
|
|
echo "⚠️ Warning: 'yq' is not installed. Cannot parse $config_file."
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# If no theme given, attempt to get it from config
|
|
|
|
|
if [[ -z "$theme" && -f "$config_file" ]]; then
|
2025-05-05 16:36:51 +03:00
|
|
|
theme=$(yq -r '.default' "$config_file")
|
2025-05-05 16:06:10 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Fail silently if no theme could be determined
|
|
|
|
|
if [[ -z "$theme" ]]; then
|
|
|
|
|
echo "⚠️ Warning: No theme specified and no default set in config file."
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Determine which dircolors command to use
|
|
|
|
|
# give a warning and fail silently if not found
|
|
|
|
|
if [[ "$(uname)" == "Darwin" ]]; then
|
|
|
|
|
if command -v gdircolors >/dev/null 2>&1; then
|
|
|
|
|
dircolors_cmd="gdircolors"
|
|
|
|
|
else
|
|
|
|
|
echo "❌ Error: gdircolors not found. Please install via 'brew install coreutils'."
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
if command -v dircolors >/dev/null 2>&1; then
|
|
|
|
|
dircolors_cmd="dircolors"
|
|
|
|
|
else
|
|
|
|
|
echo "❌ Error: dircolors not found. Please install coreutils."
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2025-05-05 16:53:38 +03:00
|
|
|
# debugging
|
|
|
|
|
# echo "shell_colors: $shell_colors"
|
|
|
|
|
# echo "theme: $theme"
|
|
|
|
|
# echo "dir_colors_cmd: $dircolors_cmd"
|
2025-05-05 16:36:51 +03:00
|
|
|
|
2025-05-05 16:06:10 +03:00
|
|
|
# Apply dircolors theme or fallback
|
|
|
|
|
if [[ -r "$shell_colors/$theme" ]]; then
|
|
|
|
|
eval "$($dircolors_cmd -b "$shell_colors/$theme")"
|
|
|
|
|
elif [[ -r "$HOME/.dircolors" ]]; then
|
|
|
|
|
eval "$($dircolors_cmd -b "$HOME/.dircolors")"
|
|
|
|
|
else
|
|
|
|
|
echo "⚠️ Warning: No readable dircolors file found for '$theme' or ~/.dircolors. Using default ls colors."
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# get prompt from config.yaml if available
|
|
|
|
|
if [[ -f "$config_file" ]]; then
|
2025-05-05 16:36:51 +03:00
|
|
|
prompt=$(yq -r ".prompts.$theme" "$config_file")
|
2025-05-05 16:06:10 +03:00
|
|
|
else
|
|
|
|
|
prompt=""
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# apply prompt or fallback
|
|
|
|
|
if [[ -n "$prompt" && "$prompt" != "null" ]]; then
|
|
|
|
|
export PS1="$prompt"
|
|
|
|
|
else
|
|
|
|
|
echo "⚠️ Warning: No prompt found for theme '$theme'. Using fallback."
|
|
|
|
|
export PS1='\[\033[01;34m\]\u@\h \[\033[01;32m\]\w\[\033[00m\] \$ '
|
|
|
|
|
fi
|
|
|
|
|
|
2025-05-06 00:30:25 +03:00
|
|
|
# ensure ls uses color
|
2025-05-06 00:36:28 +03:00
|
|
|
echo "[prompt-themes] ⚙️ Applied: alias ls='ls --color=auto'"
|
2025-05-06 00:30:25 +03:00
|
|
|
alias ls='ls --color=auto'
|
2025-05-05 23:54:03 +03:00
|
|
|
|
|
|
|
|
|