mirror of
https://github.com/foo-dogsquared/dotfiles.git
synced 2025-01-31 04:57:57 +00:00
89 lines
2.6 KiB
Bash
89 lines
2.6 KiB
Bash
#!/usr/bin/env sh
|
|
|
|
# Create a theme with wal and copy the theme JSON in the appropriate location.
|
|
|
|
# Dependencies:
|
|
# * GNU coreutils 8.31
|
|
# * wal 3.3.0
|
|
|
|
function extract_path_without_ext() {
|
|
local path=$1
|
|
|
|
local filename=$(basename -- "$path")
|
|
|
|
# Return the filename without the file extension.
|
|
# For more information, you can look up the parameter expansion in
|
|
# https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html.
|
|
# Even if the filename has no extension, it will print the whole filename.
|
|
printf "${filename%.*}"
|
|
}
|
|
|
|
# Constant settings
|
|
LIGHT_MODE_SUFFIX='__light'
|
|
XDG_CACHE_HOME=${XDG_CACHE_HOME:-"$HOME/.cache"}
|
|
CACHE_DIR=${PYWAL_CACHE_DIR:-"$XDG_CACHE_HOME/wal"}
|
|
|
|
help_section="Create a theme with wal and copy the theme JSON in the appropriate location.
|
|
|
|
Usage: $0 IMAGE_PATH [-o/--output OUTPUT_DIR] [--light-mode]
|
|
|
|
Options:
|
|
* -o, --output <OUTPUT_DIR> - The location of the wal config folder.
|
|
The default value is '$HOME/.config/wal'.
|
|
* --light-mode - Create a light mode theme.
|
|
Appends the resulting file name with '$LIGHT_MODE_SUFFIX'.
|
|
* -b, --background <BG_COLOR> - Creates the theme with the following background color.
|
|
This is passed to the 'wal' command.
|
|
* -e, --execute <STRING> - Append the resulting wal command with the given string.
|
|
"
|
|
|
|
# Setting the variables for the program.
|
|
# Feel free to change `OUTPUT_DIR`.
|
|
OUTPUT_DIR="$HOME/.config/wal"
|
|
LIGHT_MODE=0
|
|
IMAGE_PATH="$1"
|
|
|
|
while [[ $# -gt 0 ]]
|
|
do
|
|
case $1 in
|
|
-h|--help)
|
|
printf "$help_section"
|
|
exit 0;;
|
|
-o|--output)
|
|
OUTPUT_DIR="$2"
|
|
shift
|
|
shift;;
|
|
--light-mode)
|
|
LIGHT_MODE=1
|
|
shift;;
|
|
-b|--background)
|
|
BG_COLOR="$2"
|
|
shift
|
|
shift;;
|
|
-e|--execute)
|
|
EXECUTE="$2"
|
|
shift
|
|
shift;;
|
|
*)
|
|
shift;;
|
|
esac
|
|
done
|
|
|
|
image_basename=$(extract_path_without_ext "$IMAGE_PATH")
|
|
wal_command_string="wal -i $IMAGE_PATH"
|
|
output_file=$([ $LIGHT_MODE -eq 1 ] && echo "$OUTPUT_DIR/colorschemes/light/$image_basename" || echo "$OUTPUT_DIR/colorschemes/dark/$image_basename.json")
|
|
|
|
if [[ $LIGHT_MODE -eq 1 ]]; then
|
|
wal_command_string+=" -l"
|
|
fi
|
|
|
|
if [[ -n "$BG_COLOR" ]]; then
|
|
wal_command_string+=" -b $BG_COLOR"
|
|
fi
|
|
|
|
if [[ -n "$EXECUTE" ]]; then
|
|
wal_command_string+="$EXECUTE"
|
|
fi
|
|
|
|
command -p $wal_command_string && cp "$CACHE_DIR/colors.json" "$output_file"
|