Switch back to ephemeral mode
This commit is contained in:
parent
0ff80e6fc6
commit
542fb3ee30
|
@ -3,7 +3,7 @@
|
|||
config,
|
||||
...
|
||||
}: let
|
||||
modeFile = "${config.home.homeDirectory}/.volatile/mode";
|
||||
modeFile = "${config.home.homeDirectory}/.mode";
|
||||
wallPapers = "${config.home.homeDirectory}/media/images/wallpapers";
|
||||
randomWallpaper =
|
||||
pkgs.writeHaskellScript
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
final: _: let
|
||||
inherit (final) pkgs lib;
|
||||
homeDir = "/home/maralorn";
|
||||
modeFile = "${homeDir}/.volatile/mode";
|
||||
modeFile = "${homeDir}/mode";
|
||||
modeDir = "${homeDir}/.volatile/modes";
|
||||
configPath = "${homeDir}/git/config";
|
||||
configGit = "${lib.getExe pkgs.git} -C ${configPath}";
|
||||
get_mode = ''
|
||||
mode <- decodeUtf8 @Text <$> (cat "${modeFile}" |> captureTrim)
|
||||
'';
|
||||
get_available_modes = ''
|
||||
available_modes <- Directory.listDirectory "${modeDir}"
|
||||
'';
|
||||
get_hostname = ''
|
||||
hostname <- BSC.strip <$> readFileBS "/etc/hostname"
|
||||
'';
|
||||
|
@ -48,8 +45,6 @@ final: _: let
|
|||
} ''
|
||||
main = do
|
||||
[mode] <- getArgs
|
||||
${get_available_modes}
|
||||
unless (mode `elem` available_modes) do say [i|"#{mode}" is not a known mode|]; exitFailure
|
||||
writeFile "${modeFile}" mode
|
||||
activate_mode
|
||||
ignoreFailure $ killall ["GeckoMain", "firefox", ".firefox-wrapped"]
|
||||
|
|
|
@ -15,6 +15,8 @@ import Say (say, sayErr)
|
|||
import Shh (ExecReference (Absolute), Proc, captureTrim, exe, ignoreFailure, load, readInputLines, (&>), (|>))
|
||||
import Shh qualified
|
||||
import System.Directory (listDirectory)
|
||||
import System.Environment (getEnv)
|
||||
import System.FilePath ((</>))
|
||||
|
||||
data Mode = Klausur | Orga | Communication | Code | Leisure | Unrestricted deriving (Eq, Ord, Show, Enum, Bounded)
|
||||
|
||||
|
@ -23,9 +25,10 @@ load Absolute ["git", "khal", "playerctl", "notmuch", "readlink", "nix", "nix-di
|
|||
modes :: [Mode]
|
||||
modes = enumFrom Klausur
|
||||
|
||||
getMode :: IO Mode
|
||||
getMode = do
|
||||
name <- decodeUtf8 . ByteString.strip <$> readFileBS "/home/maralorn/.volatile/mode" `onException` sayErr "File /home/maralorn/.mode not found."
|
||||
getMode :: FilePath -> IO Mode
|
||||
getMode home = do
|
||||
let mode_file = home </> ".mode"
|
||||
name <- decodeUtf8 . ByteString.strip <$> readFileBS mode_file `onException` sayErr [i|File #{mode_file} not found.|]
|
||||
maybe (sayErr [i|Unknown mode #{name}|] >> error [i|Unknown mode #{name}|]) pure $ find (\mode -> name == Text.toLower (show mode)) modes
|
||||
|
||||
isDirty :: String -> IO Bool
|
||||
|
@ -150,6 +153,9 @@ white = "D9E0EE"
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
home <- getEnv "HOME"
|
||||
let git_dir = home </> "git"
|
||||
modes_dir = home </> ".volatile" </> "modes"
|
||||
mode_var <- newVar Unrestricted
|
||||
dirty_var <- newTVarIO []
|
||||
let read_mode = fst <$> readTVarIO (value mode_var)
|
||||
|
@ -188,13 +194,13 @@ main = do
|
|||
else pure 0
|
||||
when' (codeUpdates /= 0) $ withColor cyan [i|Code Updates: #{codeUpdates}|]
|
||||
, simpleModule (5 * oneSecond) do
|
||||
dirs <- listDirectory "/home/maralorn/git"
|
||||
dirty <- fmap toText <$> filterM (isDirty . ("/home/maralorn/git/" <>)) dirs
|
||||
dirs <- listDirectory git_dir
|
||||
dirty <- fmap toText <$> filterM (isDirty . (git_dir <>)) dirs
|
||||
atomically $ writeTVar dirty_var dirty
|
||||
when' (not $ null dirty) $ withColor red [i|Dirty: #{Text.intercalate " " dirty}|]
|
||||
, simpleModule (5 * oneSecond) do
|
||||
dirs <- listDirectory "/home/maralorn/git"
|
||||
unpushed <- fmap toText <$> filterM (isUnpushed . ("/home/maralorn/git/" <>)) dirs
|
||||
dirs <- listDirectory git_dir
|
||||
unpushed <- fmap toText <$> filterM (isUnpushed . (git_dir <>)) dirs
|
||||
when' (not $ null unpushed) do withColor yellow [i|Unpushed: #{Text.intercalate " " unpushed}|]
|
||||
, simpleModule (5 * oneSecond) do
|
||||
let hosts = ["hera", "fluffy"]
|
||||
|
@ -208,11 +214,11 @@ main = do
|
|||
modes_dirty_var <- newTVarIO False
|
||||
host_name <- ByteString.strip <$> readFileBS "/etc/hostname"
|
||||
let scan = do
|
||||
current_commit <- readFileBS "/home/maralorn/git/config/.git/refs/heads/main"
|
||||
current_commit <- readFileBS (git_dir </> "config/.git/refs/heads/main")
|
||||
system_commit <- Exception.try do readFileBS "/run/current-system/config-commit"
|
||||
modes_commit <- Exception.try do readFileBS "/home/maralorn/.volatile/modes/config-commit"
|
||||
modes_commit <- Exception.try do readFileBS (modes_dir </> "config-commit")
|
||||
current_system <- readlink "/run/current-system" |> captureTrim
|
||||
current_modes <- readlink "/home/maralorn/.volatile/modes" |> captureTrim
|
||||
current_modes <- readlink modes_dir |> captureTrim
|
||||
let stale_config :: Either Exception.IOException ByteString -> Bool = \case
|
||||
(Right commit) | commit == current_commit -> False
|
||||
_ -> True
|
||||
|
@ -251,7 +257,7 @@ main = do
|
|||
onUpdate mode_var $ updateVarIfChanged var . runIdentity . withColor blue . show
|
||||
]
|
||||
foldConcurrently_
|
||||
[ void $ simpleModule oneSecond getMode mode_var
|
||||
[ void $ simpleModule oneSecond (getMode home) mode_var
|
||||
, runModules modules
|
||||
]
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ executable status-script
|
|||
, base ^>=4.16.4.0
|
||||
, bytestring
|
||||
, directory
|
||||
, filepath
|
||||
, reflex
|
||||
, relude
|
||||
, say
|
||||
|
|
Loading…
Reference in a new issue