aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/theme-tour
blob: 3b4a4ce71b24ccad1ccf2e6b8de3f31ea5d6f535 (plain) (blame)
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
#!/bin/sh
# Show the themes in contrib/themes on a running session.
#
#   contrib/theme-tour                 spawn a session and cycle every theme
#   contrib/theme-tour slate           apply one to the session named below
#   SESSION=work contrib/theme-tour    ...to a different session
#
# One control-socket call per theme (`cmd theme`), which is the same thing a
# person does with one line of their config -- the tour used to copy a theme
# file over the session's config and wait for the watcher to notice, which
# demonstrated the watcher rather than the themes.
#
# THEME_DIR points the session at this repo's themes, so the tour shows what is
# in the checkout rather than what happens to be installed.
set -e
here=$(cd "$(dirname "$0")" && pwd)
bin="$here/../build/slosh"
SESSION=${SESSION:-themes}
CONF=${SLOSH_CONFIG:-/tmp/slosh-theme-tour.kdl}
DWELL=${DWELL:-4}

apply() {
  "$bin" -s "$SESSION" cmd "theme $1" >/dev/null
  printf '  %-10s %s\n' "$1" "$(sed -n '1s|// ||p' "$here/themes/$1.kdl")"
}

if ! "$bin" ls 2>/dev/null | grep -q "^$SESSION "; then
  printf 'theme_dir "%s"\ntheme_name "sl0p"\n' "$here/themes" >"$CONF"
  echo "starting a session called $SESSION..."
  SLOSH_CONFIG="$CONF" "$bin" -s "$SESSION" -- "${SHELL:-/bin/sh}" &
  sleep 1
fi

if [ -n "$1" ]; then
  [ -f "$here/themes/$1.kdl" ] || { echo "no such theme: $1"; exit 1; }
  apply "$1"
  exit 0
fi

echo "cycling every theme, ${DWELL}s each. ^C to stop wherever you like."
for t in "$here"/themes/*.kdl; do
  apply "$(basename "$t" .kdl)"
  sleep "$DWELL"
done