Skip to content

Commit 4c8c789

Browse files
authored
More hashbang support (#97)
2 parents 0579e8a + 4fd8b29 commit 4c8c789

File tree

5 files changed

+47
-9
lines changed

5 files changed

+47
-9
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Default styles
2+
--------------
3+
4+
* Support ``.fish`` (Fish shell).
5+
* Support ``.zsh`` (zsh shell).
6+
* Recognize fish, Powershell, R, and zsh file types
7+
by their hashbang executable name.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Fixed
2+
-----
3+
4+
* Strip the executable extension (like ``.exe``) before removing version numbers
5+
when identifying a file type based on its hashbang.
6+
7+
This resolves a bug that prevented identification of version-specific
8+
executable names, like ``python3.14.exe``, on Windows platforms.

src/chipshot/reader/identity.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ def handle(info: FileInfo, config: dict[str, typing.Any]) -> None:
3838
info.identity = config["interpreters"][name]
3939
return
4040

41-
# Look for a version-less name.
42-
name_without_version = name.rstrip("0123456789.")
43-
if name_without_version in config["interpreters"]:
44-
log.debug(f"{info.path}: Found versioned interpreter '{name}'")
45-
info.identity = config["interpreters"][name_without_version]
46-
return
47-
48-
# Try removing the extension (such as "python.exe" on Windows).
41+
# Try removing the extension (such as ".exe" on Windows).
4942
stem = path.stem
5043
if stem in config["interpreters"]:
5144
log.debug(f"{info.path}: Found base interpreter '{name}'")
5245
info.identity = config["interpreters"][stem]
5346
return
47+
48+
# Look for a version-less name.
49+
name_without_version = stem.rstrip("0123456789.")
50+
if name_without_version in config["interpreters"]:
51+
log.debug(f"{info.path}: Found versioned interpreter '{name}'")
52+
info.identity = config["interpreters"][name_without_version]
53+
return

src/chipshot/resources/default-config.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ style = "slash-slash"
117117
prologue = "css-charset"
118118
style = "slash-star"
119119

120+
[extensions.fish]
121+
prologue = "hashbang"
122+
style = "hash"
123+
120124
[extensions.gd]
121125
style = "hash"
122126

@@ -230,20 +234,28 @@ prologue = "xhtml_declaration_and_doctype"
230234
style = "xml"
231235
prologue = "xml_declaration"
232236

237+
[extensions.zsh]
238+
style = "hash"
239+
prologue = "hashbang"
240+
233241

234242
# Interpreters
235243
# ------------
236244

237245
[interpreters]
238246
bash = "shell"
247+
fish = "shell"
239248
gorun = "go"
240249
node = "javascript"
241250
nodejs = "javascript"
242251
perl = "perl"
252+
powershell = "powershell"
243253
pwsh = "powershell"
244254
python = "python"
255+
rscript = "r"
245256
ruby = "ruby"
246257
sh = "shell"
258+
zsh = "shell"
247259

248260

249261
# Types
@@ -269,6 +281,10 @@ style = "hash"
269281
prologue = "hashbang-with-encoding"
270282
style = "hash"
271283

284+
[types.r]
285+
prologue = "hashbang"
286+
style = "hash"
287+
272288
[types.ruby]
273289
prologue = "hashbang-with-encoding"
274290
style = "hash"

tests/test_reader_identity.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@
1919
pytest.param("#!/usr/bin/python", "python", id="base executable name"),
2020
pytest.param("#!/usr/bin/python3.11", "python", id="trailing version"),
2121
pytest.param("#!/usr/bin/env python", "python", id="env"),
22-
pytest.param(r"#!C:\Program Files\Python39\python.exe", "python", id="windows"),
22+
pytest.param(
23+
r'#!"C:\Program Files\Python39\python3.9.exe"', "python", id="windows"
24+
),
25+
pytest.param(
26+
"#!/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -File",
27+
"powershell",
28+
id="language-powershell",
29+
),
2330
# Loop exhaustion
2431
pytest.param("#!env unknown -c", "", id="loop exhaustion"),
2532
),

0 commit comments

Comments
 (0)