diff --git a/bin/chbg b/bin/chbg index 01e7b7b..38150a0 100755 --- a/bin/chbg +++ b/bin/chbg @@ -132,19 +132,22 @@ done echo "Selected: $randomimage" +request_wallpaper() { + tmpfile=$(mktemp) + trap 'rm -f "$tmpfile"' EXIT + if command -v curl >/dev/null 2>&1; then + curl -sSL "$1" -o "$tmpfile" + elif command -v wget >/dev/null 2>&1; then + wget -qO "$tmpfile" "$1" + else + echo "x) Unable to fetch image without 'curl' or 'wget'." >&2 + exit 2 + fi + set_wallpaper "$tmpfile" +} + if [ -f "$randomimage" ]; then set_wallpaper "$randomimage" - exit 0 -fi - -tmpfile=$(mktemp) -trap 'rm -f "$tmpfile"' EXIT -if command -v curl >/dev/null 2>&1; then - curl -sSL "$randomimage" -o "$tmpfile" -elif command -v wget >/dev/null 2>&1; then - wget -qO "$tmpfile" "$randomimage" else - echo "x) Unable to fetch image without 'curl' or 'wget'." >&2 - exit 2 + request_wallpaper "$randomimage" fi -set_wallpaper "$tmpfile"