@@ -3596,6 +3596,8 @@ prop_checkPipeToNowhere17 = verify checkPipeToNowhere "echo World | cat << 'EOF'
3596
3596
prop_checkPipeToNowhere18 = verifyNot checkPipeToNowhere " ls 1>&3 3>&1 3>&- | wc -l"
3597
3597
prop_checkPipeToNowhere19 = verifyNot checkPipeToNowhere " find . -print0 | du --files0-from=/dev/stdin"
3598
3598
prop_checkPipeToNowhere20 = verifyNot checkPipeToNowhere " find . | du --exclude-from=/dev/fd/0"
3599
+ prop_checkPipeToNowhere21 = verifyNot checkPipeToNowhere " yes | cp -ri foo/* bar"
3600
+ prop_checkPipeToNowhere22 = verifyNot checkPipeToNowhere " yes | rm --interactive *"
3599
3601
3600
3602
data PipeType = StdoutPipe | StdoutStderrPipe | NoPipe deriving (Eq )
3601
3603
checkPipeToNowhere :: Parameters -> Token -> WriterT [TokenComment ] Identity ()
@@ -3661,6 +3663,7 @@ checkPipeToNowhere params t =
3661
3663
commandSpecificException name cmd =
3662
3664
case name of
3663
3665
" du" -> any ((`elem` [" exclude-from" , " files0-from" ]) . snd ) $ getAllFlags cmd
3666
+ _ | name `elem` interactiveFlagCmds -> hasInteractiveFlag cmd
3664
3667
_ -> False
3665
3668
3666
3669
warnAboutDupes (n, list@ (_: _: _)) =
@@ -3684,7 +3687,7 @@ checkPipeToNowhere params t =
3684
3687
name <- getCommandBasename cmd
3685
3688
guard $ name `elem` nonReadingCommands
3686
3689
guard . not $ hasAdditionalConsumers cmd
3687
- guard . not $ name `elem` [ " cp " , " mv " , " rm " ] && cmd `hasFlag` " i "
3690
+ guard . not $ name `elem` interactiveFlagCmds && hasInteractiveFlag cmd
3688
3691
let suggestion =
3689
3692
if name == " echo"
3690
3693
then " Did you want 'cat' instead?"
@@ -3699,6 +3702,9 @@ checkPipeToNowhere params t =
3699
3702
treeContains pred t = isNothing $
3700
3703
doAnalysis (guard . not . pred ) t
3701
3704
3705
+ interactiveFlagCmds = [ " cp" , " mv" , " rm" ]
3706
+ hasInteractiveFlag cmd = cmd `hasFlag` " i" || cmd `hasFlag` " interactive"
3707
+
3702
3708
mayConsume t =
3703
3709
case t of
3704
3710
T_ProcSub _ " <" _ -> True
0 commit comments