diff options
author | InigoGutierrez <inigogf.95@gmail.com> | 2022-09-20 13:54:01 +0200 |
---|---|---|
committer | InigoGutierrez <inigogf.95@gmail.com> | 2022-09-20 13:54:01 +0200 |
commit | 48cec0cfbf1a9b27d4e8d11f7cf2cf66e48362d3 (patch) | |
tree | 00b3ca57b5b5bd70228cd769375aa150a4719ebf | |
parent | 2cd81ede4a0a6b540cf370c4ef222277b8b867a6 (diff) | |
download | scripts-48cec0cfbf1a9b27d4e8d11f7cf2cf66e48362d3.tar.gz scripts-48cec0cfbf1a9b27d4e8d11f7cf2cf66e48362d3.zip |
Implemented wallpaper history navigation and organized wallpaper scripts.
-rwxr-xr-x | dmenuTerm.sh | 4 | ||||
-rwxr-xr-x | floats/floatBgBrowser.sh | 4 | ||||
-rwxr-xr-x | floats/floatWpBrowser.sh | 4 | ||||
-rwxr-xr-x | liveBG.sh | 14 | ||||
-rwxr-xr-x | setBG.sh | 7 | ||||
-rwxr-xr-x | setRandomBG.sh | 10 | ||||
-rwxr-xr-x | wallpaper/liveWP.sh | 14 | ||||
-rwxr-xr-x | wallpaper/pkmWpSelector.sh (renamed from pkmBgSelector.sh) | 0 | ||||
-rwxr-xr-x | wallpaper/setRandomWP.sh | 9 | ||||
-rwxr-xr-x | wallpaper/setWP.sh | 10 | ||||
-rwxr-xr-x | wallpaper/wpBrowser.sh (renamed from bgBrowser.sh) | 20 | ||||
-rwxr-xr-x | wallpaper/wpPointer.sh | 184 | ||||
-rwxr-xr-x | xinit.sh | 2 |
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") @@ -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 & |