OSDN Git Service

new pidfile
[instantos/instantOS.git] / programs / instantdpi
1 #!/bin/bash
2
3 # apply instantOS dpi settings
4
5 DPI="$(iconf dpi)"
6
7 resetdpi() {
8     echo "resetting dpi"
9     sed -i '/^Xft\.dpi/d' ~/.Xresources
10     sed -i '/^st.font/d' ~/.Xresources
11 }
12
13 appendpi() {
14     echo "setting dpi to $DPI"
15     echo "Xft.dpi: $DPI" >>~/.Xresources
16     NEWDPI="$(echo "( $DPI / 96 ) * 15" | bc -l | grep -o '^[^\.]*')"
17     sed -i '/^st.font/d' ~/.Xresources
18     echo "st.font: Fira Code Nerd Font Mono:pixelsize=$NEWDPI:antialias=true:autohint=true" >>~/.Xresources
19     echo "st.font2: JoyPixels:pixelsize=$NEWDPI:antialias=true:autohint=true" >>~/.Xresources
20 }
21
22 if [ -z "$DPI" ]; then
23     resetdpi
24     exit
25 fi
26
27 [ "$DPI" -eq "$DPI" ] || exit
28
29 # resetting
30 if [ "$DPI" = "96" ]; then
31     resetdpi
32     exit
33 fi
34
35 if ! [ -e .Xresources ]; then
36     echo "initializing xresources"
37     touch ~/.Xresources
38     appendpi "$DPI"
39 else
40     if grep -q '^Xft.dpi' ~/.Xresources; then
41         resetdpi
42     fi
43     appendpi "$DPI"
44 fi