Skip to content

Commit

Permalink
feat: read hashbang
Browse files Browse the repository at this point in the history
  • Loading branch information
axelrindle committed Apr 29, 2024
1 parent ab1aabb commit 3a64f00
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@
"type": "boolean",
"default": true,
"description": "Whether to scan for additional shell files. Reload window for the changes to take effect."
},
"task-explorer.defaultShell": {
"type": "string",
"default": "/bin/bash",
"description": "The default shell to use for shell tasks."
}
}
},
Expand Down
18 changes: 16 additions & 2 deletions src/provider/task-provider-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,21 @@ export default class TaskProviderShell implements TaskProvider<ShellTask> {
const name = basename(file.path)
const folder = workspace.getWorkspaceFolder(file)

// TODO: Get hashbang
let executable = this.config.getOr('defaultShell', '/bin/bash')
let shellArgs: string[] = []

const contents = await workspace.fs.readFile(file)
const lines = contents.toString().split('\n')
if (lines.length > 0) {
const firstLine = lines[0].replace('\r', '')

if (firstLine.startsWith('#!')) {
const parts = firstLine.split(' ')

executable = parts[0].replace('#!', '')
shellArgs = parts.slice(1)
}
}

const task = new ShellTask(
new ShellTaskDefinition(),
Expand All @@ -61,7 +75,7 @@ export default class TaskProviderShell implements TaskProvider<ShellTask> {
file.fsPath,
{
cwd: folder?.uri.fsPath,
executable: '/bin/bash',
executable, shellArgs
}
)
)
Expand Down
2 changes: 2 additions & 0 deletions src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface ConfigSchema {
exclude: string[]

scanShell: boolean

defaultShell: string
}

type ConfigKey = keyof ConfigSchema
Expand Down

0 comments on commit 3a64f00

Please sign in to comment.