From 52763e0205f00b9b4f388e9f994aebe0fa0b41b5 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Fri, 20 Mar 2026 21:04:26 -0700 Subject: [PATCH 1/6] feat: add tclsh, wish, and expect shebang detection for Tcl syntax Add first_line_match to the Tcl syntax definition via a patch file, enabling automatic Tcl highlighting for scripts with tclsh, wish, or expect shebangs. Fixes #3513 --- CHANGELOG.md | 1 + assets/patches/Tcl.sublime-syntax.patch | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 assets/patches/Tcl.sublime-syntax.patch diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fc4e54e..3682bb82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ## Features - Preserve `--diff` change markers and snip separators when `--plain` is set. Closes #3630, see #3643 (@mvanhorn) +- Add shebang-based detection for Tcl (`tclsh`, `wish`) and Expect (`expect`) scripts, see #3513 (@mvanhorn) - Added support for `hidden_file_extensions` from `.sublime-syntax` files, see #3613 (@Matei02355) - Add word wrapping mode via `--wrap=word`, see #3597 (@veeceey) - Support configuring `--terminal-width` via `BAT_WIDTH`, see #3679 (@officialasishkumar) diff --git a/assets/patches/Tcl.sublime-syntax.patch b/assets/patches/Tcl.sublime-syntax.patch new file mode 100644 index 00000000..487a1841 --- /dev/null +++ b/assets/patches/Tcl.sublime-syntax.patch @@ -0,0 +1,12 @@ +diff --git syntaxes/01_Packages/TCL/Tcl.sublime-syntax syntaxes/01_Packages/TCL/Tcl.sublime-syntax +index 1234567..abcdefg 100644 +--- syntaxes/01_Packages/TCL/Tcl.sublime-syntax ++++ syntaxes/01_Packages/TCL/Tcl.sublime-syntax +@@ -3,6 +3,7 @@ + # http://www.sublimetext.com/docs/3/syntax.html + name: Tcl + file_extensions: + - tcl ++first_line_match: ^\#!.*\b(tclsh|wish|expect)\b + scope: source.tcl + variables: From 1f89178fce7dde0f6241091fff241768317a9c46 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Fri, 20 Mar 2026 21:06:42 -0700 Subject: [PATCH 2/6] fix: reference PR number in changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3682bb82..79b65708 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,12 @@ ## Features +<<<<<<< HEAD - Preserve `--diff` change markers and snip separators when `--plain` is set. Closes #3630, see #3643 (@mvanhorn) - Add shebang-based detection for Tcl (`tclsh`, `wish`) and Expect (`expect`) scripts, see #3513 (@mvanhorn) +======= +- Add shebang-based detection for Tcl (`tclsh`, `wish`) and Expect (`expect`) scripts, see #3647 (@mvanhorn) +>>>>>>> 785fff9 (fix: reference PR number in changelog entry) - Added support for `hidden_file_extensions` from `.sublime-syntax` files, see #3613 (@Matei02355) - Add word wrapping mode via `--wrap=word`, see #3597 (@veeceey) - Support configuring `--terminal-width` via `BAT_WIDTH`, see #3679 (@officialasishkumar) From e070d105b57f854d982212265e2e52d6ea6d24ec Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Thu, 26 Mar 2026 22:22:54 -0700 Subject: [PATCH 3/6] test: add shebang regression tests and move changelog to Syntaxes section Add extensionless regression test files for tclsh, wish, and expect shebangs so syntect bumps don't silently break first-line detection. Move changelog entry from Features to Syntaxes per reviewer suggestion. Co-Authored-By: Claude Opus 4.6 --- CHANGELOG.md | 6 ++-- .../regression_tests/issue_3647_expect | 2 ++ .../regression_tests/issue_3647_tclsh | 2 ++ .../examples/regression_tests/issue_3647_wish | 2 ++ tests/integration_tests.rs | 31 +++++++++++++++++++ 5 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tests/examples/regression_tests/issue_3647_expect create mode 100644 tests/examples/regression_tests/issue_3647_tclsh create mode 100644 tests/examples/regression_tests/issue_3647_wish diff --git a/CHANGELOG.md b/CHANGELOG.md index 79b65708..99222693 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,9 @@ <<<<<<< HEAD - Preserve `--diff` change markers and snip separators when `--plain` is set. Closes #3630, see #3643 (@mvanhorn) -- Add shebang-based detection for Tcl (`tclsh`, `wish`) and Expect (`expect`) scripts, see #3513 (@mvanhorn) -======= - Add shebang-based detection for Tcl (`tclsh`, `wish`) and Expect (`expect`) scripts, see #3647 (@mvanhorn) ->>>>>>> 785fff9 (fix: reference PR number in changelog entry) +======= +>>>>>>> 29c913f (test: add shebang regression tests and move changelog to Syntaxes section) - Added support for `hidden_file_extensions` from `.sublime-syntax` files, see #3613 (@Matei02355) - Add word wrapping mode via `--wrap=word`, see #3597 (@veeceey) - Support configuring `--terminal-width` via `BAT_WIDTH`, see #3679 (@officialasishkumar) @@ -50,6 +49,7 @@ ## Syntaxes +- Add shebang-based detection for Tcl (`tclsh`, `wish`) and Expect (`expect`) scripts, see #3647 (@mvanhorn) - Change the URL of Zig submodule from GitHub to Codeberg, see #3519 (@sorairolake) - Don't color strings inside CSV files, to make it easier to tell which column they belong to, see #3521 (@keith-hall) - Add syntax highlighting support for COBOL, see #3584 (@adukhan99) diff --git a/tests/examples/regression_tests/issue_3647_expect b/tests/examples/regression_tests/issue_3647_expect new file mode 100644 index 00000000..3786df69 --- /dev/null +++ b/tests/examples/regression_tests/issue_3647_expect @@ -0,0 +1,2 @@ +#!/usr/bin/expect -f +set timeout 30 diff --git a/tests/examples/regression_tests/issue_3647_tclsh b/tests/examples/regression_tests/issue_3647_tclsh new file mode 100644 index 00000000..0f4b3c5c --- /dev/null +++ b/tests/examples/regression_tests/issue_3647_tclsh @@ -0,0 +1,2 @@ +#!/usr/bin/env tclsh +puts "Hello from tclsh" diff --git a/tests/examples/regression_tests/issue_3647_wish b/tests/examples/regression_tests/issue_3647_wish new file mode 100644 index 00000000..8bfe4baf --- /dev/null +++ b/tests/examples/regression_tests/issue_3647_wish @@ -0,0 +1,2 @@ +#!/usr/bin/wish +button .b -text "Click" diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 8ae4cfdd..9f18f598 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -4201,4 +4201,35 @@ fn plain_without_diff_still_works() { .assert() .success() .stdout("line 1\nline 2 modified\nline 3\nline 4 added\n"); +#[test] +fn tcl_shebang_detection_tclsh() { + bat() + .arg("--color=always") + .arg("--style=plain") + .arg("--decorations=always") + .arg("regression_tests/issue_3647_tclsh") + .assert() + .success(); +} + +#[test] +fn tcl_shebang_detection_wish() { + bat() + .arg("--color=always") + .arg("--style=plain") + .arg("--decorations=always") + .arg("regression_tests/issue_3647_wish") + .assert() + .success(); +} + +#[test] +fn tcl_shebang_detection_expect() { + bat() + .arg("--color=always") + .arg("--style=plain") + .arg("--decorations=always") + .arg("regression_tests/issue_3647_expect") + .assert() + .success(); } From cafad6b03668abc1ab41e1e10e72fd449ac609e4 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Fri, 27 Mar 2026 12:18:30 -0700 Subject: [PATCH 4/6] test: add highlighted outputs for Tcl shebang regression tests Generate highlighted test outputs for tclsh, wish, and expect shebang detection files to prevent regressions. --- CHANGELOG.md | 4 ---- tests/integration_tests.rs | 2 ++ tests/syntax-tests/highlighted/Tcl/expect_shebang | 7 +++++++ tests/syntax-tests/highlighted/Tcl/tclsh_shebang | 7 +++++++ tests/syntax-tests/highlighted/Tcl/wish_shebang | 5 +++++ 5 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 tests/syntax-tests/highlighted/Tcl/expect_shebang create mode 100644 tests/syntax-tests/highlighted/Tcl/tclsh_shebang create mode 100644 tests/syntax-tests/highlighted/Tcl/wish_shebang diff --git a/CHANGELOG.md b/CHANGELOG.md index 99222693..8049cba3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,7 @@ ## Features -<<<<<<< HEAD - Preserve `--diff` change markers and snip separators when `--plain` is set. Closes #3630, see #3643 (@mvanhorn) -- Add shebang-based detection for Tcl (`tclsh`, `wish`) and Expect (`expect`) scripts, see #3647 (@mvanhorn) -======= ->>>>>>> 29c913f (test: add shebang regression tests and move changelog to Syntaxes section) - Added support for `hidden_file_extensions` from `.sublime-syntax` files, see #3613 (@Matei02355) - Add word wrapping mode via `--wrap=word`, see #3597 (@veeceey) - Support configuring `--terminal-width` via `BAT_WIDTH`, see #3679 (@officialasishkumar) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 9f18f598..432faed8 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -4201,6 +4201,8 @@ fn plain_without_diff_still_works() { .assert() .success() .stdout("line 1\nline 2 modified\nline 3\nline 4 added\n"); +} + #[test] fn tcl_shebang_detection_tclsh() { bat() diff --git a/tests/syntax-tests/highlighted/Tcl/expect_shebang b/tests/syntax-tests/highlighted/Tcl/expect_shebang new file mode 100644 index 00000000..22f2101e --- /dev/null +++ b/tests/syntax-tests/highlighted/Tcl/expect_shebang @@ -0,0 +1,7 @@ +#!/usr/bin/expect -f +# Expect script detected via expect shebang +set timeout 30 +spawn ssh user@host +expect "password:" +send "secret\r" +expect eof diff --git a/tests/syntax-tests/highlighted/Tcl/tclsh_shebang b/tests/syntax-tests/highlighted/Tcl/tclsh_shebang new file mode 100644 index 00000000..de50978f --- /dev/null +++ b/tests/syntax-tests/highlighted/Tcl/tclsh_shebang @@ -0,0 +1,7 @@ +#!/usr/bin/env tclsh +# Tcl script detected via tclsh shebang +puts "Hello from tclsh" +set x 42 +if {$x > 0} { + puts "positive" +} diff --git a/tests/syntax-tests/highlighted/Tcl/wish_shebang b/tests/syntax-tests/highlighted/Tcl/wish_shebang new file mode 100644 index 00000000..134b185d --- /dev/null +++ b/tests/syntax-tests/highlighted/Tcl/wish_shebang @@ -0,0 +1,5 @@ +#!/usr/bin/wish +# Tk script detected via wish shebang +package require Tk +button .b -text "Click" -command {puts "clicked"} +pack .b From 77ea750e662d6dd21196acec1cae32517fe57dac Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Sat, 18 Apr 2026 06:58:45 -0700 Subject: [PATCH 5/6] test(Tcl): add shebang source files for regression test CI reported FileNotFoundError for Tcl/{tclsh,expect,wish}_shebang in tests/syntax-tests/source/Tcl/. The highlighted files existed but the source files had been omitted, so create_highlighted_versions.py had nothing to read from. Source files match the shebang regression test inputs at tests/examples/regression_tests/issue_3647_*. --- tests/syntax-tests/source/Tcl/expect_shebang | 7 +++++++ tests/syntax-tests/source/Tcl/tclsh_shebang | 7 +++++++ tests/syntax-tests/source/Tcl/wish_shebang | 5 +++++ 3 files changed, 19 insertions(+) create mode 100644 tests/syntax-tests/source/Tcl/expect_shebang create mode 100644 tests/syntax-tests/source/Tcl/tclsh_shebang create mode 100644 tests/syntax-tests/source/Tcl/wish_shebang diff --git a/tests/syntax-tests/source/Tcl/expect_shebang b/tests/syntax-tests/source/Tcl/expect_shebang new file mode 100644 index 00000000..ef288ba8 --- /dev/null +++ b/tests/syntax-tests/source/Tcl/expect_shebang @@ -0,0 +1,7 @@ +#!/usr/bin/expect -f +# Expect script detected via expect shebang +set timeout 30 +spawn ssh user@host +expect "password:" +send "secret\r" +expect eof diff --git a/tests/syntax-tests/source/Tcl/tclsh_shebang b/tests/syntax-tests/source/Tcl/tclsh_shebang new file mode 100644 index 00000000..08faa4d6 --- /dev/null +++ b/tests/syntax-tests/source/Tcl/tclsh_shebang @@ -0,0 +1,7 @@ +#!/usr/bin/env tclsh +# Tcl script detected via tclsh shebang +puts "Hello from tclsh" +set x 42 +if {$x > 0} { + puts "positive" +} diff --git a/tests/syntax-tests/source/Tcl/wish_shebang b/tests/syntax-tests/source/Tcl/wish_shebang new file mode 100644 index 00000000..690e73ef --- /dev/null +++ b/tests/syntax-tests/source/Tcl/wish_shebang @@ -0,0 +1,5 @@ +#!/usr/bin/wish +# Tk script detected via wish shebang +package require Tk +button .b -text "Click" -command {puts "clicked"} +pack .b From 0ecdeb28d43c7a259c59cc35dd5e1f0c2a266d3e Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Sat, 18 Apr 2026 09:42:26 -0700 Subject: [PATCH 6/6] test(Tcl): regenerate shebang golden files to match patched syntax The Tcl.sublime-syntax.patch adds first_line_match so bat recognizes tclsh/wish/expect shebang files as Tcl. With the patch applied, the leading '#!/...' and '# comment' lines get tokenized as Tcl comments and rendered in Monokai-Extended's comment color instead of default foreground. The goldens were generated against unpatched bat in the original commit, so CI's 'Run tests with updated syntaxes and themes' job (which runs assets/create.sh before the regression test) disagreed. Regenerate against the patched build so the regression test passes. --- tests/syntax-tests/highlighted/Tcl/expect_shebang | 14 +++++++------- tests/syntax-tests/highlighted/Tcl/tclsh_shebang | 12 ++++++------ tests/syntax-tests/highlighted/Tcl/wish_shebang | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/syntax-tests/highlighted/Tcl/expect_shebang b/tests/syntax-tests/highlighted/Tcl/expect_shebang index 22f2101e..871eed6c 100644 --- a/tests/syntax-tests/highlighted/Tcl/expect_shebang +++ b/tests/syntax-tests/highlighted/Tcl/expect_shebang @@ -1,7 +1,7 @@ -#!/usr/bin/expect -f -# Expect script detected via expect shebang -set timeout 30 -spawn ssh user@host -expect "password:" -send "secret\r" -expect eof +#!/usr/bin/expect -f +# Expect script detected via expect shebang +set timeout 30 +spawn ssh user@host +expect "password:" +send "secret\r" +expect eof diff --git a/tests/syntax-tests/highlighted/Tcl/tclsh_shebang b/tests/syntax-tests/highlighted/Tcl/tclsh_shebang index de50978f..5461f5f8 100644 --- a/tests/syntax-tests/highlighted/Tcl/tclsh_shebang +++ b/tests/syntax-tests/highlighted/Tcl/tclsh_shebang @@ -1,7 +1,7 @@ -#!/usr/bin/env tclsh -# Tcl script detected via tclsh shebang -puts "Hello from tclsh" -set x 42 -if {$x > 0} { - puts "positive" +#!/usr/bin/env tclsh +# Tcl script detected via tclsh shebang +puts "Hello from tclsh" +set x 42 +if {$x > 0} { + puts "positive" } diff --git a/tests/syntax-tests/highlighted/Tcl/wish_shebang b/tests/syntax-tests/highlighted/Tcl/wish_shebang index 134b185d..94fb971f 100644 --- a/tests/syntax-tests/highlighted/Tcl/wish_shebang +++ b/tests/syntax-tests/highlighted/Tcl/wish_shebang @@ -1,5 +1,5 @@ -#!/usr/bin/wish -# Tk script detected via wish shebang -package require Tk -button .b -text "Click" -command {puts "clicked"} -pack .b +#!/usr/bin/wish +# Tk script detected via wish shebang +package require Tk +button .b -text "Click" -command {puts "clicked"} +pack .b