Alias ash to dash with warning.
This commit is contained in:
parent
cf1c46d852
commit
fee6c94d40
|
@ -400,15 +400,20 @@ prop_checkShebang1 = verifyNotTree checkShebang "#!/usr/bin/env bash -x\necho co
|
||||||
prop_checkShebang2 = verifyNotTree checkShebang "#! /bin/sh -l "
|
prop_checkShebang2 = verifyNotTree checkShebang "#! /bin/sh -l "
|
||||||
prop_checkShebang3 = verifyTree checkShebang "ls -l"
|
prop_checkShebang3 = verifyTree checkShebang "ls -l"
|
||||||
prop_checkShebang4 = verifyNotTree checkShebang "#shellcheck shell=sh\nfoo"
|
prop_checkShebang4 = verifyNotTree checkShebang "#shellcheck shell=sh\nfoo"
|
||||||
|
prop_checkShebang5 = verifyTree checkShebang "#!/usr/bin/env ash"
|
||||||
|
prop_checkShebang6 = verifyNotTree checkShebang "#!/usr/bin/env ash\n# shellcheck shell=dash\n"
|
||||||
|
prop_checkShebang7 = verifyNotTree checkShebang "#!/usr/bin/env ash\n# shellcheck shell=sh\n"
|
||||||
checkShebang params (T_Annotation _ list t) =
|
checkShebang params (T_Annotation _ list t) =
|
||||||
if any isOverride list then [] else checkShebang params t
|
if any isOverride list then [] else checkShebang params t
|
||||||
where
|
where
|
||||||
isOverride (ShellOverride _) = True
|
isOverride (ShellOverride _) = True
|
||||||
isOverride _ = False
|
isOverride _ = False
|
||||||
checkShebang params (T_Script id sb _) =
|
checkShebang params (T_Script id sb _) = execWriter $
|
||||||
[makeComment ErrorC id 2148
|
unless (shellTypeSpecified params) $ do
|
||||||
"Tips depend on target shell and yours is unknown. Add a shebang."
|
when (sb == "") $
|
||||||
| not (shellTypeSpecified params) && sb == "" ]
|
err id 2148 "Tips depend on target shell and yours is unknown. Add a shebang."
|
||||||
|
when (executableFromShebang sb == "ash") $
|
||||||
|
warn id 2187 "Ash scripts will be checked as Dash. Add '# shellcheck shell=dash' to silence."
|
||||||
|
|
||||||
|
|
||||||
prop_checkForInQuoted = verify checkForInQuoted "for f in \"$(ls)\"; do echo foo; done"
|
prop_checkForInQuoted = verify checkForInQuoted "for f in \"$(ls)\"; do echo foo; done"
|
||||||
|
|
|
@ -153,6 +153,7 @@ prop_determineShell4 = determineShell (fromJust $ pScript
|
||||||
prop_determineShell5 = determineShell (fromJust $ pScript
|
prop_determineShell5 = determineShell (fromJust $ pScript
|
||||||
"#shellcheck shell=sh\nfoo") == Sh
|
"#shellcheck shell=sh\nfoo") == Sh
|
||||||
prop_determineShell6 = determineShell (fromJust $ pScript "#! /bin/sh") == Sh
|
prop_determineShell6 = determineShell (fromJust $ pScript "#! /bin/sh") == Sh
|
||||||
|
prop_determineShell7 = determineShell (fromJust $ pScript "#! /bin/ash") == Dash
|
||||||
determineShell t = fromMaybe Bash $ do
|
determineShell t = fromMaybe Bash $ do
|
||||||
shellString <- foldl mplus Nothing $ getCandidates t
|
shellString <- foldl mplus Nothing $ getCandidates t
|
||||||
shellForExecutable shellString
|
shellForExecutable shellString
|
||||||
|
@ -166,8 +167,13 @@ determineShell t = fromMaybe Bash $ do
|
||||||
getCandidates (T_Annotation _ annotations s) =
|
getCandidates (T_Annotation _ annotations s) =
|
||||||
map forAnnotation annotations ++
|
map forAnnotation annotations ++
|
||||||
[Just $ fromShebang s]
|
[Just $ fromShebang s]
|
||||||
fromShebang (T_Script _ s t) = shellFor s
|
fromShebang (T_Script _ s t) = executableFromShebang s
|
||||||
|
|
||||||
|
-- Given a string like "/bin/bash" or "/usr/bin/env dash",
|
||||||
|
-- return the shell basename like "bash" or "dash"
|
||||||
|
executableFromShebang :: String -> String
|
||||||
|
executableFromShebang = shellFor
|
||||||
|
where
|
||||||
shellFor s | "/env " `isInfixOf` s = head (drop 1 (words s)++[""])
|
shellFor s | "/env " `isInfixOf` s = head (drop 1 (words s)++[""])
|
||||||
shellFor s | ' ' `elem` s = shellFor $ takeWhile (/= ' ') s
|
shellFor s | ' ' `elem` s = shellFor $ takeWhile (/= ' ') s
|
||||||
shellFor s = reverse . takeWhile (/= '/') . reverse $ s
|
shellFor s = reverse . takeWhile (/= '/') . reverse $ s
|
||||||
|
|
|
@ -88,6 +88,7 @@ shellForExecutable name =
|
||||||
"sh" -> return Sh
|
"sh" -> return Sh
|
||||||
"bash" -> return Bash
|
"bash" -> return Bash
|
||||||
"dash" -> return Dash
|
"dash" -> return Dash
|
||||||
|
"ash" -> return Dash -- There's also a warning for this.
|
||||||
"ksh" -> return Ksh
|
"ksh" -> return Ksh
|
||||||
"ksh88" -> return Ksh
|
"ksh88" -> return Ksh
|
||||||
"ksh93" -> return Ksh
|
"ksh93" -> return Ksh
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# TODO: Find a less trashy way to get the next available error code
|
||||||
|
|
||||||
|
shopt -s globstar
|
||||||
|
|
||||||
|
for i in 1 2
|
||||||
|
do
|
||||||
|
last=$(grep -hv "^prop" **/*.hs | grep -Ewo "$i[0-9]{3}" | sort -n | tail -n 1)
|
||||||
|
echo "Next ${i}xxx: $((last+1))"
|
||||||
|
done
|
Loading…
Reference in New Issue