-
Notifications
You must be signed in to change notification settings - Fork 0
/
st_theme
executable file
·633 lines (582 loc) · 20.5 KB
/
st_theme
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
#!/usr/bin/env bash
# coding: utf-8
# we export all functions for fzf's subprocs - would not work when default shell is fish:
export SHELL=/bin/bash
alpha=1
confirmed=false
theme=
d_tmp="/tmp/st"
here="$(cd "$(dirname ${BASH_SOURCE[0]})"; pwd)"
export set_full_xrdb=false
pid=
pretty=
rel_alpha=
reset=false
sortby=
st_theme="$(basename "$0")"
url_b16_master="https://github.com/chriskempson/base16-schemes-source.git"
wid="$WINDOWID"
test -z "$wid" && { echo "No X11 WINDOWID" >/dev/stderr; exit 1; }
# contains function wininfos, setting $windir -
# required only for setting dir theme when started on hotkey
export wininfos="$HOME/bin/wininfos"
# when fzf is launched by hotkey -w is passed -> set differently. need to activate both
wid_me="$WINDOWID"
wid_other= # for transfers
d_cfg="$HOME/.config/st_theme"
export xrdb_template='
*foreground: ${forground:-$base05}
*cursorColor: ${cursorColor:-$base05}
*background: ${background:-$base00}
*color0: ${color00:-$base00}
*color1: ${color01:-$base08}
*color2: ${color02:-$base0B}
*color3: ${color03:-$base0A}
*color4: ${color04:-$base0D}
*color5: ${color05:-$base0E}
*color6: ${color06:-$base0C}
*color7: ${color07:-$base05}
*color8: ${color08:-$base03}
*color9: ${color09:-$base08}
*color10: ${color10:-$base0B}
*color11: ${color11:-$base0A}
*color12: ${color12:-$base0D}
*color13: ${color13:-$base0E}
*color14: ${color14:-$base0C}
*color15: ${color15:-$base07}
*color16: ${color16:-$base09}
*color17: ${color17:-$base0F}
*color18: ${color18:-$base01}
*color19: ${color19:-$base02}
*color20: ${color20:-$base04}
*color21: ${color21:-$base06}
*theme: $theme
*alpha: ${alpha:-1}
'
# ------------------------------------------------------------------------------- tools
function growl { dunstify -r "${growlid:-123454321}" "$st_theme" "$*"; unset growlid; }
#function growl { dunstify -t 10000 "$st_theme" "$*"; }
function notify { growl "$*" 2>/dev/null; }
function msg { [[ "$1" == "+n" ]] && { shift; notify "$*"; }; echo -e "$*"; }
function die { msg +n "ERR: $*"; exit 1; }
type dunstify 1>/dev/null 2>&1 || function growl { true; }
function h {
# action help display
test "$3" == "-H" -o "$3" == "-h" && echo "$1" && { \
test "$3" == "-h" -a -n "$2" && echo -e "\n$2" | sed -e 's/^ //g'; exit; }
}
function load {
test -e "$1" || return
set -a; source "$1"; set +a
}
function set_pid_from_wid {
[ -n "$pid" ] && return 0
pid="$(xprop -id $wid |grep WM_PID | cut -d ' ' -f 3)"
}
function load_theme_by_match {
# when assign is set, we assume match is not exact and show a little fzf chooser
# intended for use on the prompt, for the current window: e.g. st_theme set -t dark
local fn match="$1" showselector="${2:-}"
fn="$ST_THEMES_DIR/$match.config"
if [ -e "$fn" ]; then
load "$fn"
msg +n "Sourced $match"
test -n "$showselector" && theme="$match"
return
fi
test -z "$showselector" && { msg +n "Not found theme $fn"; return; }
action_show_inline_selector_for_match
test -e "$ST_THEMES_DIR/$match.config" || die "No match: $match."
export theme="$match"
#msg +n "Setting theme: $theme"
load_theme_by_match "$match"
}
function action_show_inline_selector_for_match {
h 'Shows a little in-terminal selector' '' "$@"
[[ ! -t 1 ]] && return
showit () { grep "$match" < "$ST_THEMES_DIR/index" | cut -d '|' -f 1; }
export -f showit
match="$( cd "$ST_THEMES_DIR"
ls *.config | cut -d . -f 1 | fzf \
-q "$match" \
--preview-window=up:1 \
--height=30% -1 -0 \
--preview="showit {}"
)"
test -z "$match" && exit
}
function source_theme_config {
# must first source the theme= indirection, THEN overlay with specific overwrites
# we could source 2 times or first eval the theme name like follows:
tc="$(cat "$1")"
local fx x=
eval "$(echo -e "$tc" | grep ^theme= | sed -e 's/theme=/x=/g')"
test -n "$x" && source_theme_by_match "$x"
eval "$tc"
}
function cfg_default_config {
echo "$d_cfg/${default_config:-"default_config"}" # config file settable
}
# ----------------------------------------------------------------------------- actions
function action_b16fetch {
h 'Downloads all base16 schemes from the master list' \
"We recursively down load from $url_b16_master" "$@"
test -e "base16" && die "The base16 folder already exists in $(pwd)"
git clone "$url_b16_master" base16 || die "Could not clone $url_b16_master"
mkdir -p "./base16/schemes"
nr="."
while read -r line; do
[[ "$line" == \#* ]] && continue
[[ -z "$line" ]] && continue
echo "$line" | grep http | grep ': ' >/dev/null || continue
n="${line%%: *}"
k="${line#*: }"
msg +n "Fetching $n"
git clone -q "$k" "./base16/schemes/$n"
nr="$nr."; test "$nr" == "$test_max_downloads" && break
done < "./base16/list.yaml"
all="$(find base16/schemes -print | grep .yaml)"
msg "$all"
msg +n "$(echo "$all" | wc -l) theme fetched. Convert them via \`$st_theme b16convert\`"
}
function action_b16convert {
h 'Converts fetched base16 scheme yaml files into xrdb files and sets \$ST_THEMES_DIR accordingly.' \
'Must be called from a directory containing a base16/schemes folder, e.g. created by b16fetch' "$@"
set -e
local d_o yml d_schemes="./base16/schemes"
d_o="$(pwd)/base16/output/$st_theme"
rm -f "$d_o/index"
mkdir -p "$d_o"
test -e "$d_schemes" || die "Missing $d_schemes. Run \`$st_theme b16fetch\`."
add () {
sed -e 's/: "/="#/g' < "$yml" | sed -e 's/scheme="#/scheme="/g' # yaml to shell
dn="$(dirname "$yml")"
echo -e "\nrepo='$(cd "$dn" && git remote get-url origin)'"
echo -e "filename='$fn'"
}
for yml in $(find "$d_schemes" -maxdepth 2 -print | grep .yaml); do
fn="$(basename "$yml" | cut -d '.' -f 1)"
fnf="$d_o/$fn.config"
add > "$fnf"
source "$fnf" || die "Cannot source $fnf"
#rgb contrast >> "$fnf"
rgb line "$fnf" | tee -a "$d_o/index" # adds the colored line to the index
done
cat "$d_o/index"
echo "Converted $(find "$d_o" | wc -l) themes into $d_o/index"
set +e
fn="$d_cfg/config.sh"
test "$ST_THEMES_DIR" == "$d_o" && return
msg "Adding ST_THEMES_DIR=$d_o to $fn. Ok? "
$confirmed || {
read -n1 q; msg
test "$q" == "q" -o "$q" == "n" && { msg unconfirmed; return; }
}
mkdir -p "$d_cfg"
touch "$fn" || die "Permission error on $fn"
cat "$fn" | grep -v "^ST_THEMES_DIR" > "$fn.n"
echo "ST_THEMES_DIR='$d_o'" > "$fn"
cat "$fn.n" >> "$fn"
rm -f "$fn.n"
msg "Written."
}
function cur_theme {
(
unset theme
load "$(cfg_default_config)"
load "$d_tmp/$wid/config"
test -n "$theme" && echo "$theme"
)
}
function action_list {
h='Format:
<base16 true colors as rgb/ansi> <scheme> | <filename> | <base16 hls values> | <misc>
misc: hsl diffs for bg and fg colors (e.g. for contrast)
=> Sort by bg luminance:
cat base16/output/st_theme/index | sort -t "|" -b -nk4.6 | cut -d "|"" -f 1
Args:
-s n: sort by name
-s l: sort by bg luminance
-r : sort reverse
-P : cut sorting infos (pretty)
'
h 'Show all themes, colored, sorted by contrast' "$h" "$@"
l="$(cat "$ST_THEMES_DIR/index")"
if [ -n "$sortby" ]; then
s="sort -t '|'"
$reset && s="$s -r" # reusing -r
[[ "$sortby" == "n" ]] && s="$s -k 2"
[[ "$sortby" == "l" ]] && s="$s -n -k 3.6"
l="$(echo -e "$l" | eval "$s")"
fi
test "$1" == '-fzf' && {
test -e "$d_tmp/filter-off" || {
test -n "$filter" && l="$(echo -e "$l" | grep -viE "$filter")"
}
t="$(cur_theme)"
test -n "$t" && l="original: $t\t$t\n$l"
l="$(echo -e "$l" | sed -e 's/|/\t/g')"
}
test "$pretty" == "true" && echo -e "$l" | cut -d '|' -f 1 || echo -e "$l"
}
function action_set {
h='ARGS:
-a: relative alpha (e.g. -a -0.1)
-c: custom arguments (e.g. -c alpha=0.1 -c "background=#0000FF")
-p: pid if known (will call xprop to find out)
-r: reset to defaults before applying increment
-t: theme name (e.g. "phd")
-w: window where to set to (must be an st window, we do not verify that)
'
h 'Set/change a theme directly' "$h" "$@"
local d # /tmp/st/<wid>
local fn_db="$d_cfg/xrdb_template"
local cli_theme="$theme" # must be from cli or fzf, not yet loaded old config
unset theme # must be from config
xdomode=focus # make X server/wm(?) run the rendering
prepare_tmp_wid_dir () {
# make sure our pid is matching its pid file, X is reusing windowids a lot:
d="$d_tmp/$wid"
test -e "$d" || mkdir -p "$d"
set_pid_from_wid
test "x$(cat "$d/pid" 2>/dev/null)" == "x$pid" && return
rm -f "$d"/*; echo "$pid" > "$d/pid"
}
load_last_config () {
load "$d/config"
}
load_default_config_if_reset_or_new () {
[ "$reset" == "true" ] || [ -z "$theme" ] && load "$(cfg_default_config)"
}
load_theme_on_theme_change () {
$set_full_xrdb || {
test -z "$cli_theme" && return
test "$cli_theme" == "$theme" && return
}
load_theme_by_match "$cli_theme" theme # only when cli theme is set we fzf
}
load_cli_config () {
local fn="$d/custom"
touch "$fn"
# keep old ones, when they are not overwritten:
while read line; do
k="$(echo "$line" | cut -d = -f 1)"
test -z "$k" && continue
echo "$custom" | grep "$k=" && continue
echo "$line" >> "$fn.tmp"
done < "$fn"
# theme itself is never just a custom value:
echo -e "$custom" | grep -v 'theme=' >> "$fn.tmp"
mv "$fn.tmp" "$fn"
# previous custom values are preserved - except on theme change, when they had
# been deleted
load "$fn"
}
apply_relative_alpha () {
test -z "$rel_alpha" && return
xdomode=activate
alpha=$(python -Ssc "print(round(${alpha:-1}+$rel_alpha, 2))")
}
write_new_config () {
local fn="$d/config"
export theme alpha
#env |grep -E '^base0|^alpha=|^color|^theme=' | grep -v '=$' > "$fn"
env |grep -E '^alpha=|^theme=' | grep -v '=$' > "$fn"
sed -e '/^alpha=/d' -e '/^theme=/d' "$d/custom" >> "$fn"
}
prepare_xrdb_template () {
test -e "$fn_db" && return
mkdir -p "$d_cfg"
echo -e "$xrdb_template" > "$fn_db" || die "No permissions on $fn_db"
}
render_new_xrdb () {
# evaluates the xrdb template, i.e. inserts current (not exported) values:
# the grep removes unset values:
local tmpl fn="$1"
tmpl="$(cat "$fn_db")"
eval "echo -e \"$tmpl\" \
| sed -e 's/*/\n*/g' \
| grep -v -E ':(\ )*$'" \
| sed -e '/^$/d' > "$fn"
}
load_new_xrdb () {
local m
m="$(grep theme < "$d/xrdb" | xargs)"
m="$m\n$(grep alpha < "$d/xrdb" | xargs)"
m="wid: $wid pid: $pid\n$m"
msg +n "$m"
kill -1 "$pid"
test "$wid" == $WINDOWID && return
xdotool "window$xdomode" "$wid" # alpha changes require activate
xdotool "window$xdomode" "$WINDOWID"
}
prepare_tmp_wid_dir
load_last_config
load_default_config_if_reset_or_new
load_theme_on_theme_change
load_cli_config
apply_relative_alpha
write_new_config
prepare_xrdb_template
render_new_xrdb "$d/xrdb"
load_new_xrdb
}
function action_select {
h 'Start fzf theme selector (alias: s)' "" "$@"
local st a n fn binds header
sortby="n"
backup_current_settings () {
local fn="$d_tmp/$wid/config"
test -e "$fn" && cp "$fn" "$fn.backup"
}
export_functions_and_vars () {
# export all for the on-change subprocess
for f in $(grep '^function ' < "$0" | cut -d ' ' -f 2); do eval export -f "$f"; done
export -f fzf_on_select revert set_dir_theme
export d_tmp d_cfg here pid reset st_theme wid wid_me
}
add_cmd () {
header="$header,$1"; binds="$binds,$2"
}
define_fzf_binds () {
export binds=""
header="Enter: Make default, ctrl-k:up"
add_cmd "P:transfer" "P:execute("$0" transfer -w "$wid")"
add_cmd "R:revert" "R:execute-silent(revert)"
add_cmd "D:set_dir" "D:execute-silent(set_dir_theme)"
for a in "left -0.05" "right 0.05"
do
d=${a%% *}; n="${a##* }"
add_cmd "$d" "$d:execute-silent(rel_alpha=$n; action_set )"
done
header="$header:alpha"
binds="$( echo "$binds" | cut -d , -f2-)"
}
fzf_on_select () {
#notify-send "1: $1."
q="${2:-x}"
if [ -z "$(echo "$q" | sed -e 's/[+-]*[0-9]*[.]*[0-9]*//g')" ]; then
local fn="$d_tmp/$wid/config"
grep -v "^alpha=" "$fn" > "$fn.t"
echo "alpha=$q" >> "$fn.t"
mv "$fn.t" "$fn"
source "$fn"
touch $d_tmp/alphamode
else
rm -f $d_tmp/alphamode
theme="$(echo -e "$1" | cut -d $'\t' -f 2 | xargs)"
notify "selected: $theme"
fi
action_set
}
set_as_default_config () {
theme="$(cur_theme)"
set_full_xrdb=true # force to create full xrdb with this:
action_set -p "$pid" -w "$wid"
cp "$d_tmp/$wid/config" "$(cfg_default_config)"
local X="$d_cfg/Xresources"
cp "$d_tmp/$wid/xrdb" "$X"
xrdb -load "$X"
msg +n "Written and loaded into Xserver: $(cfg_default_config) $X"
}
revert () {
local fn="$d_tmp/$wid/config"
test -e "$fn.backup" || msg +n "No backup"
cp "$fn.backup" "$fn"
growlid=101; growl "Reverting to backup"
source "$d_tmp/$wid/config"
set_full_xrdb=true # force to create full xrdb with this:
action_set -p "$pid" -w "$wid"
}
set_dir_theme () {
fn="$d_cfg/directory_themes"
if [ "$wid" == "$wid_me" ]; then
windir="$(pwd)"
else
source "$wininfos"
wininfos "$wid"
fi
test -z "$windir" && { msg +n "Require \$windir"; exit 1; }
test -e "$fn" || touch "$fn"
grep -v "^$windir:" < "$fn" > "$fn.tmp"
load "$(cfg_default_config)"
load "$d_tmp/$wid/config"
d="$windir:$theme:${alpha:-1}"
echo "$d" >> "$fn.tmp"
mv "$fn.tmp" "$fn"
growlid=101; growl "Have set<br>$d into<br>$fn"
}
set_pid_from_wid
backup_current_settings
export_functions_and_vars
define_fzf_binds
local themes hd='' b='' h=''
test "$wid" == "$wid_me" && h="--height=50%"
while true
do
# filter is an optional config file val
themes="$(action_list -fzf)"
test -e "$d_tmp/alphamode" || {
[ -n "$filter" ] && {
if [ -e "$d_tmp/filter-off" ]; then
hd=",F:filter-on" b="touch '$d_tmp/filter-on'"
else
hd=",F:filter-off" b="touch $d_tmp/filter-off"
fi
b=",F:execute-silent($b)+abort"
rm -f "$d_tmp/filter-"*
}
}
echo -e "$themes" | fzf \
$h \
--query="$theme" \
--preview-window=up:10% \
--delimiter='\t' \
--with-nth=1 \
--no-info \
--ansi \
--color='bg:232,marker:196' \
--bind="$binds$b" \
--header="$header$hd" \
--preview="fzf_on_select {} {q} &" > /dev/null
ret=$?
test -e "$d_tmp/alphamode" && {
[ "$ret" == 130 ] && exit "$ret" # entered alpha, hit escape -> out
continue # entered alpha hit return -> back to color selection
}
test -e "$d_tmp/filter-"* && continue
[ "$ret" == "0" ] && set_as_default_config
exit "$ret"
done
}
function action_transfer {
h 'Transfers config to other window' '' "$@"
local ow fn="$d_tmp/$wid/config"
test -e "$fn" || "$0" set -w "$wid"
t="$(cur_theme)"
configure_other () {
d="$d_tmp/$1"
mkdir -p "$d"; rm -f "$d/*"
cp "$fn" "$d/config"
"$0" set -w "$1" -f -t "$t"
}
test -n "$wid_other" && { configure_other "$wid_other"; return $?; }
while true
do
wid_other="$(xdotool selectwindow)"
test -z "$wid_other" -o "$wid_other" == "$ow" && return
ow="$wid_other"
configure_other "$ow"
done
}
function usage {
actions_help () {
actions="$( grep "^function action_" < "$0" \
| cut -d '_' -f 2- \
| cut -d ' ' -f 1 )"
for a in $actions; do test "$a" != "help" && {
echo -en "\x1b[1m$a\x1b[0m\x1b[1000D\x1b[12C"; $0 "$a" -H; }
done
}
echo -e "\x1b[1mTheme Selector For Suckless Terminal (st)\x1b[0m
USAGE: $st_theme [action] [switches]
ACTIONS (default: start fzf selector):
$(actions_help)
Default action: Start fzf selector on windowid given via switch -w
$st_theme <action name> -h: Detailed help on actions.
" | sed -e 's/^ //g'
exit 0
}
function source_config {
test -e "$d_cfg/config.sh" || return
set -a; source "$d_cfg/config.sh"; set +a
}
function main {
test -z "$1" && usage
test "$1" == "-D" && { d_cfg="$2"; shift 2; } # for tests, to deliver a test config
source_config
[[ "$1" == -* ]] || { action="$1"; shift; }
while getopts "F:HPa:c:fho:p:rs:t:w:y" opt; do
case ${opt} in
h) [[ -n "$action" ]] || usage
;;
F) filter="$OPTARG"
;;
P) pretty=true
;;
a) rel_alpha="$OPTARG"
;;
c) custom="$custom\n$OPTARG"
;;
f) set_full_xrdb=true
;;
o) wid_other="$OPTARG"
;;
p) pid="$OPTARG"
;;
r) reset=true
;;
s) sortby="$OPTARG"
;;
t) theme="$OPTARG"
;;
y) confirmed=true;
;;
w) wid="$OPTARG"
;;
*) ;;
esac
done
[ -z "$action" ] || [ "$action" == "s" ] && action=select
test -z "action_$action" && usage
"action_$action" "$@"
}
# ------------------------------------------------------------------------ Python Tools
# we keep that at the end to not confuse single ft colorscheme vim setups
function rgb {
python -sSc "if 1:
import colorsys as C
rgb = lambda hexc: tuple(int(hexc[1:][i:i+2], 16) for i in (0, 2, 4))
spec = {}
with open('$2') as fd: s = fd.read()
exec(s, {}, spec)
def print_colored_lines():
R = '\033[0m'
# add the fzf ansi colored line to the index:
b16s = [hex(i).replace('x', '').upper() for i in range(0, 16)]
spec.update({'base%s_rgb' % k: rgb(spec['base%s' % k]) for k in b16s})
spec.update({'base%s_hsl' % k: C.rgb_to_hls(*spec['base%s_rgb' % k]) for k in b16s})
spec['bgfgdiff'] = [spec['base00_hsl'][i] - spec['base05_hsl'][i] for i in range(3)]
T = '\033[48;2;%s;%s;%sm '
cut = lambda n, s: spec[s].ljust(n)[:n]
l = ''.join([T % spec['base%s_rgb' % k] for k in b16s])
l += R + ' ' + T % spec['base00_rgb']
l += (T.replace('[48', '[38') % spec['base05_rgb'])[:-2]
l += cut(30, 'scheme') + R + ' | ' + cut(30, 'filename') + ' | '
l += '|'.join(['%.2f,%.2f,%.2f' % spec['base%s_hsl' % k] for k in b16s])
l += '| %.2f,%.2f,%.2f' % tuple(spec['bgfgdiff'])
print(l)
print_colored_lines()
"
}
# function set_x_resources_inplace {
# # for what it's worth:
# # this would replace theme values into an existing resources filename
# # leaving other values intact. $1: Theme values, $2 Xresources file
# python -Ssc "if 1:
# x='$1'; X=open('$2').read().splitlines()
# xind = {k.split(': ', 1)[0]: i for k, i in zip(X, range(len(X)))}
# x = open(x).read().splitlines()
# while x:
# kv = x.pop(0)
# if not kv.startswith('*'): continue
# k, v = kv.split()
# pos = xind.get(k[:-1])
# if not pos:
# X.append(kv)
# else:
# X[pos] = kv
# open('$2', 'w').write('\n'.join(X))
# "
# }
main "$@"