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