~tardypad/dotfiles

ref: 03a818bd23c8c8c19b661d564661f33ee1ce2547 dotfiles/files/scripts/shell/presentation-mode -rwxr-xr-x 1.0 KiB
03a818bd — Damien Tardy-Panis Less uses lesskey file directly in XDG config folder 2 months ago
                                                                                
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
#!/bin/sh

init_variables() {
  COMMAND=${0##*/}

  FILE_PATH="${XDG_RUNTIME_DIR:-/tmp}/presentation_mode"

  ACTION='status'
}

parse_command_line() {
  [ -z "$1" ] || ACTION="$1"
}

validate_command_line() {
  if [ "${ACTION}" != 'enable' ] \
     && [ "${ACTION}" != 'disable' ] \
     && [ "${ACTION}" != 'toggle' ] \
     && [ "${ACTION}" != 'status' ]; then
    exit_error "Invalid action '${ACTION}'"
  fi
}

exit_error() {
  [ -z "$1" ] || echo "${COMMAND}: $1"
  exit 1
} >&2

pres_enable() {
  swaymsg -q bar mode invisible

  touch "${FILE_PATH}" \
    && update_i3blocks
}

pres_disable() {
  swaymsg -q bar mode dock

  rm -f "${FILE_PATH}" \
    && update_i3blocks
}

update_i3blocks() {
  pkill -x -RTMIN+10 i3blocks
}

pres_status() {
  if is_pres_enabled; then
    echo 'enabled'
  else
    echo 'disabled'
  fi
}

pres_toggle() {
  if is_pres_enabled; then
    pres_disable
  else
    pres_enable
  fi
}

is_pres_enabled() {
  [ -f "${FILE_PATH}" ]
}

init_variables
parse_command_line "$@"
validate_command_line

"pres_${ACTION}"