Skip to content

Commit 3a64f00

Browse files
committed
feat: read hashbang
1 parent ab1aabb commit 3a64f00

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@
116116
"type": "boolean",
117117
"default": true,
118118
"description": "Whether to scan for additional shell files. Reload window for the changes to take effect."
119+
},
120+
"task-explorer.defaultShell": {
121+
"type": "string",
122+
"default": "/bin/bash",
123+
"description": "The default shell to use for shell tasks."
119124
}
120125
}
121126
},

src/provider/task-provider-shell.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,21 @@ export default class TaskProviderShell implements TaskProvider<ShellTask> {
5050
const name = basename(file.path)
5151
const folder = workspace.getWorkspaceFolder(file)
5252

53-
// TODO: Get hashbang
53+
let executable = this.config.getOr('defaultShell', '/bin/bash')
54+
let shellArgs: string[] = []
55+
56+
const contents = await workspace.fs.readFile(file)
57+
const lines = contents.toString().split('\n')
58+
if (lines.length > 0) {
59+
const firstLine = lines[0].replace('\r', '')
60+
61+
if (firstLine.startsWith('#!')) {
62+
const parts = firstLine.split(' ')
63+
64+
executable = parts[0].replace('#!', '')
65+
shellArgs = parts.slice(1)
66+
}
67+
}
5468

5569
const task = new ShellTask(
5670
new ShellTaskDefinition(),
@@ -61,7 +75,7 @@ export default class TaskProviderShell implements TaskProvider<ShellTask> {
6175
file.fsPath,
6276
{
6377
cwd: folder?.uri.fsPath,
64-
executable: '/bin/bash',
78+
executable, shellArgs
6579
}
6680
)
6781
)

src/services/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export interface ConfigSchema {
88
exclude: string[]
99

1010
scanShell: boolean
11+
12+
defaultShell: string
1113
}
1214

1315
type ConfigKey = keyof ConfigSchema

0 commit comments

Comments
 (0)