Use printf instead of echo for xmessage help

In some shells—like bash—the entire help message is shown in a single
line because a newline is printed as a literal "\n" character when using
echo.  Some distributions[1] have /bin/sh linked to bash, and so new
users are likely to run into this at some point.

We could fix this by either removing show and explicitly adding an
escaped quotation symbol before and after the string, or by using printf
instead of echo.  The printf solution seems more portable[2] and so I
propose we go with that one.

[1]: f5b9a25cdd/nixos/modules/config/shells-environment.nix (L129-L143)
[2]: https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo/#65819
This commit is contained in:
MuhammedZakir 2021-06-18 23:47:27 +05:30 committed by slotThe
parent 13849c6230
commit 2e6eb9068d
2 changed files with 2 additions and 2 deletions

View File

@ -129,7 +129,7 @@ myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
, ((modm , xK_q ), spawn "xmonad --recompile; xmonad --restart")
-- Run xmessage with a summary of the default keybindings (useful for beginners)
, ((modm .|. shiftMask, xK_slash ), spawn ("echo \"" ++ help ++ "\" | xmessage -file -"))
, ((modm .|. shiftMask, xK_slash ), spawn ("printf " ++ show help ++ " | xmessage -file -"))
]
++

View File

@ -239,7 +239,7 @@ keys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
, (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
where
helpCommand :: X ()
helpCommand = spawn ("echo " ++ show help ++ " | xmessage -file -")
helpCommand = spawn ("printf " ++ show help ++ " | xmessage -file -")
-- | Mouse bindings: default actions bound to mouse events
mouseBindings :: XConfig Layout -> M.Map (KeyMask, Button) (Window -> X ())