diff options
author | Julian T <julian@jtle.dk> | 2020-11-21 17:54:54 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2020-11-21 17:54:54 +0100 |
commit | c848308227c9bcd2c6de188c4431944fc5cfccd3 (patch) | |
tree | 0a3afcb91d0a58983ac8e339e6d5f6a6c379a265 /scripts | |
parent | 5fd95daceb6663f78647358e232a6396ff385ed0 (diff) |
Add reapply to setwall
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/Scripts/setwall | 242 |
1 files changed, 135 insertions, 107 deletions
diff --git a/scripts/Scripts/setwall b/scripts/Scripts/setwall index f385623..728243d 100755 --- a/scripts/Scripts/setwall +++ b/scripts/Scripts/setwall @@ -6,140 +6,168 @@ WALLLINK="$HOME/Pictures/current_wall" BINNAME="setwall" function unsetwalls() { - echo unsetting $@ - for wall in $@; do - sed -i.bak "/$wall/d" $WALLFILE - done + echo unsetting $@ + for wall in $@; do + sed -i.bak "/$wall/d" $WALLFILE + done } function delete() { - echo deleting wallfile - rm $WALLFILE + echo deleting wallfile + rm $WALLFILE } function unsetall() { - echo clearing wallfile - echo -n > $WALLFILE + echo clearing wallfile + echo -n > $WALLFILE } function setwalls() { - for wall in $@; do - if grep -q $wall "$WALLFILE"; then - echo $wall already set - else - echo setting $wall - echo $wall >> $WALLFILE - fi - done + for wall in $@; do + if grep -q $wall "$WALLFILE"; then + echo $wall already set + else + echo setting $wall + echo $wall >> $WALLFILE + fi + done } function applywall() { - echo applying wallpaper $1 - rm $WALLLINK - ln -s $(pwd)/$1 $WALLLINK - feh --bg-fill $1 + echo applying wallpaper $1 + rm $WALLLINK + ln -s $(pwd)/$1 $WALLLINK + feh --bg-fill $1 +} + +function reapply() { + echo reapplying linked wallpaper + feh --bg-fill $WALLLINK } function help() { - echo "Wallpaper mangement script" - echo - echo "Syntax: ${BINNAME} OPTIONS" - echo "options:" - echo " -A, --apply applies a random wallpaper" - echo " -S, --set FILES sets new wallpapers" - echo " -U, --unset [OPTIONS] [FILES] unsets new wallpapers" - echo " -P, --preview FILE temporarily sets a wallpaper" - echo " -h, --help this message" - echo - echo "unset options:" - echo " -a, --all clears wallconfig file" - echo " -d, --delete deleted wallconfig file" + echo "Wallpaper mangement script" + echo + echo "Syntax: ${BINNAME} OPTIONS" + echo "options:" + echo " -A, --apply [OPTIONS] applies a random wallpaper" + echo " -S, --set FILES sets new wallpapers" + echo " -U, --unset [OPTIONS] [FILES] unsets new wallpapers" + echo " -P, --preview FILE temporarily sets a wallpaper" + echo " -h, --help this message" + echo + echo "unset options:" + echo " -a, --all clears wallconfig file" + echo " -d, --delete deleted wallconfig file" + echo + echo "apply options:" + echo " -r, --reapply reapply last applied wallpaper" } function unknown() { - echo "${BINNAME}: unknown option $1" 1>&2 - exit 1 + echo "${BINNAME}: unknown option $1" 1>&2 + exit 1 } if [[ $# -eq 0 ]]; then - echo "${BINNAME}: no arguments given" 1>&2 - help - exit 1 + echo "${BINNAME}: no arguments given" 1>&2 + help + exit 1 fi mode="N" pos="" while [[ $# -gt 0 ]]; do - keys="$1" - # If $1 does is single - argument - if [[ $1 == '-'* ]] && [[ ! $1 == '--'* ]] ; then - # Remove first - - keys=${keys#?} - # Place space between each character - keys=$(echo $keys | sed 's/./-& /g') - fi + keys="$1" + # If $1 does is single - argument + if [[ $1 == '-'* ]] && [[ ! $1 == '--'* ]] ; then + # Remove first - + keys=${keys#?} + # Place space between each character + keys=$(echo $keys | sed 's/./-& /g') + fi + + for key in $keys; do + case $mode in + U) + case $key in + -a|--all) + unsetall + exit 0 + ;; + -d|--delete) + delete + exit 0 + ;; + '-'*|'--'*) + unknown $key + ;; + *) + pos="$pos $key" + shift + ;; + esac + ;; + A) + case $key in + -r|--reapply) + reapply + exit 0 + ;; + '-'*|'--'*) + unknown $key + ;; + *) + echo Unexpected argument + help + exit 0 + ;; + esac + ;; + S) + pos="$pos $key" + shift + ;; - for key in $keys; do - case $mode in - U) - case $key in - -a|--all) - unsetall - exit 0 - ;; - -d|--delete) - delete - exit 0 - ;; - '-'*|'--'*) - unknown $key - ;; - *) - pos="$pos $key" - shift - ;; - esac - ;; - S) - pos="$pos $key" - shift - ;; - *) - case $key in - -A|--apply) - applywall $(shuf -n 1 $WALLFILE) - exit 0 - ;; - -U|--unset) - mode="U" - shift - ;; - -S|--set) - mode="S" - shift - ;; - -P|--preview) - applywall $2 - exit 0 - ;; - -h|--help) - help - shift - exit 0 - ;; - *) - unknown $key - ;; - esac - ;; - esac - done + *) + case $key in + -A|--apply) + mode="A" + shift + ;; + -U|--unset) + mode="U" + shift + ;; + -S|--set) + mode="S" + shift + ;; + -P|--preview) + applywall $2 + exit 0 + ;; + -h|--help) + help + shift + exit 0 + ;; + *) + unknown $key + ;; + esac + ;; + esac + done done case $mode in - U) - unsetwalls $pos - ;; - S) - setwalls $pos - ;; + U) + unsetwalls $pos + ;; + S) + setwalls $pos + ;; + A) + applywall $(shuf -n 1 $WALLFILE) + ;; esac |