Change install script to Haskell

This commit is contained in:
Frederik Hanghøj Iversen 2019-02-02 17:53:43 +01:00
parent 8678ee8a67
commit d0c5d0698e
2 changed files with 72 additions and 17 deletions

72
install.hs Executable file
View file

@ -0,0 +1,72 @@
#!/usr/bin/env runhaskell
{-# Language GADTSyntax, LambdaCase #-}
{-# OPTIONS_GHC -Wall #-}
import Data.Foldable (traverse_)
import Data.Functor (void)
import GHC.IO.Handle (Handle)
import System.Process (createProcess, proc, ProcessHandle)
import System.Environment
import System.FilePath
symlink
:: FilePath
-> FilePath
-> Link
-> IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
symlink dotfiles config s
= createProcess (proc "ln" ["-s", source, target])
where
(source, target) = spec s
spec :: Link -> (FilePath, FilePath)
spec = \case
Config p -> (dotfiles </> p, config)
Absolute trg src -> (trg, src)
getHome :: IO FilePath
getHome = getEnv "HOME"
-- TODO Make configurable/more portable.
getDotfiles :: FilePath -> FilePath
getDotfiles home = home </> "git/fredefox/dotfiles"
getConfig :: FilePath -> FilePath
getConfig home = home </> ".config"
data Link where
Config :: FilePath -> Link
Absolute :: FilePath -> FilePath -> Link
getLinks :: FilePath -> [] Link
getLinks home = std <> absolute
where
std = Config <$>
[ "git"
, "i3"
, "urxvt"
, "xinit"
, "Xresources"
, "zsh"
]
absolute =
[ ".emacs.d" |> ".config/emacs"
, ".gitconfig" |> ".config/git/config"
, ".urxvt" |> ".config/urxvt"
, ".xinitrc" |> ".config/xinit/xinitrc"
, ".xsession" |> ".xinitrc"
, ".xsessionrc" |> ".config/xinit/xinitrc"
, ".zshrc" |> ".config/zsh/init"
]
src |> trg = Absolute trg (home </> src)
main :: IO ()
main = do
home <- getHome
let
config = getConfig home
dotfiles = getDotfiles home
links = getLinks home
void $ createProcess (proc "mkdir" [config])
traverse_ (symlink dotfiles config) links

View file

@ -1,17 +0,0 @@
#!/usr/bin/bash
# Untested!!
ln -s ~/.emacs.d ~/.conf/emacs
tee ~/.xinitrc << EOF
#!/usr/bin/env bash
setxkbmap -option grp:win_space_toggle -layout us,dk
xrdb -merge ~/.Xresources
EOF
tee ~/.Xresources << EOF
#include ".config/Xresources/general"
#include ".config/Xresources/urxvt"
#include ".config/Xresources/theme/monokai-dark
EOF