From 2e9fe0947360642bf2f1222784e72c8bca6073d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ceylan=20Bozo=C4=9Fullar=C4=B1ndan?= Date: Tue, 12 Feb 2019 17:06:31 +0300 Subject: [PATCH] Background setting from URL feature added! With -u argument, the script downloads the file from URL and set the file as background. Script is also working without -u flag like before. --- .scripts/tools/setbg | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.scripts/tools/setbg b/.scripts/tools/setbg index c9e4a940..5303093d 100755 --- a/.scripts/tools/setbg +++ b/.scripts/tools/setbg @@ -1,4 +1,20 @@ #!/bin/sh -# Sets the background. If given an argument, will set file as background. -[ ! -z "$1" ] && cp "$1" ~/.config/wall.png && notify-send -i "$HOME/.config/wall.png" "Wallpaper changed." -xwallpaper --maximize ~/.config/wall.png +# Sets the background. +# If given an argument with -u flag, will download file from given url and set the file as background. +# Without -u flag, will set local file as backgound. + +if [ ! -z "$1" ]; then + if [ "$1" == "-u" ]; then + curl -o ~/.config/wall-temp.png "$2" + type="$(file -b ~/.config/wall-temp.png --mime-type | sed s/[/].*$//)" + if [ "$type" == "image" ]; then + mv ~/.config/wall-temp.png ~/.config/wall.png + xwallpaper --maximize ~/.config/wall.png + else + rm ~/.config/wall-temp.png + fi + else + [ ! -z "$1" ] && cp "$1" ~/.config/wall.png && notify-send -i "$HOME/.config/wall.png" "Wallpaper changed." + xwallpaper --maximize ~/.config/wall.png + fi +fi