summaryrefslogtreecommitdiff
path: root/wide_rotation.sh
blob: 333c854345a1a68c816b2ae904f568d700df2314 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash


# xfconf-query -c xfce4-desktop -m
# Start monitoring channel "xfce4-desktop":
# set: /backdrop/screen0/monitorDP1/workspace0/last-image


# look into types of parentheses, $(( )) is math for example
# shuf is a thing
# also xargs -r is a thing


SHORTCUTS=(
    'FUNCTION                     |     TERMINAL EQUIVALENT                  |     RECOMMENDED KEYBIND'
    '------------------------------------------------------------------------------------------'
    'Randomize Pape               |     pape.sh                              |     NUM-'
    'Notify-send Current Pape     |     pape.sh -n                           |     Ctrl+NUM-'
    'Toggle Pape Daemon           |     pape.sh -d                           |     Shift+NUM-'
    'Select Pape                  |     pape.sh -s                           |     Ctrl+Shift+NUM-'
)

current_desktop="/backdrop/screen0/monitorHDMI-2/workspace0"

current_pape=$(xfconf-query -c xfce4-desktop -p $current_desktop/last-image) # INVALIDATE DUPLICATES

select_flag=false
daemon_flag=false # SET TOGGLER WITH KILLALL/SPAWN

PAPES="$HOME/papes"
PAPE=""
DMENU_APPEARANCE="mononoki;11;#191919;#AAAAAA;#CC6600;#FFFFFF;Choose your pape:"

#E0E04B
#AAAA00

function rotation_daemon {
    while true; do
        xfconf-query -c xfce4-desktop -p $current_desktop/last-image -s "$(find ~/papes -type f -iregex '.*\.\(bmp\|gif\|jpg\|jpeg\|png\)$' | sort -R | head -1)"
        sleep 180
    done
}


while getopts "hnds" opt; do
    case $opt in
    h) echo -e "usage: $0 [-h help] [-d toggle daemon] [-s select]\n\nSuggested Keyboard Shortcuts:\n"; printf '%s\n' "${SHORTCUTS[@]}";  exit ;;            # PRINT HELP IN TERMINAL
    n) $HOME/stuf/scripts/notification_wrapper.sh "$( sed -r 's|^\/([^\/]+\/)+||g' <<< "$current_pape" )" "WIDEROT"; exit ;;     # NOTIFY-SEND QUEUE VIA MY OWN WRAPPER
    d) daemon_flag=true ;;
    s) select_flag=true ;;
    ?) echo "error: option -$OPTARG is not implemented"; exit ;;
    esac
done


for i in {1..7}
do
   declare "dm$i=$( cut -f$i -d';' <<< "$DMENU_APPEARANCE" )"     # CONVERT DMENU APPEARANCE STRIP INTO SEPARATE PARAMETERS
done


if $daemon_flag ; then
    if [[ $(pgrep -f "wide_rotation.sh -d" | wc -l) -ge 3 ]]; then
         $HOME/stuf/scripts/notification_wrapper.sh "$( pkill -o -f -e "wide_rotation.sh -d" )" "WIDEROT"
    else
        rotation_daemon </dev/null >/dev/null 2>&1 & disown
        $HOME/stuf/scripts/notification_wrapper.sh "$(pgrep -f "wide_rotation.sh -d" )" "WIDEROT"
    fi
    exit
fi


if $select_flag ; then

    # FIND EVERY DIRECTORY WITH AN AUDIO FILE IN IT AND PIPE IT INTO DMENU
    PAPE=$(find $PAPES -type f -iregex ".*\.\(bmp\|gif\|jpg\|jpeg\|png\)$" | grep -v "$current_pape" | sed -r "s|^\/([^\/]+\/)+||g" | sort --version-sort | uniq \
    | dmenu -fn "$([[ $(fc-match "$dm1" | grep "$dm1") ]] && fc-match -f %{family} "$dm1" || fc-match -f %{family} mono)-$dm2" -l 10 -i -nb "$dm3" -nf "$dm4" -sb "$dm5" -sf "$dm6" -p "$dm7" )

    [[ -n $PAPE ]] && echo $PAPE | sed -r "s|'|\\\'|g" | xargs -I{} find $PAPES -type f -iname "{}" | head -n 1 \
    | xargs -I{} xfconf-query -c xfce4-desktop -p $current_desktop/last-image -s  "{}"


else

    # RANDOMIZE IT
    # find "$IE" -type f | sed "s|^.*\.\/|$IE|g" | grep -vf "$IE/exceptions.txt" | findimagedupes -R -p /bin/feh -t 95% -
    xfconf-query -c xfce4-desktop -p $current_desktop/last-image -s "$(find $PAPES -type f -iregex '.*\.\(bmp\|gif\|jpg\|jpeg\|png\)$' | sort -R | head -1)"
fi