Skip to content

Commit 1c8bc13

Browse files
authored
Merge pull request #560 from bash-lsp/fix-shebang-parser
Fix shebang parser
2 parents 9cfe6c5 + 7a09134 commit 1c8bc13

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

server/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Bash Language Server
22

3+
## 3.2.1
4+
5+
- Fix shebang parser that ignores some bash files https://github.com/bash-lsp/bash-language-server/pull/560
6+
37
## 3.2.0
48

59
- Dependency upgrades

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "A language server for Bash",
44
"author": "Mads Hartmann",
55
"license": "MIT",
6-
"version": "3.2.0",
6+
"version": "3.2.1",
77
"publisher": "mads-hartmann",
88
"main": "./out/server.js",
99
"typings": "./out/server.d.ts",

server/src/util/__tests__/shebang.test.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,18 @@ describe('hasBashShebang', () => {
99
expect(hasBashShebang(`#!/usr/bin/env python2.7\n# set -x`)).toBe(false)
1010
})
1111

12-
it('returns true for "#!/bin/sh -"', () => {
13-
expect(hasBashShebang('#!/bin/sh -')).toBe(true)
14-
expect(hasBashShebang('#!/bin/sh - ')).toBe(true)
12+
it('returns false for "#!/usr/bin/pwsh"', () => {
13+
expect(hasBashShebang('#!/usr/bin/pwsh')).toBe(false)
1514
})
1615

17-
it('returns true for "#!/usr/bin/env bash"', () => {
18-
expect(hasBashShebang('#!/usr/bin/env bash')).toBe(true)
19-
expect(hasBashShebang('#!/usr/bin/env bash ')).toBe(true)
20-
})
21-
22-
it('returns true for "#!/bin/sh"', () => {
23-
expect(hasBashShebang('#!/bin/sh')).toBe(true)
24-
expect(hasBashShebang('#!/bin/sh ')).toBe(true)
25-
})
26-
27-
it('returns true for "#!/bin/bash"', () => {
28-
expect(hasBashShebang('#!/bin/bash')).toBe(true)
29-
expect(hasBashShebang('#!/bin/bash ')).toBe(true)
16+
test.each([
17+
['#!/bin/sh -'],
18+
['#!/usr/bin/env bash'],
19+
['#!/bin/sh'],
20+
['#!/bin/bash'],
21+
['#!/bin/bash -u'],
22+
])('returns true for %p', (command) => {
23+
expect(hasBashShebang(command)).toBe(true)
24+
expect(hasBashShebang(`${command} `)).toBe(true)
3025
})
3126
})

server/src/util/shebang.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ export function getShebang(fileContent: string): string | null {
66
return null
77
}
88

9-
return match[1].replace('-', '').trim()
9+
return match[1]
1010
}
1111

12+
/**
13+
* Check if the given shebang is a bash shebang.
14+
*/
1215
export function isBashShebang(shebang: string): boolean {
13-
return shebang.endsWith('bash') || shebang.endsWith('sh')
16+
return (
17+
shebang.startsWith('/bin/bash') ||
18+
shebang.startsWith('/bin/sh') ||
19+
shebang.startsWith('/usr/bin/env bash') ||
20+
shebang.startsWith('/usr/bin/env sh')
21+
)
1422
}
1523

1624
export function hasBashShebang(fileContent: string): boolean {

0 commit comments

Comments
 (0)