Skip to content

Instantly share code, notes, and snippets.

@nekolinuxblog
Last active March 19, 2021 12:43
Show Gist options
  • Save nekolinuxblog/630514e99ddb77d7862d25a543c29509 to your computer and use it in GitHub Desktop.
Save nekolinuxblog/630514e99ddb77d7862d25a543c29509 to your computer and use it in GitHub Desktop.
Haskell stack template for managing xmonad.hs
{-# START_FILE .gitignore #-}
# files produced by compiler
*.o
*.hi
*.errors
*.cabal
# compiled xmonad executable
xmonad-*
# files used by stack
.stack-work/
# directory created by `build` script
bin/
# files automatically created by xmonad
xmonad.state
{-# START_FILE lib/.gitignore #-}
# This file is included so that a `lib/` directory will be created.
{-# START_FILE build #-}
#!/bin/sh
#
# As of 0.13, xmonad --recompile will look for a custom build script.
set -e
stack build :{{name}}-exe --verbosity error
stack install :{{name}}-exe --local-bin-path bin/ --verbosity error
mv bin/{{name}}-exe "$1"
{-# START_FILE package.yaml #-}
name: {{name}}
version: 0.1.0.0
dependencies:
- base
- xmonad >= 0.13
- xmonad-contrib >= 0.13
#- dbus
#- utf8-string
#- X11
#- mtl
#- containers
#- data-default
#- fuzzy
#- monoid-subclasses
library:
source-dirs: lib
executables:
{{name}}-exe:
main: ./xmonad.hs
ghc-options:
- -Werror
- -fno-warn-missing-signatures
- -threaded
dependencies:
- {{name}}
{-# START_FILE xmonad.hs #-}
--------------------------------------------------------------------------------
-- shunsk's base xmonad.hs file for custamize
-- https://ok-xmonad.blogspot.com
--------------------------------------------------------------------------------
import System.Exit
import XMonad
import XMonad.Util.Run
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.DynamicLog
import qualified XMonad.StackSet as W
import XMonad.Actions.CycleWS
import XMonad.Layout.Spacing
import XMonad.Layout.Renamed
import XMonad.Layout.MultiToggle
import XMonad.Layout.MultiToggle.Instances
import XMonad.Layout.NoBorders
import XMonad.Util.EZConfig
---------------------------------------------------------------
-- MAIN
---------------------------------------------------------------
main = do
-- xmobarを使う
h <- spawnPipe "xmobar -f 'xft:IPAGothic:size=14:medium:antialias=true'"
-- xmonadの実行
xmonad
$ docks
$ def { terminal = "xterm -fa Monospace -fs 14"
, modMask = mod4Mask
, focusFollowsMouse = False
, workspaces = map show [1..9 ::Int]
, borderWidth  = 3
, normalBorderColor = "#cccccc"
, focusedBorderColor= "#00bbff"
, manageHook = manageHook def
, handleEventHook = handleEventHook def
, layoutHook = mylayouthook
, logHook = myXmobarLogHook h
, keys = \c -> mkKeymap c (keyMapDataList c)
}
---------------------------------------------
-- ステータスバー表示のカスタマイズ
---------------------------------------------
-- xmobar用
myXmobarLogHook h =
dynamicLogWithPP
xmobarPP
{ ppOutput = hPutStrLn h
, ppCurrent = xmobarColor "#FF9F1C" "#1A1B41" . pad . wrap "[" "]"
, ppTitle = xmobarColor "#1A1B41" "#C2E7DA" . shorten 50 . pad
}
---------------------------------------------
-- レイアウト
---------------------------------------------
mylayouthook
= smartBorders $ avoidStruts (mytall ||| mymirror) ||| myfull
where
mytall
= renamed [CutWordsLeft 1]
$ spacingRaw True (Border 10 10 10 10) True (Border 5 5 5 5) True
$ Tall 1 0.03 0.5
mymirror
= Mirror mytall
myfull
= noBorders
$ Full
---------------------------------------------
-- キーバインド関連
---------------------------------------------
keyMapDataList :: XConfig Layout -> [(String, X ())]
keyMapDataList conf =
[("M-S-<Return>", spawn $ XMonad.terminal conf)
,("M-p", spawn "dmenu_run")
,("M-S-c", kill)
,("M-<Space>", sendMessage NextLayout)
,("M-S-<Space>", setLayout $ XMonad.layoutHook conf)
,("M-n", refresh)
,("M-j", windows W.focusDown)
,("M-k", windows W.focusUp)
,("M-m", windows W.focusMaster)
,("M-S-j", windows W.swapDown)
,("M-S-k", windows W.swapUp)
,("M-<Return>", windows W.swapMaster)
,("M-h", sendMessage Shrink)
,("M-l", sendMessage Expand)
,("M-t", withFocused $ windows . W.sink)
,("M-,", sendMessage $ IncMasterN 1)
,("M-.", sendMessage $ IncMasterN (-1))
,("M-<R>", nextWS)
,("M-<L>", prevWS)
,("M-S-q", io (exitWith ExitSuccess))
,("M-q", spawn myRecompileCmd)
]
-- workspaceの移動等
++
[("M-" ++ m ++ show k , windows $ f i)
| (i,k) <- zip (XMonad.workspaces conf) ([1..9] :: [Int])
, (f,m) <- [(W.view, ""),(W.shift, "S-")]
]
where
myRecompileCmd =
"xmonad --recompile && (killall xmobar; xmonad --restart)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment