From 21716ef31c8985b08fbb453fecf678f1361d2738 Mon Sep 17 00:00:00 2001 From: Robert Wolff Date: Thu, 14 May 2026 22:33:51 +0200 Subject: [PATCH] fix(ui): show "Shell" instead of "Bash" in headers of shell script files (#12562) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a quick hack to show "Shell" instead of "Bash" which is an upstream issue that likely won’t be fixed. This makes it also slightly more consistent with the repository’s language statistics, which show "Shell", too. Closes: Codeberg/Community#2627 Related: https://github.com/alecthomas/chroma/pull/1174 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12562 Reviewed-by: Gusted --- modules/highlight/highlight.go | 10 +++++++++- modules/highlight/highlight_test.go | 6 ++++++ tests/integration/linguist_test.go | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/highlight/highlight.go b/modules/highlight/highlight.go index ba3ba479d5..71318c0f69 100644 --- a/modules/highlight/highlight.go +++ b/modules/highlight/highlight.go @@ -103,7 +103,12 @@ func Code(fileName, language, code string) (output template.HTML, lexerName stri cache.Add(fileName, lexer) } - return CodeFromLexer(lexer, code), formatLexerName(lexer.Config().Name) + lexerName = formatLexerName(lexer.Config().Name) + if lexerName == "Bash" { + lexerName = "Shell" + } + + return CodeFromLexer(lexer, code), lexerName } // CodeFromLexer returns a HTML version of code string with chroma syntax highlighting classes @@ -183,6 +188,9 @@ func File(fileName, language string, code []byte) ([]template.HTML, string, erro } lexerName := formatLexerName(lexer.Config().Name) + if lexerName == "Bash" { + lexerName = "Shell" + } iterator, err := lexer.Tokenise(nil, string(code)) if err != nil { diff --git a/modules/highlight/highlight_test.go b/modules/highlight/highlight_test.go index ed5d190764..96af9ecacb 100644 --- a/modules/highlight/highlight_test.go +++ b/modules/highlight/highlight_test.go @@ -55,6 +55,12 @@ func TestFile(t *testing.T) { want: lines(""), lexerName: "YAML", }, + { + name: "empty.sh", + code: "", + want: lines(""), + lexerName: "Shell", + }, { name: "tags.txt", code: "<>", diff --git a/tests/integration/linguist_test.go b/tests/integration/linguist_test.go index 06ff1bd22f..01ffae5069 100644 --- a/tests/integration/linguist_test.go +++ b/tests/integration/linguist_test.go @@ -242,13 +242,13 @@ func TestLinguistSupport(t *testing.T) { t.Run("file source view", func(t *testing.T) { defer tests.PrintCurrentTest(t)() - assertFileLanguage(t, "/src/branch/main/foo.c?display=source", "Bash") + assertFileLanguage(t, "/src/branch/main/foo.c?display=source", "Shell") }) t.Run("file blame view", func(t *testing.T) { defer tests.PrintCurrentTest(t)() - assertFileLanguage(t, "/blame/branch/main/foo.c", "Bash") + assertFileLanguage(t, "/blame/branch/main/foo.c", "Shell") }) })