Suggest 'cat' when piping/redirecting to echo (fixes #1292)
This commit is contained in:
parent
0f835a5a2c
commit
581be5878b
|
@ -2856,16 +2856,25 @@ checkPipeToNowhere _ t =
|
||||||
name <- getCommandBasename cmd
|
name <- getCommandBasename cmd
|
||||||
guard $ name `elem` nonReadingCommands
|
guard $ name `elem` nonReadingCommands
|
||||||
guard . not $ hasAdditionalConsumers cmd
|
guard . not $ hasAdditionalConsumers cmd
|
||||||
|
-- Confusing echo for cat is so common that it's worth a special case
|
||||||
|
let suggestion =
|
||||||
|
if name == "echo"
|
||||||
|
then "Did you want 'cat' instead?"
|
||||||
|
else "Wrong command or missing xargs?"
|
||||||
return $ warn (getId cmd) 2216 $
|
return $ warn (getId cmd) 2216 $
|
||||||
"Piping to '" ++ name ++ "', a command that doesn't read stdin. Wrong command or missing xargs?"
|
"Piping to '" ++ name ++ "', a command that doesn't read stdin. " ++ suggestion
|
||||||
|
|
||||||
checkRedir cmd = potentially $ do
|
checkRedir cmd = potentially $ do
|
||||||
name <- getCommandBasename cmd
|
name <- getCommandBasename cmd
|
||||||
guard $ name `elem` nonReadingCommands
|
guard $ name `elem` nonReadingCommands
|
||||||
guard . not $ hasAdditionalConsumers cmd
|
guard . not $ hasAdditionalConsumers cmd
|
||||||
guard . not $ name `elem` ["cp", "mv", "rm"] && cmd `hasFlag` "i"
|
guard . not $ name `elem` ["cp", "mv", "rm"] && cmd `hasFlag` "i"
|
||||||
|
let suggestion =
|
||||||
|
if name == "echo"
|
||||||
|
then "Did you want 'cat' instead?"
|
||||||
|
else "Bad quoting, wrong command or missing xargs?"
|
||||||
return $ warn (getId cmd) 2217 $
|
return $ warn (getId cmd) 2217 $
|
||||||
"Redirecting to '" ++ name ++ "', a command that doesn't read stdin. Bad quoting or missing xargs?"
|
"Redirecting to '" ++ name ++ "', a command that doesn't read stdin. " ++ suggestion
|
||||||
|
|
||||||
-- Could any words in a SimpleCommand consume stdin (e.g. echo "$(cat)")?
|
-- Could any words in a SimpleCommand consume stdin (e.g. echo "$(cat)")?
|
||||||
hasAdditionalConsumers t = fromMaybe True $ do
|
hasAdditionalConsumers t = fromMaybe True $ do
|
||||||
|
|
Loading…
Reference in New Issue