~mil/f_scripts

f_scripts/scripts/f_theme -rwxr-xr-x 2.3 KiB
4d320ea0Miles Alan All scripts: unset strict_errexit to resolve regression with oil 0.11 27 days 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
72
73
74
#!/usr/bin/env osh
shopt -s strict:all; shopt --unset strict_errexit
DEP="terminus-font util-linux-misc"
DEC="Change the framebuffer theme (font & colors)"
DOC="
  Allows customizing your framebuffer's theme by setting the font, colors,
  and framebuffer rotation. Uses the setterm and setfont command line
  tools - so only applicable in the TTY / framebuffer. Also uses escape
  codes to make colors (true black / true white).

  Use the variables for \$F_THEME_FONT{SM,MD,LG} to set the fonts
  used for {sm,md,lg}{white,dark}.
"
VAR='
  F_THEME_FONTSM="/usr/share/consolefonts/ter-114n.psf.gz"
  F_THEME_FONTMD="/usr/share/consolefonts/ter-920n.psf.gz"
  F_THEME_FONTLG="/usr/share/consolefonts/ter-v32n.psf.gz"
'

fontchange() {
  local FONTS PICKED

  FONTS="$(ls -1 /usr/share/consolefonts/ | sed 's/.psf.gz//g' )"
  [ -p /tmp/fbp.fifo ] && echo -e "\b\fcancel\n$FONTS" > /tmp/fbp.fifo
  echo "$FONTS"
  echo "Pick a font:"
  read -r PICKED
  [ "$PICKED" = cancel ] && return
  setfont /usr/share/consolefonts/$PICKED.psf.gz
  [ -p /tmp/fbp.fifo ] && echo -e "\v" > /tmp/fbp.fifo
}

blackonwhite() {
  setterm -foreground black -background white --clear --store
  echo  -en "\e]P7ffffff"
  [ -p /tmp/fbp.fifo ] && echo -e "\v" > /tmp/fbp.fifo
}

whiteonblack() {
  setterm -foreground white -background black --clear --store
  echo  -en "\e]P7ffffff"
  [ -p /tmp/fbp.fifo ] && echo -e "\v" > /tmp/fbp.fifo
}

lgdark() { setfont $F_THEME_FONTLG; whiteonblack; }
mddark() { setfont $F_THEME_FONTMD; whiteonblack; }
smdark() { setfont $F_THEME_FONTSM; whiteonblack; }

lgwhite() { setfont $F_THEME_FONTLG; blackonwhite; }
mdwhite() { setfont $F_THEME_FONTMD; blackonwhite; }
smwhite() { setfont $F_THEME_FONTSM; blackonwhite; }

rotate() {
  [ -p /tmp/fbp.fifo ] && echo -e "\a" > /tmp/fbp.fifo
  echo "$(
    grep -q 1 /sys/class/graphics/fbcon/rotate && echo 0 || echo 1
  )" | sudo tee /sys/class/graphics/fbcon/rotate_all > /dev/null
  [ -p /tmp/fbp.fifo ] && echo -e "\v" > /tmp/fbp.fifo
}

main() {
  local RUN

  env | grep -q "^$(basename "$0" | tr '[a-z]' '[A-Z]')=" || eval "$VAR"

  while true; do
    OPTS="lgdark mddark smdark lgwhite mdwhite smwhite fontchange rotate"
    [ -p /tmp/fbp.fifo ] && { echo -e "\b\f\r"; echo "$OPTS" | tr " " "\n"; } > /tmp/fbp.fifo
    read -p "Choice ($OPTS)" RUN
    "$RUN"
  done
}

if [ -n "$1" ]; then "$@"; else main; fi