Add base shell script, config file & current file

This commit is contained in:
Maximilian P. Käfer 2021-05-16 14:47:41 +02:00
parent ac952996e7
commit c586c0d420
Signed by: mpk
GPG Key ID: 035869C949377C5C
3 changed files with 101 additions and 0 deletions

1
current_wallpaper.txt Normal file
View File

@ -0,0 +1 @@

3
paperchanger.conf.sh Normal file
View File

@ -0,0 +1,3 @@
# This is the configuration file used by the paperchanger program
default_directory=/win-f/Daten/Wallpaper/

97
paperchanger.sh Executable file
View File

@ -0,0 +1,97 @@
#!/usr/bin/env bash
# Simple CLI to make wallpaper changes with xwallpaper more comfortable
read -r current_file_path < current_wallpaper.txt
source $(dirname $0)/paperchanger.conf.sh
function _help() {
echo ""
echo "A tool to help change the wallpaper in a more comfortable way."
echo "Uses xwallpaper to load the specified wallpaper."
echo ""
echo "Usage: paperchanger [OPTION] [PATH]"
printf " %-45s\t%-54s\n" \
"-h, --help, help" "Print this help." \
"-d, --display, display" "Display the specified wallpaper." \
"-s, --set, set" "Set the wallpaper with the path as parameter." \
"-S, --Set, Set" "Set the wallpaper with a graphical file chooser." \
"-ds, --display-and-set, display-and-set" "Set the wallpaper with an path as parameter AND display the specified wallpaper." \
"-dS, --display-and-Set, display-and-Set" "Set the wallpaper with a graphical file chooser AND display the specified wallpaper." \
"-p, --path, path" "Set the path of the default directory as parameter, where the file chooser to select a wallpaper is initially opened." \
"-P, --Path, Path" "Set the path of the default directory with a graphical file chooser, where the file chooser to select a file chooser is initially opened." \
}
function _display() {
xwallpaper --zoom $current_file_path
}
function _set() {
current_file_path="$1"
echo "$current_file_path" > current_wallpaper.txt
}
function _change_config_path() {
sed -i "s/^default_directory=.*\$/default_directory=${1//\//\\/}/" paperchanger.conf.sh
}
case "$#" in
0)
_help
;;
1)
case "$1" in
-h | --help | help)
_help
;;
-d | --display | display)
if [[ "$current_file_path" == "" ]]; then
echo "No wallpaper is selected. Please use <paperchanger -s> or <paperchanger -S> first!"
exit 1
else
_display
fi
;;
-S | --Set | Set)
if [[ "$default_directory" == "" ]]; then
_set "$(zenity --file-selection)"
else
_set "$(zenity --file-selection --filename=$default_directory)"
fi
;;
-dS | --display-and-Set | display-and-Set)
if [[ "$default_directory" == "" ]]; then
_set "$(zenity --file-selection)"
else
_set "$(zenity --file-selection --filename=$default_directory)"
fi
_display
;;
-P | --Path | Path)
_change_config_path "$(zenity --file-selection --directory)/"
;;
*)
echo "Input Error"
exit 1
;;
esac
;;
2) if [[ "$1" == "-s" || "$1" == "--set" || "$1" == "set" ]]; then
_set "$2"
elif [[ "$1" == "-ds" || "$1" == "--display-and-set" || "$1" == "display-and-set" ]]; then
_set "$2"
_display
elif [[ "$1" == "-p" || "$1" == "--path" || "$1" == "path" ]]; then
_change_config_path "$2"
else
echo "Input Error"
exit 1
fi
;;
*)
echo "Input error, too many parameters."
echo "please use paperchanger -h or the man page to get help."
exit 1
;;
esac