diff --git a/current_wallpaper.txt b/current_wallpaper.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/current_wallpaper.txt @@ -0,0 +1 @@ + diff --git a/paperchanger.conf.sh b/paperchanger.conf.sh new file mode 100644 index 0000000..0061f55 --- /dev/null +++ b/paperchanger.conf.sh @@ -0,0 +1,3 @@ +# This is the configuration file used by the paperchanger program + +default_directory=/win-f/Daten/Wallpaper/ diff --git a/paperchanger.sh b/paperchanger.sh new file mode 100755 index 0000000..c97bc56 --- /dev/null +++ b/paperchanger.sh @@ -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 or 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