From 77981e7b1d3ae10ac3659606033eb1c5e4fdd815 Mon Sep 17 00:00:00 2001 From: Niclas Overby Date: Sat, 14 Mar 2026 11:19:17 +0100 Subject: [PATCH] appview/pages: detect syntax highlighting from shebang Fall back to parsing the shebang line for extensionless scripts, enabling highlighting for files like nushell/python/bash scripts that lack a file extension. Signed-off-by: Niclas Overby --- appview/pages/funcmap.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/appview/pages/funcmap.go b/appview/pages/funcmap.go index 7a2ed11c..38f1b359 100644 --- a/appview/pages/funcmap.go +++ b/appview/pages/funcmap.go @@ -294,6 +294,19 @@ func (p *Pages) funcMap() template.FuncMap { ) lexer := lexers.Get(filepath.Base(path)) + if lexer == nil { + if firstLine, _, ok := strings.Cut(content, "\n"); ok && strings.HasPrefix(firstLine, "#!") { + // extract interpreter from shebang (handles "#!/usr/bin/env nu", "#!/usr/bin/nu", etc.) + fields := strings.Fields(firstLine[2:]) + if len(fields) > 0 { + interp := filepath.Base(fields[len(fields)-1]) + lexer = lexers.Get(interp) + } + } + } + if lexer == nil { + lexer = lexers.Analyse(content) + } if lexer == nil { lexer = lexers.Fallback } -- 2.51.2