Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daml-assistant: Install bash completion scripts on Linux and Mac. #3946

Merged
merged 10 commits into from
Jan 6, 2020
Prev Previous commit
Next Next commit
specifically -> explicitly
  • Loading branch information
associahedron committed Jan 3, 2020
commit fcf6d1f6b70ab8b56b40a44e36271a0bc50c5ba8
20 changes: 10 additions & 10 deletions daml-assistant/src/DA/Daml/Assistant/Install/BashCompletion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- /usr/local/etc/bash_completion.d (on Mac) or
-- /etc/bash_completion.d (elsewhere). These are not installed on
-- Windows by default, and won't be reinstalled unless the user
-- asks by passing @--bash-completions=yes@ specifically.
-- asks by passing @--bash-completions=yes@ explicitly.
module DA.Daml.Assistant.Install.BashCompletion
( installBashCompletions
) where
Expand All @@ -29,19 +29,19 @@ shouldInstallBashCompletions options =
BashCompletions No -> pure False
BashCompletions Auto -> andM
[ pure (not isWindows)
, doesDirectoryExist bashCompletionDir
, not <$> doesFileExist bashCompletionScript
, doesDirectoryExist bashCompletionDirPath
, not <$> doesFileExist bashCompletionScriptPath
]

doInstallBashCompletions :: DamlPath -> (String -> IO ()) -> IO ()
doInstallBashCompletions damlPath output = do
dirExists <- doesDirectoryExist bashCompletionDir
dirExists <- doesDirectoryExist bashCompletionDirPath
if dirExists
then do
completionScript <- getCompletionScript damlPath
BSL.writeFile bashCompletionScript completionScript
BSL.writeFile bashCompletionScriptPath completionScript
output "Bash completions installed for DAML assistant."
else output ("Bash completions not installed for DAML assistant: " <> bashCompletionDir <> " does not exist")
else output ("Bash completions not installed for DAML assistant: " <> bashCompletionDirPath <> " does not exist")

getCompletionScript :: DamlPath -> IO BSL.ByteString
getCompletionScript damlPath = do
Expand All @@ -51,10 +51,10 @@ getCompletionScript damlPath = do
assistantPath :: DamlPath -> FilePath
assistantPath (DamlPath p) = p </> "bin" </> "daml"

bashCompletionDir :: FilePath
bashCompletionDir
bashCompletionDirPath :: FilePath
bashCompletionDirPath
| isMac = "/usr/local/etc/bash_completion.d"
This conversation was marked as resolved.
Show resolved Hide resolved
| otherwise = "/etc/bash_completion.d"
This conversation was marked as resolved.
Show resolved Hide resolved

bashCompletionScript :: FilePath
bashCompletionScript = bashCompletionDir </> "daml"
bashCompletionScriptPath :: FilePath
bashCompletionScriptPath = bashCompletionDirPath </> "daml"