aboutsummaryrefslogtreecommitdiffstats
path: root/install
blob: f2395cfa240531ca2bb9c0241a187df74ed892f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env runhaskell
-- -*- haskell -*-

import System.Directory ( removeFile
                        , doesFileExist
                        , createFileLink
                        , pathIsSymbolicLink
                        , copyFile
                        , makeAbsolute
                        , getHomeDirectory
                        )

remIf :: FilePath -> IO ()
remIf dest = do
  res <- doesFileExist dest
  resSym <- pathIsSymbolicLink dest
  rem res dest
  rem resSym dest
  where
    rem b dest
      | b = removeFile dest
      | otherwise = return ()

forceOp :: (FilePath -> FilePath -> IO ()) -> FilePath -> FilePath -> IO ()
forceOp op src dest = do
  remIf dest
  fullSrc <- makeAbsolute src
  homeDir <- getHomeDirectory
  op fullSrc (homeDir ++ dest)

forceCopy :: FilePath -> FilePath -> IO ()
forceCopy = forceOp copyFile

forceFileSymLink :: FilePath -> FilePath -> IO ()
forceFileSymLink = forceOp createFileLink

main :: IO ()
main = do
  putStrLn "Installing emacs config..."
  forceCopy "./emacs/init.el" "/.emacs.d/init.el"
  forceFileSymLink "./emacs/loader.org" "/.emacs.d/loader.org"

  putStrLn "Installing X config..."
  forceFileSymLink "./X/.Xmodmap" "/.Xmodmap"
  forceFileSymLink "./X/.Xresources" "/.Xresources"
  forceFileSymLink "./X/.xinitrc" "/.xinitrc"

  putStrLn "Installing tmux config..."
  forceFileSymLink "./tmux/.tmux.conf" "/.tmux.conf"

  putStrLn "Installing i3 config..."
  forceFileSymLink "./i3/config" "/.config/i3/config"

  putStrLn "Installing zsh config..."
  forceFileSymLink "./zsh/.zshrc" "/.zshrc"

  putStrLn "Installing isync config..."
  forceFileSymLink "./isync/.mbsyncrc" "/.mbsyncrc"