-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vanessa McHale
committed
Jan 18, 2018
1 parent
058bbcd
commit 4632244
Showing
12 changed files
with
34 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,8 @@ | ||
import Control.Monad (unless, void) | ||
import Data.Maybe | ||
import Distribution.CommandLine | ||
import Distribution.Simple | ||
import System.Directory (createDirectoryIfMissing) | ||
import System.Environment (lookupEnv) | ||
import System.Process (readCreateProcessWithExitCode, shell) | ||
|
||
manpage :: IO String | ||
manpage = readFile "man/madlang.1" | ||
|
||
main :: IO () | ||
main = setManpath >> | ||
writeManpages >> | ||
writeBashCompletions >> | ||
writeManpages "man/madlang.1" "madlang.1" >> | ||
writeBashCompletions "madlang" >> | ||
defaultMain | ||
|
||
setManpath :: IO () | ||
setManpath = do | ||
home <- lookupEnv "HOME" | ||
case home of | ||
Just x -> do | ||
let bashRc = x ++ "/.bashrc" | ||
config <- readFile bashRc | ||
unless ("#manpath updated by madlang" `elem` lines config) | ||
(appendFile bashRc "\n#manpath updated by madlang\nexport MANPATH=~/.local/share:$MANPATH\n" >> | ||
void (readCreateProcessWithExitCode (shell $ "MANPATH=" ++ x ++ "/.local/share mandb") "")) | ||
Nothing -> pure () | ||
|
||
writeManpages :: IO () | ||
writeManpages = do | ||
home <- lookupEnv "HOME" | ||
case home of | ||
Just x -> do | ||
let manPath = x ++ "/.local/share/man/man1" | ||
createDirectoryIfMissing True manPath | ||
writeFile (manPath ++ "/madlang.1") =<< manpage | ||
Nothing -> pure () | ||
|
||
-- TODO only write if we can't find our own thing! | ||
writeBashCompletions :: IO () | ||
writeBashCompletions = do | ||
home <- lookupEnv "HOME" | ||
case home of | ||
Just x -> do | ||
let bashRc = x ++ "/.bashrc" | ||
config <- readFile bashRc | ||
unless ("# Added by madlang" `elem` lines config) | ||
(appendFile bashRc "\n# Added by madlang\neval \"$(madlang --bash-completion-script madlang)\"\n") | ||
Nothing -> pure () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters