forked from alphapapa/org-ql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo-org-ql-view-dispatch.sh
executable file
·166 lines (139 loc) · 3.04 KB
/
demo-org-ql-view-dispatch.sh
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
# NOTE: Run "setxkbmap us" before running. See https://github.com/jordansissel/xdotool/issues/49
# NOTE: <f1> should be bound to this function in the Emacs window, like this:
# (global-set-key [f1]
# (defun gif-screencast-start-or-stop ()
# (interactive)
# (if gif-screencast-mode
# (progn
# (gif-screencast-stop)
# (setq gc-cons-threshold gc-cons-threshold-original))
# (setq gc-cons-threshold-original gc-cons-threshold)
# (setq gc-cons-threshold (* 1024 1024 500))
# (gif-screencast))))
# * Functions
function ensure_window_name {
if ! [[ $(xdotool getwindowfocus getwindowname) = $1 ]]
then
echo "Wrong window!" >&2
exit 1
fi
}
function key {
xdotool key "$@"
}
function input {
raw_input "$@"
# Correct for Helm's input idle delay by sending extra commands to
# make the screenshots be taken. Not sure why two are necessary,
# but they seem to be.
key ctrl+p
sleep 0.26
key ctrl+p
}
function raw_input {
xdotool type --delay 200 "$@"
}
function view-dispatch {
key v
sleep 2
}
function view-refresh {
key r
sleep 2
}
function clear-input {
key ctrl+a ctrl+k
sleep 0.5
}
function set-field {
key $1
shift
sleep 1
clear-input
raw_input "$@"
sleep 1
key Return
sleep 1
}
function set-field-with-unique-completion {
# "$@" should be a unique completion.
key $1
shift
sleep 0.5
clear-input
key Tab
sleep 0.5
raw_input "$@"
key Tab
sleep 0.75
key Return
sleep 1
}
function complete-in-steps {
# Assumes input is clear.
key Tab
sleep 0.75
key Tab
sleep 0.75
for s in "$@"
do
raw_input "$s"
key Tab
sleep 0.75
done
sleep 1
}
# * Script
# No matter what I try, xdotool is not working properly to focus/raise/select
# a window. And for some bizarre reason, the "xdotool selectwindow" command
# outputs a completely different window ID than "xdotool search" outputs. In
# fact, the window ID it outputs does not even appear in the output of
# "xprop" for that window. I have no idea where it's getting that ID.
# So rather than cleanly selecting the proper window in the script, we have to
# do a hacky workaround by sleeping and checking the name of the active
# window.
sleep 3
ensure_window_name "data.org"
# Start gif-screencast
key F1
sleep 2
# M-x org-ql-view RET, TAB, Ov TAB, Ag TAB, RET
key alt+x
sleep 0.2
raw_input "org-ql-view"
sleep 1
key Return
sleep 1
complete-in-steps Ov Ag
key Return
sleep 2
# Edit view.
view-dispatch
set-field t "Space-related"
set-field q "tags:space,spaceship"
set-field-with-unique-completion g pri
view-refresh
# Save query
view-dispatch
key ctrl+s
sleep 1
key Return
sleep 2
# New query: Ambition
view-dispatch
set-field t Ambition
set-field q "category:ambition"
set-field s "priority"
set-field g "parent"
view-refresh
view-dispatch
set-field t "Upcoming: ambition"
set-field g ts
view-refresh
# Save view.
view-dispatch
key ctrl+s
sleep 0.75
key Return
key F1