aboutsummaryrefslogtreecommitdiff
path: root/tools/shader_watcher.sh
blob: d32285d3f2338ed04b13d3807fc4b149efb52f35 (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
#!/usr/bin/env bash
#  ____  _   _    _    ____  _____ ____  
# / ___|| | | |  / \  |  _ \| ____|  _ \ 
# \___ \| |_| | / _ \ | | | |  _| | |_) |
#  ___) |  _  |/ ___ \| |_| | |___|  _ < 
# |____/|_| |_/_/   \_\____/|_____|_| \_\
#                                        
# __        ___  _____ ____ _   _ _____ ____  
# \ \      / / \|_   _/ ___| | | | ____|  _ \ 
#  \ \ /\ / / _ \ | || |   | |_| |  _| | |_) |
#   \ V  V / ___ \| || |___|  _  | |___|  _ < 
#    \_/\_/_/   \_\_| \____|_| |_|_____|_| \_\
#                                             
# This program require xdotool to communicate
# with the window.

wai=$(dirname $(readlink -f "$0")) # Current script directory


refresh() {
    wid=$(xdotool search --name 'SFML/OpenGL Ray Marching')
    [ ! -z "$wid" ] && xdotool key --window "$wid" R
}

usage() {
    echo "Usage: $0 [options]"
    echo "Options:"
    echo " --every <time> Refresh shader every <time> seconds"
    exit 1
}

[ $# -ne 2 ] && [ $# -ne 0 ] && usage

if [ $# -eq 2 ] && [ $1 == "--every" ]
then
    shift
    time=$1
    while [ true ]
    do
        sleep $time
        refresh
    done
else

    while [ true ]
    do
    ls $wai/../resources/shaders/*.glsl | entr -pd -s 'kill $PPID'
    refresh
    done
fi