From ce0b313b9357eeff5cb4aa9059315b75a3ce933b Mon Sep 17 00:00:00 2001
From: Vidar Holen <spam@vidarholen.net>
Date: Mon, 13 May 2013 09:15:45 -0700
Subject: [PATCH] Better messages for ignored backslashes like 'echo foo\n'

---
 ShellCheck/Parser.hs | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs
index b78ab91..f89b4a5 100644
--- a/ShellCheck/Parser.hs
+++ b/ShellCheck/Parser.hs
@@ -422,7 +422,7 @@ readArithmeticContents =
 
     readArithTerm = readBased <|> readArithTermUnit
     readArithTermUnit = readGroup <|> readExpansion <|> readQuoted <|> readNumber <|> readVar
-    
+
     readQuoted = readDoubleQuoted <|> readSingleQuoted
 
     readSequence = do
@@ -560,7 +560,7 @@ readNormalWordPart end = do
             pos <- getPosition
             lookAhead $ char '('
             parseProblemAt pos ErrorC "'(' is invalid here. Did you forget to escape it?"
-        
+
 
 readSpacePart = do
     id <- getNextId
@@ -691,8 +691,15 @@ readNormalEscaped = called "escaped char" $ do
       <|>
         do
             next <- anyChar
-            parseNoteAt pos WarningC $ "Did you mean \"$(printf \"\\" ++ [next] ++ "\")\"? The shell just ignores the \\ here."
+            case escapedChar next of
+                Just name -> parseNoteAt pos WarningC $ "\\" ++ [next] ++ " is just literal '" ++ [next] ++ "' here. For " ++ name ++ ", use \"$(printf \"\\" ++ [next] ++ "\")\"."
+                Nothing -> parseNoteAt pos InfoC $ "This \\" ++ [next] ++ " will be a regular '" ++ [next] ++ "' in this context."
             return [next]
+  where
+    escapedChar 'n' = Just "line feed"
+    escapedChar 't' = Just "tab"
+    escapedChar 'r' = Just "carriage return"
+    escapedChar _ = Nothing
 
 
 prop_readExtglob1 = isOk readExtglob "!(*.mp3)"
@@ -1069,7 +1076,7 @@ readIfClause = called "if expression" $ do
     return $ T_IfExpression id ((condition, action):elifs) elses
 
 
-verifyNotEmptyIf s = 
+verifyNotEmptyIf s =
     optional (do
                 emptyPos <- getPosition
                 try . lookAhead $ (g_Fi <|> g_Elif <|> g_Else)