Skip to content

Commit 21716ef

Browse files
mahlzahnGusted
authored andcommitted
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: alecthomas/chroma#1174 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12562 Reviewed-by: Gusted <gusted@noreply.codeberg.org>
1 parent 05d784b commit 21716ef

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

modules/highlight/highlight.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ func Code(fileName, language, code string) (output template.HTML, lexerName stri
103103
cache.Add(fileName, lexer)
104104
}
105105

106-
return CodeFromLexer(lexer, code), formatLexerName(lexer.Config().Name)
106+
lexerName = formatLexerName(lexer.Config().Name)
107+
if lexerName == "Bash" {
108+
lexerName = "Shell"
109+
}
110+
111+
return CodeFromLexer(lexer, code), lexerName
107112
}
108113

109114
// 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
183188
}
184189

185190
lexerName := formatLexerName(lexer.Config().Name)
191+
if lexerName == "Bash" {
192+
lexerName = "Shell"
193+
}
186194

187195
iterator, err := lexer.Tokenise(nil, string(code))
188196
if err != nil {

modules/highlight/highlight_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ func TestFile(t *testing.T) {
5555
want: lines(""),
5656
lexerName: "YAML",
5757
},
58+
{
59+
name: "empty.sh",
60+
code: "",
61+
want: lines(""),
62+
lexerName: "Shell",
63+
},
5864
{
5965
name: "tags.txt",
6066
code: "<>",

tests/integration/linguist_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,13 @@ func TestLinguistSupport(t *testing.T) {
242242
t.Run("file source view", func(t *testing.T) {
243243
defer tests.PrintCurrentTest(t)()
244244

245-
assertFileLanguage(t, "/src/branch/main/foo.c?display=source", "Bash")
245+
assertFileLanguage(t, "/src/branch/main/foo.c?display=source", "Shell")
246246
})
247247

248248
t.Run("file blame view", func(t *testing.T) {
249249
defer tests.PrintCurrentTest(t)()
250250

251-
assertFileLanguage(t, "/blame/branch/main/foo.c", "Bash")
251+
assertFileLanguage(t, "/blame/branch/main/foo.c", "Shell")
252252
})
253253
})
254254

0 commit comments

Comments
 (0)