aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdmenuTerm.sh4
-rwxr-xr-xfloats/floatBgBrowser.sh4
-rwxr-xr-xfloats/floatWpBrowser.sh4
-rwxr-xr-xliveBG.sh14
-rwxr-xr-xsetBG.sh7
-rwxr-xr-xsetRandomBG.sh10
-rwxr-xr-xwallpaper/liveWP.sh14
-rwxr-xr-xwallpaper/pkmWpSelector.sh (renamed from pkmBgSelector.sh)0
-rwxr-xr-xwallpaper/setRandomWP.sh9
-rwxr-xr-xwallpaper/setWP.sh10
-rwxr-xr-xwallpaper/wpBrowser.sh (renamed from bgBrowser.sh)20
-rwxr-xr-xwallpaper/wpPointer.sh184
-rwxr-xr-xxinit.sh2
13 files changed, 234 insertions, 48 deletions
diff --git a/dmenuTerm.sh b/dmenuTerm.sh
index 5f984b7..9654649 100755
--- a/dmenuTerm.sh
+++ b/dmenuTerm.sh
@@ -1,7 +1,7 @@
#!/bin/sh
# dmenu script for opening console programs and scripts directly
-options="neofetch\ncmus\ncmus (float)\nweather\nReset NetworkManager\nwifiUp\nwifiDown\nyears\nmonths\nbg selection\nshowColors\npython\nmusicMode\nClose music mode\n"
+options="neofetch\ncmus\ncmus (float)\nweather\nReset NetworkManager\nwifiUp\nwifiDown\nyears\nmonths\nwp selection\nshowColors\npython\nmusicMode\nClose music mode\n"
count="$(printf "$options" | wc -l)"
@@ -14,7 +14,7 @@ case "$chosen" in
"years") ~/scripts/floats/floatYears.sh ;;
"months") ~/scripts/floats/floatMonths.sh ;;
"weather") urxvt -title floating -sh 10 -geometry 125x40 -e weather.sh ;;
- "bg selection") ~/scripts/floats/floatBgBrowser.sh "$HOME/images/wallpapers/" ;;
+ "wp selection") ~/scripts/floats/floatWpBrowser.sh "$HOME/images/wallpapers/" ;;
"python") urxvt -title floating -geometry 80x28 -e python -q ;;
#programs
"cmus") urxvt -cd ~/music -e cmus ;;
diff --git a/floats/floatBgBrowser.sh b/floats/floatBgBrowser.sh
deleted file mode 100755
index 0fbf0d3..0000000
--- a/floats/floatBgBrowser.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-path="$1"
-[ -z "$path" ] && path="/home/taamas/images/wallpapers/"
-urxvt -title floating -sh 20 -cr black -geometry "45x6-5-5" -e ~/scripts/bgBrowser.sh "$path"
diff --git a/floats/floatWpBrowser.sh b/floats/floatWpBrowser.sh
new file mode 100755
index 0000000..cbfdee9
--- /dev/null
+++ b/floats/floatWpBrowser.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+path="$1"
+[ -z "$path" ] && path="/home/taamas/images/wallpapers/"
+urxvt -title floating -sh 20 -cr black -geometry "45x6-5-5" -e wpBrowser.sh "$path"
diff --git a/liveBG.sh b/liveBG.sh
deleted file mode 100755
index c173e32..0000000
--- a/liveBG.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-
-# Dependencies: feh
-
-bgsFolder="/home/taamas/images/wallpapers/live/current/"
-delay=0.2
-
-while [ 1 ]; do
- for file in $(echo $bgsFolder*); do
- feh --bg-max "$file"
- sleep $delay
- done
-done
-exit 0
diff --git a/setBG.sh b/setBG.sh
deleted file mode 100755
index b2bbae7..0000000
--- a/setBG.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh
-
-# Sets an image as wallpaper and sends a confirmation notification.
-
-bgiconPath="/tmp/bgicon"
-convert "$1" -resize 64x64 "$bgiconPath"
-feh --bg-max "$1" && notify-send -t 3000 -i "$bgiconPath" "$1 set as background."
diff --git a/setRandomBG.sh b/setRandomBG.sh
deleted file mode 100755
index d7c5669..0000000
--- a/setRandomBG.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-# Sets a random image as wallpaper and soft-links it from home folder.
-
-bgsFolder="$CONFIG_FOLDER_RANDOMBG"
-[ -z "$bgsFolder" ] && dunstify '$CONFIG_FOLDER_RANDOMBG env variable not set.' && exit 0
-[ ! -d "$bgsFolder" ] && dunstify "'$CONFIG_FOLDER_RANDOMBG' folder does not exist." && exit 0
-wpFile="$(ls -d "$CONFIG_FOLDER_RANDOMBG"/* | shuf -n 1)"
-feh --bg-max "$wpFile"
-ln -sf "$wpFile" "${HOME}/wp"
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/pkmBgSelector.sh b/wallpaper/pkmWpSelector.sh
index 7fea1b9..7fea1b9 100755
--- a/pkmBgSelector.sh
+++ b/wallpaper/pkmWpSelector.sh
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/bgBrowser.sh b/wallpaper/wpBrowser.sh
index 4edb900..8fd3a8b 100755
--- a/bgBrowser.sh
+++ b/wallpaper/wpBrowser.sh
@@ -29,12 +29,12 @@ function updateCurrentFile {
done
}
-function updateBg {
+function updateWp {
feh --no-fehbg --bg-max "$folder""$selectedFile"
- echo "New bg: $selectedFile"
+ echo "New wp: $selectedFile"
}
-echo "Welcome to bg browser! Usage:"
+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."
@@ -49,13 +49,13 @@ do
indexSet=$((indexSet+1))
clear
updateCurrentFile
- updateBg
+ updateWp
;;
h)
indexSet=$((indexSet-1))
clear
updateCurrentFile
- updateBg
+ updateWp
;;
r)
clear && echo "Rename? [y]es/[no]"
@@ -74,11 +74,11 @@ do
echo "$selectedFile -> $newName"
updateFiles
updateCurrentFile
- updateBg
+ updateWp
fi
fi
else
- clear && echo "Current bg: $selectedFile"
+ clear && echo "Current wp: $selectedFile"
fi
;;
d)
@@ -89,13 +89,13 @@ do
clear && echo "\"$selectedFile\" deleted"
updateFiles
updateCurrentFile
- updateBg
+ updateWp
else
- clear && echo "Not deleted." && echo "Current bg: $selectedFile"
+ clear && echo "Not deleted." && echo "Current wp: $selectedFile"
fi
;;
*)
- clear && echo "Current bg: $selectedFile"
+ clear && echo "Current wp: $selectedFile"
;;
esac
read -n 1 input
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")
diff --git a/xinit.sh b/xinit.sh
index 3b547d1..d1e3ae9 100755
--- a/xinit.sh
+++ b/xinit.sh
@@ -10,5 +10,5 @@ xset -b
pgrep -x unclutter || unclutter --idle 1 &
#touchpad.sh
initialLayout.sh
-setRandomBG.sh
+setRandomWP.sh
pgrep -x sxhkd || sxhkd >~/logs/sxhkd.log &