]> gitweb.ps.run Git - ps-cgit/blobdiff - filters/syntax-highlighting.sh
Merge branch 'lh/panel'
[ps-cgit] / filters / syntax-highlighting.sh
index 999ad0ce3d07f00a6e6d0cc8999502dd9a5e96c4..6283ce92efc62e9cf63d2bd20486af43bec7b489 100755 (executable)
@@ -3,6 +3,10 @@
 # tree-view by refering to this file with the source-filter or repo.source-
 # filter options in cgitrc.
 #
+# This script requires a shell supporting the ${var##pattern} syntax.
+# It is supported by at least dash and bash, however busybox environments
+# might have to use an external call to sed instead.
+#
 # Note: the highlight command (http://www.andre-simon.de/) uses css for syntax
 # highlighting, so you'll probably want something like the following included
 # in your css file (generated by highlight 2.4.8 and adapted for cgit):
 # table.blob .kwb  { color:#830000; }
 # table.blob .kwc  { color:#000000; font-weight:bold; }
 # table.blob .kwd  { color:#010181; }
+#
+# The following environment variables can be used to retrieve the configuration
+# of the repository for which this script is called:
+# CGIT_REPO_URL        ( = repo.url       setting )
+# CGIT_REPO_NAME       ( = repo.name      setting )
+# CGIT_REPO_PATH       ( = repo.path      setting )
+# CGIT_REPO_OWNER      ( = repo.owner     setting )
+# CGIT_REPO_DEFBRANCH  ( = repo.defbranch setting )
+# CGIT_REPO_SECTION    ( = section        setting )
+# CGIT_REPO_CLONE_URL  ( = repo.clone-url setting )
+#
+
+# store filename and extension in local vars
+BASENAME="$1"
+EXTENSION="${BASENAME##*.}"
+
+# map Makefile and Makefile.* to .mk
+[ "${BASENAME%%.*}" == "Makefile" ] && EXTENSION=mk
 
-case "$1" in
-       *.c)
-               highlight -f -I -X -S c
-               ;;
-       *.h)
-               highlight -f -I -X -S c
-               ;;
-       *.sh)
-               highlight -f -I -X -S sh
-               ;;
-       *.css)
-               highlight -f -I -X -S css
-               ;;
-       *)
-               highlight -f -I -X -S txt
-               ;;
-esac
+exec highlight --force -f -I -X -S $EXTENSION 2>/dev/null