Skip to content

Commit

Permalink
X.P.Pass: Properly escape backslashes
Browse files Browse the repository at this point in the history
  • Loading branch information
slotThe committed Oct 6, 2023
1 parent fde30fc commit 7854f77
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions XMonad/Prompt/Pass.hs
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,12 @@ typeString cmd = cmd ++ " | head -n1 | tr -d '\n' | xdotool type --clearmodifier

-- | Generate a pass prompt.
--
-- >>> pass "otp" "git\"hub\""
-- "pass otp \"git\\\"hub\\\"\""
-- >>> pass "otp" "\\n'git'\"hub\""
-- "pass otp \"\\\\n'git'\\\"hub\\\"\""
pass :: String -> String -> String
pass cmd label = concat ["pass ", cmd, " \"", concatMap escape label, "\""]
where
escape :: Char -> String
escape '"' = "\\\""
escape x = [x]
escape '"' = "\\\""
escape '\\' = "\\\\"
escape x = [x]

0 comments on commit 7854f77

Please sign in to comment.