aboutsummaryrefslogtreecommitdiff
path: root/wallpaper
diff options
context:
space:
mode:
Diffstat (limited to 'wallpaper')
-rwxr-xr-xwallpaper/liveWP.sh14
-rwxr-xr-xwallpaper/pkmWpSelector.sh11
-rwxr-xr-xwallpaper/setRandomWP.sh9
-rwxr-xr-xwallpaper/setWP.sh10
-rwxr-xr-xwallpaper/wpBrowser.sh102
-rwxr-xr-xwallpaper/wpPointer.sh184
6 files changed, 330 insertions, 0 deletions
diff --git a/wallpaper/liveWP.sh b/wallpaper/liveWP.sh
new file mode 100755
index 0000000..ad07bd8
--- /dev/null
+++ b/wallpaper/liveWP.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+# Dependencies: feh
+
+wpsFolder="/home/taamas/images/wallpapers/live/current/"
+delay=0.2
+
+while true; do
+ for file in $(echo $wpsFolder*); do
+ feh --bg-max "$file"
+ sleep "$delay"
+ done
+done
+exit 0
diff --git a/wallpaper/pkmWpSelector.sh b/wallpaper/pkmWpSelector.sh
new file mode 100755
index 0000000..7fea1b9
--- /dev/null
+++ b/wallpaper/pkmWpSelector.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+hour=$(date +%H)
+if [ $hour -gt 4 -a $hour -lt 7 ]; then
+ feh --bg-scale ~/images/wallpapers/pkmduskbg.png
+elif [ $hour -gt 6 -a $hour -lt 15 ]; then
+ feh --bg-scale ~/images/wallpapers/pkmdaybg.png
+elif [ $hour -gt 14 -a $hour -lt 17 ]; then
+ feh --bg-scale ~/images/wallpapers/pkmduskbg.png
+else
+ feh --bg-scale ~/images/wallpapers/pkmnightbg.jpg
+fi
diff --git a/wallpaper/setRandomWP.sh b/wallpaper/setRandomWP.sh
new file mode 100755
index 0000000..218e68b
--- /dev/null
+++ b/wallpaper/setRandomWP.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+# Sets a random image as wallpaper and soft-links it from home folder.
+
+wpsFolder="$CONFIG_FOLDER_RANDOMWP"
+[ -z "$wpsFolder" ] && dunstify '$CONFIG_FOLDER_RANDOMWP env variable not set.' && exit 0
+[ ! -d "$wpsFolder" ] && dunstify "'$CONFIG_FOLDER_RANDOMWP' folder does not exist." && exit 0
+wpFile="$(find "$CONFIG_FOLDER_RANDOMWP" | shuf -n 1)"
+wpPointer.sh "$wpFile"
diff --git a/wallpaper/setWP.sh b/wallpaper/setWP.sh
new file mode 100755
index 0000000..6ff0a9d
--- /dev/null
+++ b/wallpaper/setWP.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+# Sets an image as wallpaper and sends a confirmation notification.
+
+wpPointer.sh "$1"
+
+#bgiconPath="/tmp/bgicon"
+#convert "$1" -resize 64x64 "$bgiconPath"
+#feh --bg-max "$1" && notify-send -t 3000 -i "$bgiconPath" "$1 set as background."
+#TODO: make notification optional and fix its icon
diff --git a/wallpaper/wpBrowser.sh b/wallpaper/wpBrowser.sh
new file mode 100755
index 0000000..8fd3a8b
--- /dev/null
+++ b/wallpaper/wpBrowser.sh
@@ -0,0 +1,102 @@
+#!/bin/bash
+# _ _
+# __ ____ _| | |_ __ __ _ _ __ ___ _ __
+# \ \ /\ / / _` | | | '_ \ / _` | '_ \ / _ \ '__|
+# \ V V / (_| | | | |_) | (_| | |_) | __/ |
+# \_/\_/ \__,_|_|_| .__/ \__,_| .__/ \___|_|
+# _ |_| |_|
+# | |__ _ __ _____ _____ ___ _ __
+# | '_ \| '__/ _ \ \ /\ / / __|/ _ \ '__|
+# | |_) | | | (_) \ V V /\__ \ __/ |
+# |_.__/|_| \___/ \_/\_/ |___/\___|_|
+#
+
+folder="$1"
+indexSet=0
+
+function updateFiles {
+ files=$(ls "$folder" | grep -e .jpg -e .jpeg -e .png)
+}
+
+function updateCurrentFile {
+ [[ $indexSet -lt 1 ]] && indexSet=1 && echo "First image!"
+ i=0
+ for file in $files; do
+ i=$((i+1))
+ if [ $i -eq $indexSet ]; then
+ selectedFile="$file"
+ fi
+ done
+}
+
+function updateWp {
+ feh --no-fehbg --bg-max "$folder""$selectedFile"
+ echo "New wp: $selectedFile"
+}
+
+echo "Welcome to wp browser! Usage:"
+echo "h, l - Browse wallpapers."
+echo "r - Rename current wallpaper's file."
+echo "d - Delete current wallpaper's file."
+echo "q - Quit."
+
+updateFiles
+read -n 1 input
+while [ "$input" != "q" ]
+do
+ case $input in
+ l)
+ indexSet=$((indexSet+1))
+ clear
+ updateCurrentFile
+ updateWp
+ ;;
+ h)
+ indexSet=$((indexSet-1))
+ clear
+ updateCurrentFile
+ updateWp
+ ;;
+ r)
+ clear && echo "Rename? [y]es/[no]"
+ read -n 1 input
+ if [ "$input" = "y" ]; then
+ clear && echo "Prev name: $selectedFile" && echo "New name: "
+ read newName
+ if [ "$newName" = "$selectedFile" ]; then
+ clear && echo "Same name ($newName) - No changes"
+ else
+ # Check that name does not exist
+ if [ -f "$folder$newName" ]; then #FIX
+ clear && echo "\"$newName\" already exists - Aborting"
+ else
+ mv "$folder$selectedFile" "$folder$newName"
+ echo "$selectedFile -> $newName"
+ updateFiles
+ updateCurrentFile
+ updateWp
+ fi
+ fi
+ else
+ clear && echo "Current wp: $selectedFile"
+ fi
+ ;;
+ d)
+ clear && echo "Delete $selectedFile? [y]es/[no]"
+ read -n 1 input
+ if [ "$input" = "y" ]; then
+ rm "$folder$selectedFile"
+ clear && echo "\"$selectedFile\" deleted"
+ updateFiles
+ updateCurrentFile
+ updateWp
+ else
+ clear && echo "Not deleted." && echo "Current wp: $selectedFile"
+ fi
+ ;;
+ *)
+ clear && echo "Current wp: $selectedFile"
+ ;;
+ esac
+ read -n 1 input
+done
diff --git a/wallpaper/wpPointer.sh b/wallpaper/wpPointer.sh
new file mode 100755
index 0000000..a816f18
--- /dev/null
+++ b/wallpaper/wpPointer.sh
@@ -0,0 +1,184 @@
+#!/bin/sh
+
+# wpPointer.sh: Set next or previous wallpaper in wallpaper history or set and add one to it
+#
+# Usage: wpPointer.sh [-n|p] [-o] FILE...
+#
+# -n sets next wallpaper if it exists
+# -p sets previous wallpaper if it exists
+# -o opens recorded wallpapers in sxiv
+
+usageMessage="Usage: ${0} [-n|p] [-o] FILE..."
+
+wpDatFile="$CONFIG_WPLIST"
+wpPointerFile="$CONFIG_WPPOINTER"
+recordedMax="30"
+
+nextOrPrev=""
+next="n"
+prev="p"
+
+open=""
+
+error() {
+ printf '%s error: %s\n' "$0" "$*" >&2
+ notify-send "${0} error" "$*"
+}
+
+errorAndUsage() {
+ printf '%s error: %s\n%s\n' "$0" "$*" "$usageMessage" >&2
+ notify-send "${0} error" "${*}\n\n${usageMessage}"
+}
+
+getRecordedAmount() {
+ wc -l "$wpDatFile" | cut -d' ' -f1
+}
+
+setWP() {
+ wp="$1"
+ feh --bg-max "$wp"
+ ln -sf "$wp" "${HOME}/wp"
+}
+
+setWpByPointer() {
+ pointer="$1"
+ wp="$(sed -n "${pointer}p" "$wpDatFile")"
+ echo "$pointer" >"$wpPointerFile"
+ if ! setWP "$wp"; then
+ error "Unable to set ${wp} as wallpaper."
+ fi
+}
+
+setNextOrPrev() {
+
+ nextOrPrev="$1"
+
+ if ! [ -f "$wpDatFile" ]; then
+ error "${wpDatFile} does not exist or is not a regular file. Maybe no wallpapers were registered yet."
+ exit 2
+ fi
+
+ if ! [ -s "$wpDatFile" ]; then
+ error "${wpDatFile} is empty."
+ exit 2
+ fi
+
+ datFileLength="$(getRecordedAmount)"
+
+ if [ -f "$wpPointerFile" ]; then
+ pointer="$(cat "$wpPointerFile")"
+ else
+ pointer="$datFileLength"
+ fi
+
+ if [ "$nextOrPrev" = "$next" ]; then
+
+ if [ "$pointer" -eq "$datFileLength" ]; then
+ error 'Last recorded wallpaper already selected.'
+ exit 3
+ fi
+
+ pointer=$((pointer+1))
+ setWpByPointer "$pointer"
+
+ fi
+
+ if [ "$nextOrPrev" = "$prev" ]; then
+
+ if [ "$pointer" -eq "1" ]; then
+ error 'First recorded wallpaper already selected.'
+ exit 3
+ fi
+
+ pointer=$((pointer-1))
+ setWpByPointer "$pointer"
+
+ fi
+
+}
+
+addWp() {
+
+ wp="$1"
+
+ if ! [ -f "$1" ]; then
+ error "File ${1} does not exist."
+ exit 4
+ fi
+
+ if ! setWP "$wp"; then
+ error "Unable to set ${wp} as wallpaper."
+ exit 4
+ fi
+
+ wpPath="$(readlink -f "$wp")"
+ # Double \ for explicit \ to reach variable!
+ wpPathSanitized="$(echo "$wpPath" | sed 's|/|\\/|g')"
+
+ # Delete existing references to the wallpaper to avoid repetition in history
+ sed -i "/^${wpPathSanitized}$/d" "$wpDatFile"
+
+ echo "$wpPath" >>"$wpDatFile"
+ [ "$(getRecordedAmount)" -gt "$recordedMax" ] && sed -i "1d" "$wpDatFile"
+ getRecordedAmount >"$wpPointerFile"
+
+}
+
+# Check pointer file makes sense
+
+if [ -f "$wpPointerFile" ]; then
+ pointer="$(cat "$wpPointerFile")"
+ pointerAsNumber="$(echo "$pointer" | sed 1q | grep -E '[0-9]+')"
+ if [ "$pointer" != "$pointerAsNumber" ]; then
+ rm "$wpPointerFile"
+ else
+ if [ "$pointer" -lt 1 ]; then
+ echo "1" >"$wpPointerFile"
+ fi
+ recordedAmount=$(getRecordedAmount)
+ if [ "$pointer" -gt "$recordedAmount" ]; then
+ echo "$recordedAmount" >"$wpPointerFile"
+ fi
+ fi
+fi
+
+# Process options
+
+while getopts ':npo' opt; do
+ case $opt in
+
+ 'n' )
+ if [ -n "$nextOrPrev" ]; then
+ errorAndUsage 'Tried to use -n and -p at the same time.'
+ exit 1
+ fi
+ setNextOrPrev "$next"
+ ;;
+
+ 'p' )
+ if [ -n "$nextOrPrev" ]; then
+ errorAndUsage 'Tried to use -n and -p at the same time.'
+ exit 1
+ fi
+ setNextOrPrev "$prev"
+ ;;
+
+ 'o' )
+ open="y"
+ ;;
+
+ '?' )
+ printf '%s\n' "$usageMessage"
+ exit 1
+
+ esac
+done
+shift $((OPTIND - 1))
+
+# Set and add arguments to wallpaper history
+
+for wp in "$@"; do
+ addWp "$wp"
+done
+
+[ -n "$open" ] && sxiv -t $(cat "$wpDatFile")