Compare commits

...

17 commits
master ... sam

4 changed files with 128 additions and 47 deletions

View file

@ -10,6 +10,7 @@ import Graphics.X11.Types
import System.Exit
import Text.EditDistance
import XMonad
import XMonad.Actions.CopyWindow (kill1,copy)
import XMonad.Actions.CycleWS
import XMonad.Actions.DynamicProjects
import XMonad.Core
@ -18,12 +19,16 @@ import XMonad.Operations
import XMonad.Prompt
import XMonad.Prompt.ConfirmPrompt
import XMonad.Prompt.Shell
import XMonad.Prompt.Workspace (workspacePrompt)
import XMonad.Util.EZConfig
import XMonad.Util.NamedScratchpad
import qualified Solarized as S
import qualified Scratchpad as R
import qualified XMonad.StackSet as W
-- Custom (in libs)
import Password (passPrompt)
modify :: XConfig l -> XConfig l
modify conf = conf
{ modMask = mod4Mask -- Use the "Win" key for the mod key
@ -36,7 +41,6 @@ modify conf = conf
, ("<XF86AudioPlay>", spawn "/run/current-system/sw/bin/mpc toggle")
, ("<XF86AudioNext>", spawn "/run/current-system/sw/bin/mpc next")
, ("<XF86AudioPrev>", spawn "/run/current-system/sw/bin/mpc prev")
, ("M-<Delete>", kill)
, ("M-<Down>", windows W.focusDown)
, ("M-<Esc>", sendMessage (Toggle "Full"))
, ("M-$", sendMessage (Toggle "Full"))
@ -57,8 +61,12 @@ modify conf = conf
, ("M-p n", switchProjectPrompt promptConfig)
, ("M-p r", renameProjectPrompt promptConfig)
, ("M-p s", shellPrompt promptConfig)
, ("M-d", passPrompt promptConfig)
-- Scratchpads
, ("M-p p", namedScratchpadAction R.pads "htop")
-- Copy windows to workspaces
, ("M-<Delete>", kill1)
, ("M-c", workspacePrompt promptConfig (\name -> windows $ copy name))
]
viewProject :: WorkspaceId -> X ()
@ -77,7 +85,7 @@ promptConfig = def
, defaultText = ""
, fgColor = S.base02
, fgHLight = S.base03
, font = "xft:Iosevka Term:style=Regular:size=8"
, font = "xft:Iosevka Samae:style=Regular:size=8"
, height = 24
, promptBorderWidth = 5
}
@ -94,3 +102,4 @@ fuzzyPrompt config = do
in map snd $ take 20 $ sort $ map (\c -> (weight c,c)) cmds
mkXPrompt FuzzySpawn config (return . compl) spawn
-- https://github.com/MasseR/xmonad-masser/blob/master/src/XMonad/Password.hs

55
lib/Password.hs Normal file
View file

@ -0,0 +1,55 @@
-- Initially from
-- https://github.com/MasseR/xmonad-masser/blob/master/src/XMonad/Password.hs
module Password (passGeneratePrompt, passPrompt) where
import Control.Monad.Trans (liftIO)
import Data.Function (on)
import Data.List (foldl', scanl', sort, sortBy)
import System.Directory (getHomeDirectory)
import System.FilePath.Posix (dropExtension, takeExtension, (</>))
import System.Posix.Env (getEnv)
import XMonad.Core
import XMonad.Prompt
import XMonad.Util.Run (runProcessWithInput)
newtype Pass = Pass { passLabel :: String }
-- Rosetta code levenshtein
levenshtein :: String -> String -> Int
levenshtein s1 s2 = last $ foldl' transform [0..length s1] s2
where
transform [] _ = []
transform ns@(n:ns1) c = scanl' calc (n+1) $ zip3 s1 ns ns1
where
calc z (c1, x, y) = minimum [y+1, z+1, x + (fromEnum (c1 /= c) * 2)]
instance XPrompt Pass where
showXPrompt p = passLabel p <> ": "
commandToComplete _ = id
nextCompletion _ = getNextCompletion
passGeneratePrompt :: XPConfig -> X ()
passGeneratePrompt _ = return () -- Not implemented
passPrompt :: XPConfig -> X ()
passPrompt = mkPassPrompt "Select password" copyPassword
mkPassPrompt :: String -> (String -> X ()) -> XPConfig -> X ()
mkPassPrompt label f conf = do
-- I'm just sorting here, but could use some kind of fuzzy matching instead, but it requires a bit more effort
passwords <- sort <$> liftIO getPasswords
-- Other change, use infixof instead of prefixof
mkXPrompt (Pass label) conf (\input -> pure (sortBy (compare `on` levenshtein input) . filter (consumes input) $ passwords)) f
where
consumes [] _ = True -- everything consumed
consumes (_:_) [] = False -- all not consumed
consumes (a:xs) (a':ys) | a == a' = consumes xs ys
| otherwise = consumes (a:xs) ys
getPasswords = do
passwordStoreDir <- (</> "pass") <$> getHomeDirectory
files <- runProcessWithInput "find" [ passwordStoreDir, "-type", "f", "-name", "*.gpg", "-printf", "%p\n"] []
return . lines $ files
copyPassword :: String -> X ()
copyPassword pass = spawn $ "gpg --decrypt " ++ pass ++ " | /home/eeva/.nix-profile/bin/copy"

View file

@ -6,26 +6,51 @@ import XMonad
import XMonad.Actions.DynamicProjects
import XMonad.Util.Run
spinVimAndSt :: String -> String -> Project
spinVimAndSt dir name =
Project { projectName = name
, projectDirectory = dir <> name
, projectStartHook = Just $ do safeSpawn "vim" ["-g", "+set guifont=Victor\\ Mono\\ SemiBold\\ 18|e ."]
safeSpawn "st" ["-f","Iosevka Samae-18","-e","tmux","new","-A","-s",name]
}
adminProject = spinVimAndSt "~/admin/"
candyProject = spinVimAndSt "~/candy/"
workProject = spinVimAndSt "~/relex/"
projects :: [Project]
projects = [ Project { projectName = "admin"
, projectDirectory = "~/admin"
, projectStartHook = Just $ do safeSpawn "vim" ["-g"]
safeSpawnProg "st"
}
, Project { projectName = "mordor"
, projectDirectory = "~/mordor"
, projectStartHook = Just $ do safeSpawn "vim" ["-g"]
safeSpawnProg "st"
}
, Project { projectName = "mordor-docs"
, projectDirectory = "~/mordor-2"
, projectStartHook = Just $ do safeSpawn "vim" ["-g"]
safeSpawnProg "st"
}
, Project { projectName = "mordor-other"
, projectDirectory = "~/mordor-3"
, projectStartHook = Just $ do safeSpawn "vim" ["-g"]
safeSpawnProg "st"
projects = [ adminProject "sam-configuration-nix"
, adminProject "cdc-config"
, candyProject "dhall-packages"
, candyProject "exercism"
, workProject "atlantis"
, workProject "azure-core-infra"
, workProject "azure-kube-platform"
, workProject "bob-the-builder"
, workProject "docker-images"
, workProject "gitlab-runners"
, workProject "heimdall"
, workProject "infra-inventory"
, workProject "isengard"
, workProject "mordor-ca"
, workProject "mordor-dashboard"
, workProject "mordor-deploy"
, workProject "mordor-kvm"
, workProject "mordor-nixpkgs"
, workProject "mordor-ops"
, workProject "mordor-the-repo"
, workProject "mordorbooks"
, workProject "muir"
, workProject "nix-role"
, workProject "nixos-modules"
, workProject "nixpkgs"
, workProject "sm-terraform"
, workProject "time-tracking"
, workProject "ugluk-ansible-role"
, Project { projectName = "status"
, projectDirectory = "/tmp"
, projectStartHook = Just $ do
safeSpawn "st" ["-f","Iosevka Samae-12","-e","gotop"]
}
, Project { projectName = "email"
, projectDirectory = "~/mail"
@ -33,47 +58,31 @@ projects = [ Project { projectName = "admin"
}
, Project { projectName = "frs"
, projectDirectory = "/tmp"
, projectStartHook = Just $ do safeSpawnProg "frs"
, projectStartHook = Just $ do safeSpawnProg "ff-work"
}
, Project { projectName = "fre"
, projectDirectory = "/tmp"
, projectStartHook = Just $ do safeSpawnProg "fre"
, projectStartHook = Just $ do safeSpawnProg "ff-eeva"
}
, Project { projectName = "network-graph"
, projectDirectory = "~/relex/catch-a-network-bug/csvplotter"
, projectStartHook = Just $ do safeSpawn "zathura" ["weekXGraph.pdf"]
safeSpawnProg "st"
}
, Project { projectName = "orc"
, projectDirectory = "/tmp"
, projectStartHook = Just $ do safeSpawnProg "st"
}
, Project { projectName = "mordor-ops"
, projectDirectory = "~/relex/mordor-ops"
, projectStartHook = Just $ do safeSpawn "vim" ["-g"]
safeSpawnProg "st"
}
, Project { projectName = "mordor-deploy"
, projectDirectory = "~/relex/mordor-deploy"
, projectStartHook = Just $ do safeSpawn "vim" ["-g"]
safeSpawnProg "st"
}
, Project { projectName = "scaleout-ops"
, projectDirectory = "~/relex/scaleout-ops"
, projectStartHook = Just $ do safeSpawn "vim" ["-g"]
safeSpawnProg "st"
}
, Project { projectName = "sound"
, projectDirectory = "/tmp"
, projectStartHook = Just $ do safeSpawnProg "pavucontrol"
}
, Project { projectName = "daily"
, Project { projectName = "meeting"
, projectDirectory = "/tmp"
, projectStartHook = Just $ do safeSpawn "nix" ["run", "nixpkgs.chromium", "-c", "chromium"]
, projectStartHook = Just $ do safeSpawnProg "chromium"
}
, Project { projectName = "notes"
, projectDirectory = "~/zk/"
, projectStartHook = Just $ do safeSpawn "vim" ["-g", "+set guifont=Victor\\ Mono\\ SemiBold\\ 18|VimwikiMakeDiaryNote"]
}
]
modify :: XConfig l -> XConfig l
modify conf = dynamicProjects projects conf
{ workspaces = [] }

View file

@ -9,10 +9,16 @@ import XMonad.Actions.DynamicProjects
import XMonad.Config.Desktop
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageHelpers
import XMonad.Layout.NoBorders (noBorders, smartBorders)
import XMonad.Layout.PerScreen
import XMonad.Layout.Reflect
import XMonad.Layout.ResizableTile (ResizableTall(..))
import XMonad.Layout.Spacing
import XMonad.Layout.ThreeColumns (ThreeCol(..))
import XMonad.Layout.ToggleLayouts (toggleLayouts)
import XMonad.Util.EZConfig
import qualified Solarized as S
@ -26,9 +32,11 @@ import Scratchpad (modify)
layouts = toggleLayouts fullscreen tiled
where
fullscreen = (noBorders Full)
tiled = smarts $ resizableTall ||| (Mirror resizableTall)
smarts = (smartSpacingWithEdge 5) . smartBorders
tiled = smarts $ ifWider (1920 + 1) wideScreen normalScreen
wideScreen = ThreeColMid 1 (5/100) (1/2)
normalScreen = resizableTall
resizableTall = ResizableTall 1 (5/100) (1/2) []
smarts = (smartSpacingWithEdge 5) . smartBorders
-- Use the `xprop' tool to get the info you need for these matches.
-- For className, use the second value that xprop gives you.