summaryrefslogtreecommitdiff
path: root/cgit/syntax-highlighting.dash
diff options
context:
space:
mode:
Diffstat (limited to 'cgit/syntax-highlighting.dash')
-rwxr-xr-xcgit/syntax-highlighting.dash28
1 files changed, 28 insertions, 0 deletions
diff --git a/cgit/syntax-highlighting.dash b/cgit/syntax-highlighting.dash
new file mode 100755
index 0000000..9db14f9
--- /dev/null
+++ b/cgit/syntax-highlighting.dash
@@ -0,0 +1,28 @@
+#!/usr/bin/dash
+
+# This script requires a shell supporting the ${var##pattern} syntax.
+# It is supported by at least dash and bash, however not by busybox.
+#
+# 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 variables
+BASENAME="$1"
+EXTENSION="${BASENAME##*.}"
+
+# Use .txt as a sensible default format
+[ "${BASENAME}" = "${EXTENSION}" ] && EXTENSION=txt
+[ -z "${EXTENSION}" ] && EXTENSION=txt
+
+# Map Makefile and Makefile.* to .mk
+[ "${BASENAME%%.*}" = "Makefile" ] && EXTENSION=mk
+
+# This is for version 3 and above of the "highlight" package
+exec highlight --force -f -I -O xhtml -S "$EXTENSION" 2>/dev/null