suckless-utils/scripts/adelle-theme

300 lines
6.6 KiB
Bash
Executable file

#!/bin/sh
# Adelle Theme Manager, written in Bash.
# Adelle Theme Manager Copyright (C) 2023 Alexis Jhon Gaspar.
# This program comes with ABSOLUTELY NO WARRANTY; for details type `l'.
# This is free software, and you are welcome to redistribute it
# under certain conditions; type `l` for details.
linker() {
cachedir="$HOME/.cache/wal"
if [ -d "$cachedir" ]; then
ln -f $HOME/.cache/wal/colors.scss $HOME/.config/eww/colors.scss
ln -f $HOME/.cache/wal/cava-config $HOME/.config/cava/config
ln -f $HOME/.cache/wal/jgmenurc $HOME/.config/jgmenu/jgmenurc
else
rm -r $HOME/.cache/wal/*
ln -f $HOME/.cache/wal/colors.scss $HOME/.config/eww/colors.scss
ln -f $HOME/.cache/wal/cava-config $HOME/.config/cava/config
ln -f $HOME/.cache/wal/jgmenurc $HOME/.config/jgmenu/jgmenurc
fi
}
linkremove() {
rm -r $HOME/.cache/wal/*
rm -f $HOME/.cache/wal/colors.scss
rm -f $HOME/.cache/wal/cava-config
rm -f $HOME/.cache/wal/jgmenurc
}
movescript(){
mv /tmp/wallpaper_new /tmp/wal/wal
mv /tmp/wal $HOME/.cache/
rm -f $HOME/.cache/wal/colors.json
jq -r --arg var "$(cat "$HOME/.cache/wal/wal")" '. | .wallpaper = $var' /tmp/colors.json >> $HOME/.cache/wal/colors.json
rm /tmp/colors.json
}
help() {
printf "Adelle Theme Manager by lucss21a. Written in bash!\n\nh or help: Prints this text\ns or set: Set the colorscheme\nsw or setwall: Set the wallpaper\nd or download: Download themes to the theme directory\nc or clear: Clear the theme directory\nl or license: View the GNU General Public License Version 3.\nq or quit: Quit the program\n"
command
}
settheme() {
read -p "Where is the theme directory? " waldir
if [ -z "$waldir" ]; then
waldir="$HOME/.config/wal/colorschemes/dark"
if [[ -z $(ls -A "$waldir") ]]; then
echo "Oh no! No files here!"
settheme
else
ls -w 1 "$waldir"
fi
else
if [[ -z $(ls -A "$waldir") ]]; then
echo "Oh no! No files here!"
settheme
else
ls -w 1 "$waldir"
fi
fi
read -p "What theme? " theme
if [ -z "$theme" ]; then
settheme
else
if [[ "$theme" != *.json ]]; then
wal --theme "$waldir/$theme.json"
linker
if [ -z "$picwaldir" ]; then
setwallq
unset theme
else
unset theme
command
fi
else
wal --theme "$waldir/$theme"
linker
if [ -z "$picwaldir" ]; then
setwallq
unset theme
else
command
fi
fi
fi
}
setwallq() {
read -p "Do you want to set the wallpaper as well? (default is Yes) " wallpaper
case $wallpaper in
[yY][eE][sS]|[yY]) setwall;;
[nN][oO]|[nN]) command;;
*) setwall;;
esac
}
backendlister() {
backendlist="wal"
# TODO: Locate common locations where PIP install packages
if [ -f $HOME/.local/lib/python*/site-packages/colorz.py ]; then
backendlist="$backendlist, colorz"
else
backendlist="$backendlist"
fi
if [ -f $HOME/.local/lib/python*/site-packages/colorthief.py ]; then
backendlist="$backendlist, colorthief"
else
backendlist="$backendlist"
fi
if [ -f $HOME/.local/lib/python*/site-packages/haishoku/haishoku.py ]; then
backendlist="$backendlist, haishoku"
else
backendlist="$backendlist"
fi
if [ -f $GOPATH/bin/schemer2 ]; then
backendlist="$backendlist, schemer2"
else
if [ -f $HOME/go/bin/schemer2 ]; then
backendlist="$backendlist, schemer2"
else
backendlist="$backendlist"
fi
fi
}
backender() {
backendlister
read -p "Which backend? (Available on system: $backendlist): " backend
if [ -z "$backend" ]; then
backend=wal
else
backend="$backend"
fi
}
setwall() {
read -p "Where is the wallpaper directory? " picwaldir
if [ -z "$picwaldir" ]; then
picwaldir="$HOME/Pictures/Wallpapers"
if [[ -z $(ls -A "$picwaldir") ]]; then
echo "Oh no! No files here!"
setwall
else
ls -w 1 "$picwaldir"
fi
else
if [[ -z $(ls -A "$picwaldir") ]]; then
echo "Oh no! No files here!"
setwall
else
ls -w 1 "$picwaldir"
fi
fi
read -p "What wallpaper? " picwal
if [ -z "$picwal" ]; then
setwall
else
rm -rf /tmp/wal
mv $HOME/.cache/wal/colors.json /tmp/colors.json
mv $HOME/.cache/wal /tmp/
wal -i "$picwaldir/$picwal" -qste
mv $HOME/.cache/wal/wal /tmp/wallpaper_new
linkremove
if [ -z "$theme" ]; then
setcolor1
unset picwaldir
else
unset picwaldir
wal --theme "$waldir/$theme"
unset theme
command
fi
fi
}
setcolor1() {
read -p "Do you want to set the colors as well? (default is Yes) " colors
case $colors in
[yY][eE][sS] | [yY]) setcolor2;;
[nN][oO] | [nN]) movescript && command;;
*) setcolor2;;
esac
exit
}
setcolor2() {
read -p "Do you want to set colors automatically? (default is Yes) " manualcolor
case $manualcolor in
[yY][eE][sS] | [yY]) backender && wal -i "$picwaldir/$picwal" --backend $backend && linker && command;;
[nN][oO] | [nN]) settheme;;
*) backender && wal -i "$picwaldir/$picwal" --backend $backend && linker && command;;
esac
}
cache() {
read -p "Where is the theme directory? " waldir
if [ -z "$waldir" ]; then
waldir="$HOME/.config/wal/colorschemes/dark"
if [[ -z $(ls -A "$waldir") ]]; then
echo "Already wiped out."
command
else
read -p "Are you sure? (default is No) " del
case $del in
[yY][eE][sS] | [yY]) rm -r "$waldir/*.json*";;
[nN][oO] | [nN]) command;;
*) command;;
esac
fi
else
if [[ -z $(ls -A "$waldir") ]]; then
echo "Already wiped out."
command
else
read -p "Are you sure? (default is No) " del
case $del in
[yY][eE][sS] | [yY]) rm -rf "$waldir/*.json*";;
[nN][oO] | [nN]) command;;
*) command;;
esac
fi
fi
}
download() {
read -p "Where is the theme directory? " waldir
if [ -z "$waldir" ]; then
waldir="$HOME/.config/wal/colorschemes/dark"
else
$waldir
fi
read -p "Put the url of the file: " url
if [ -z "$url" ]; then
download
else
wget --show-progress -q -P $waldir $url
if [ "$?" != 0 ]; then
echo "Download failed. Check if you are connected or if the domain exists."
download
else
echo "Download complete!"
command
fi
fi
}
license() {
LICENSE=/tmp/gpl-3.0.txt
if [ -f "$LICENSE" ]; then
rm "$LICENSE"
else
wget -q https://www.gnu.org/licenses/gpl-3.0.txt -P /tmp
vim "$LICENSE" || nano "$LICENSE" || emacs "$LICENSE" || cat "$LICENSE"
command
fi
}
command () {
script=$(basename "$0")
echo "Enter h or help for a list of commands."
read -p "$script> " command
case $command in
[hH] | help ) help;;
[sS] | set ) settheme;;
[sS][wW] | setwall ) setwall;;
[dD] | download ) download;;
[cC] | clear) cache;;
[lL] | license) license;;
[qQ] | quit | exit) printf "Bye!\n" && exit;;
*) printf "Check h or help!\n" && command;;
esac
}
command