diff options
Diffstat (limited to 'wallpaper/wpBrowser.sh')
-rwxr-xr-x | wallpaper/wpBrowser.sh | 102 |
1 files changed, 102 insertions, 0 deletions
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 |