From 2e6eb9068d548473392873e7ec11a890d97abdea Mon Sep 17 00:00:00 2001 From: MuhammedZakir <8190126+MuhammedZakir@users.noreply.github.com> Date: Fri, 18 Jun 2021 23:47:27 +0530 Subject: [PATCH] Use printf instead of echo for xmessage help MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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]: https://github.com/NixOS/nixpkgs/blob/f5b9a25cdd21b4e45ab5f11c27b95dfe17384274/nixos/modules/config/shells-environment.nix#L129-L143 [2]: https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo/#65819 --- man/xmonad.hs | 2 +- src/XMonad/Config.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/man/xmonad.hs b/man/xmonad.hs index baf5189..4f5fbeb 100644 --- a/man/xmonad.hs +++ b/man/xmonad.hs @@ -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 -")) ] ++ diff --git a/src/XMonad/Config.hs b/src/XMonad/Config.hs index cd655d5..c377ff1 100644 --- a/src/XMonad/Config.hs +++ b/src/XMonad/Config.hs @@ -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 ())