aboutsummaryrefslogtreecommitdiffstats
path: root/cgit/syntax-highlighting.sh
blob: 7f8b944bf88f681d7091cad763e4675f1f9c210d (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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash

BASENAME="$1"
EXTENSION="${BASENAME##*.}"
TABSTOP="4"

if [ -z "${EXTENSION}" ] || [ "${BASENAME}" = "${EXTENSION}" ]; then
    EXTENSION=txt
fi

while \
    [ "${EXTENSION}" = "in" ] || \
    [ "${EXTENSION}" = "inc" ] || \
    [ "${EXTENSION}" = "filters" ] || \
    [ "${EXTENSION}" = "template" ]; do
    BASENAME="${BASENAME%.*}"
    EXTENSION="${BASENAME##*.}"
done

case "${EXTENSION}" in
    *project)                           EXTENSION=xml  ;; # Eclipse
    anjuta)                             EXTENSION=xml  ;; # Anjuta
    etspec|galview)                     EXTENSION=xml  ;; # Evolution
    schemas)                            EXTENSION=xml  ;; # GConf
    ui|glade*)                          EXTENSION=xml  ;; # Glade
    page)                               EXTENSION=xml  ;; # Mallard
    *proj|*props)                       EXTENSION=xml  ;; # MS Visual Studio
    policy)                             EXTENSION=xml  ;; # polkit
    doap)                               EXTENSION=xml  ;; # project description
    client)                             EXTENSION=xml  ;; # Telepathy
    rdf|omf)                            EXTENSION=xml  ;;
    convert)                            EXTENSION=ini  ;; # dconf
    service)                            EXTENSION=ini  ;; # D-BUS
    desktop)                            EXTENSION=ini  ;; # Launcher
    socket|device|mount|automount)      EXTENSION=ini  ;; # Systemd
    swap|target|path)                   EXTENSION=ini  ;; # Systemd
    timer|snapshot|slice|scope)         EXTENSION=ini  ;; # Systemd
    ac|m4)                              EXTENSION=sh   ;; # Autoconf
    po|pot)                             EXTENSION=sh   ;; # Gettext
    dirs)                               EXTENSION=sh   ;; # user-dirs.dirs
    install)                            EXTENSION=sh   ;; # Arch Linux PKGBUILD
    am)                                 EXTENSION=mk   ;; # Automake
    p)                                  EXTENSION=c    ;; # MapleBBS
    xpm)                                EXTENSION=c    ;;
    s)                                  EXTENSION=asm  ;;
    rules)                              EXTENSION=js   ;; # polkit
    json)                               EXTENSION=js   ;;
    ru)                                 EXTENSION=rb   ;; # config.ru
esac

case "${BASENAME%%.*}" in
    BSDmakefile)                        EXTENSION=mk   ;; # BSD make
    GNUmakefile)                        EXTENSION=mk   ;; # GNU make
    Makefile|makefile)                  EXTENSION=mk   ;; # Make
    Makevars)                           EXTENSION=mk   ;;
    configure)                          EXTENSION=sh   ;; # Autoconf
    PKGBUILD)                           EXTENSION=sh   ;; # Arch Linux PKGBUILD
    bashrc|bash_login|bash_profile)     EXTENSION=sh   ;; # Bash login script
    bash_logout)                        EXTENSION=sh   ;; # Bash logout script
    bash_include)                       EXTENSION=sh   ;;
    ebuild)                             EXTENSION=sh   ;; # Gentoo ebuild
    pkg-install|pkg-deinstall)          EXTENSION=sh   ;; # FreeBSD ports
    pkg-req|pkg-plist)                  EXTENSION=sh   ;; # FreeBSD ports
    rc)                                 EXTENSION=sh   ;; # FreeBSD rc
    kshrc)                              EXTENSION=sh   ;; # ksh script
    zshrc)                              EXTENSION=sh   ;; # zsh script
    login|cshrc|tcshrc)                 EXTENSION=tcsh ;; # tcsh script
    POTFILES)                           EXTENSION=ini  ;; # Gettext
    patch-*)                            EXTENSION=diff ;; # FreeBSD ports
    vimrc)                              EXTENSION=vim  ;; # vim script
    vimadd)                             EXTENSION=vim  ;;
    Gemfile|Rakefile)                   EXTENSION=rb   ;;
esac

case "${CGIT_REPO_NAME}" in
    taiwan-online-judge*) TABSTOP=8 ;;
    *) TABSTOP=4 ;;
esac

HIGHLIGHT=(
    highlight --force -f -I --inline-css
    -s edit-gedit -O xhtml
    -t "${TABSTOP}" -S "${EXTENSION}"
)

case "${CGIT_REPO_NAME}" in
    *bbs|maple3-itoc)
        iconv -c -f Big5 -t UTF-8 2>/dev/null | "${HIGHLIGHT[@]}" 2>/dev/null
        ;;
    *)
        exec "${HIGHLIGHT[@]}" 2>/dev/null
        ;;
esac