From 265b3b7b976732ab00e57aa064f06857b547b2b0 Mon Sep 17 00:00:00 2001 From: Julian T Date: Mon, 6 Feb 2023 20:50:11 +0100 Subject: Create new setwall script in rust --- scripts/Scripts/lc | 2 +- scripts/Scripts/setwall | 196 -------------------------------------------- scripts/Scripts/setwall_old | 196 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+), 197 deletions(-) delete mode 100755 scripts/Scripts/setwall create mode 100755 scripts/Scripts/setwall_old (limited to 'scripts/Scripts') diff --git a/scripts/Scripts/lc b/scripts/Scripts/lc index 8b9fbcd..dba58f0 100755 --- a/scripts/Scripts/lc +++ b/scripts/Scripts/lc @@ -42,7 +42,7 @@ handle_stuff() { fi if [ "$1" = "wall" ]; then - $HOME/Scripts/setwall -A + setwall --config $WALLCONFIG fi if [ "$1" = "remember" ]; then diff --git a/scripts/Scripts/setwall b/scripts/Scripts/setwall deleted file mode 100755 index 86214a6..0000000 --- a/scripts/Scripts/setwall +++ /dev/null @@ -1,196 +0,0 @@ -#!/usr/bin/env bash - -WALLFILE="$HOME/Pictures/wallconfig" -WALLLINK="$HOME/Pictures/current_wall" -BINNAME="setwall" - -function unsetwalls() { - for wall in $@; do - echo unsetting $wall - pat=$(echo $wall | sed 's/\//\\\//g') - sed -i.bak "/$pat/d" $WALLFILE - done -} -function unsetcur() { - if [ -f "${WALLLINK}" ]; then - unsetwalls $(realpath --relative-to=$HOME $WALLLINK) - else - echo "could not resolve current wallpaper" - exit 1 - fi -} -function delete() { - echo deleting wallfile - rm $WALLFILE -} -function unsetall() { - 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 -} - -function runsetwall() { - feh --bg-tile $1 - # wal --saturate 0.9 -i $1 -} - -function applywall() { - echo applying wallpaper $1 - rm $WALLLINK - ln -s $(pwd)/$1 $WALLLINK - runsetwall $1 -} - -function reapply() { - echo reapplying linked wallpaper - # feh --bg-fill $WALLLINK - runsetwall $WALLLINK -} - -function help() { - 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 " -c, --current unset currently applied wallpaper" - echo - echo "apply options:" - echo " -r, --reapply reapply last applied wallpaper" -} - -function unknown() { - echo "${BINNAME}: unknown option $1" 1>&2 - exit 1 -} - -if [[ $# -eq 0 ]]; then - echo "${BINNAME}: no arguments given" 1>&2 - help - exit 1 -fi - -mode="N" -pos="" - -function apply_mode() { - case $mode in - U) - unsetwalls $pos - ;; - S) - setwalls $pos - ;; - A) - applywall $(shuf -n 1 $WALLFILE) - ;; - esac -} - -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 - - for key in $keys; do - case $mode in - U) - case $key in - -a|--all) - unsetall - mode="N" - ;; - -d|--delete) - delete - mode="N" - ;; - -c|--current) - unsetcur - mode="N" - ;; - '-'*|'--'*) - unknown $key - ;; - *) - pos="$pos $key" - shift - ;; - esac - ;; - A) - case $key in - -r|--reapply) - reapply - mode="N" - ;; - '-'*|'--'*) - unknown $key - ;; - *) - echo Unexpected argument - help - mode="N" - ;; - esac - ;; - S) - pos="$pos $key" - shift - ;; - - *) - apply_mode - case $key in - -A|--apply) - mode="A" - shift - ;; - -U|--unset) - mode="U" - shift - ;; - -S|--set) - mode="S" - shift - ;; - -P|--preview) - applywall $2 - ;; - -h|--help) - help - shift - exit 0 - ;; - *) - unknown $key - ;; - esac - ;; - esac - done -done - -apply_mode diff --git a/scripts/Scripts/setwall_old b/scripts/Scripts/setwall_old new file mode 100755 index 0000000..86214a6 --- /dev/null +++ b/scripts/Scripts/setwall_old @@ -0,0 +1,196 @@ +#!/usr/bin/env bash + +WALLFILE="$HOME/Pictures/wallconfig" +WALLLINK="$HOME/Pictures/current_wall" +BINNAME="setwall" + +function unsetwalls() { + for wall in $@; do + echo unsetting $wall + pat=$(echo $wall | sed 's/\//\\\//g') + sed -i.bak "/$pat/d" $WALLFILE + done +} +function unsetcur() { + if [ -f "${WALLLINK}" ]; then + unsetwalls $(realpath --relative-to=$HOME $WALLLINK) + else + echo "could not resolve current wallpaper" + exit 1 + fi +} +function delete() { + echo deleting wallfile + rm $WALLFILE +} +function unsetall() { + 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 +} + +function runsetwall() { + feh --bg-tile $1 + # wal --saturate 0.9 -i $1 +} + +function applywall() { + echo applying wallpaper $1 + rm $WALLLINK + ln -s $(pwd)/$1 $WALLLINK + runsetwall $1 +} + +function reapply() { + echo reapplying linked wallpaper + # feh --bg-fill $WALLLINK + runsetwall $WALLLINK +} + +function help() { + 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 " -c, --current unset currently applied wallpaper" + echo + echo "apply options:" + echo " -r, --reapply reapply last applied wallpaper" +} + +function unknown() { + echo "${BINNAME}: unknown option $1" 1>&2 + exit 1 +} + +if [[ $# -eq 0 ]]; then + echo "${BINNAME}: no arguments given" 1>&2 + help + exit 1 +fi + +mode="N" +pos="" + +function apply_mode() { + case $mode in + U) + unsetwalls $pos + ;; + S) + setwalls $pos + ;; + A) + applywall $(shuf -n 1 $WALLFILE) + ;; + esac +} + +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 + + for key in $keys; do + case $mode in + U) + case $key in + -a|--all) + unsetall + mode="N" + ;; + -d|--delete) + delete + mode="N" + ;; + -c|--current) + unsetcur + mode="N" + ;; + '-'*|'--'*) + unknown $key + ;; + *) + pos="$pos $key" + shift + ;; + esac + ;; + A) + case $key in + -r|--reapply) + reapply + mode="N" + ;; + '-'*|'--'*) + unknown $key + ;; + *) + echo Unexpected argument + help + mode="N" + ;; + esac + ;; + S) + pos="$pos $key" + shift + ;; + + *) + apply_mode + case $key in + -A|--apply) + mode="A" + shift + ;; + -U|--unset) + mode="U" + shift + ;; + -S|--set) + mode="S" + shift + ;; + -P|--preview) + applywall $2 + ;; + -h|--help) + help + shift + exit 0 + ;; + *) + unknown $key + ;; + esac + ;; + esac + done +done + +apply_mode -- cgit v1.2.3