fix(ui): show "Shell" instead of "Bash" in headers of shell script files (#12562)

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 <gusted@noreply.codeberg.org>
This commit is contained in:
Robert Wolff 2026-05-14 22:33:51 +02:00 committed by Gusted
parent 05d784bb38
commit 21716ef31c
3 changed files with 17 additions and 3 deletions

View file

@ -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 {

View file

@ -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: "<>",

View file

@ -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")
})
})