Skip to content

Commit

Permalink
feat(install): find path to exec automatically
Browse files Browse the repository at this point in the history
- Will find the path to itself and set path in git hook
- Lets it be run from anywhere in project dir instead of just root

Closes #6
  • Loading branch information
Shane Wilson committed Jan 15, 2015
1 parent 7267f11 commit 1ee2a56
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cgtools.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ executable cgtools
, bytestring
, ansi-terminal
, hastache
, FindBin

main-is: Main.hs
-- from Tasty cabal with ansi-terminal
Expand Down Expand Up @@ -82,6 +83,7 @@ library
, bytestring
, ansi-terminal
, hastache
, FindBin

-- from Tasty cabal with ansi-terminal
cpp-options: -DCOLORS
Expand Down
6 changes: 4 additions & 2 deletions src/CGTools/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ import Text.Hastache.Context (mkGenericContext)
import Data.Data (Data, Typeable)
import Paths_cgtools
import System.IO (hFlush, stdout)
import System.Environment.FindBin (getProgPath)

data Ctx = Ctx {
path :: Text
} deriving (Data, Typeable)

runInstall :: IO ()
runInstall = do
bin <- getProgPath
let binPath = pack $ bin ++ "/cgtools"
let context = mkGenericContext Ctx { path = binPath }
g <- getGitPath
let commitHook = getPrepareCommitPath (pack g)
genFile context "prepare-commit-msg" commitHook
p <- getPermissions commitHook
setPermissions commitHook (p {executable = True})
where
context = mkGenericContext Ctx { path = "./cgtools" }

getGitPath :: IO String
getGitPath = readProcess "git" [ "rev-parse", "--git-dir" ] ""
Expand Down

0 comments on commit 1ee2a56

Please sign in to comment.