summarylogtreecommitdiffstats
path: root/qrcode
blob: 1cafee66a03cd80f1ad7ef64dc899a4c8fae0320 (plain)
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
#!/usr/bin/env bash
set -euo pipefail

if ! command -v qrencode &> /dev/null; then
    exit 1
fi

schema="utf8i"

# Detect if tty
if TTY="$(tty)"; then
    # Detect if true tty (not pty)
    if [[ "$TTY" =~ ^/dev/tty[0-9]+$ ]]; then
        # Detect current font from /etc/vconsole.conf
        if CURRENT_FONT="$(grep "^FONT=" /etc/vconsole.conf)"; then
            regex="^FONT=ter-([0-9])(.*)$"
            if [[ $CURRENT_FONT =~ $regex ]]; then
                CODEPAGES="${BASH_REMATCH[1]}"
                SIZE_STYLE="${BASH_REMATCH[2]}"
                if [ "$CODEPAGES" != "i" ]; then
                    # If not a font that supports the special characters needed for utf8i, set font to one that does
                    # If it fails, fallback to ANSI256
                    setfont "ter-i${SIZE_STYLE}" || schema="ANSI256"
                fi
            else
                # Unknown font, use ANSI256
                schema="ANSI256"
            fi
        fi

    fi
fi
qrencode "$1" -m 0 -t "$schema"