113 lines
3.2 KiB
Bash
Executable File
113 lines
3.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Simple CLI to make wallpaper changes with xwallpaper more comfortable
|
|
|
|
CONF_DIR=${XDG_CONFIG_HOME:-~/.config}/paperchanger
|
|
CONF_CURRENT_WP=${CONF_DIR}/current_wallpaper.txt
|
|
CONF_PATH=${CONF_DIR}/paperchanger.conf.sh
|
|
mkdir -p ${CONF_DIR}
|
|
|
|
if [[ ! -f ${CONF_DIR} ]]; then
|
|
touch ${CONF_DIR}
|
|
fi
|
|
|
|
|
|
if [[ ! -f ${CONF_PATH} ]]; then
|
|
echo '# This is the configuration file used by the paperchanger program
|
|
|
|
default_directory=' > ${CONF_DIR}/paperchanger.conf.sh
|
|
fi
|
|
|
|
read -r current_file_path < ${CONF_CURRENT_WP}
|
|
source ${CONF_PATH}
|
|
|
|
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" > ${CONF_CURRENT_WP}
|
|
}
|
|
|
|
function _change_config_path() {
|
|
sed -i "s/^default_directory=.*\$/default_directory=${1//\//\\/}/" ${CONF_PATH}
|
|
}
|
|
|
|
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
|