feat(repo): initialise repository
This commit is contained in:
commit
c85e45aaee
11 changed files with 237 additions and 0 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
use flake ".#"
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
dist-newstyle
|
||||||
|
.direnv
|
||||||
|
*~
|
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Revision history for cool-haskell-project
|
||||||
|
|
||||||
|
## 0.1.0.0 -- YYYY-mm-dd
|
||||||
|
|
||||||
|
* First version. Released on an unsuspecting world.
|
14
LICENSE
Normal file
14
LICENSE
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
Version 2, December 2004
|
||||||
|
|
||||||
|
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim or modified
|
||||||
|
copies of this license document, and changing it is allowed as long
|
||||||
|
as the name is changed.
|
||||||
|
|
||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||||
|
|
65
app/Main.hs
Normal file
65
app/Main.hs
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
module Main where
|
||||||
|
|
||||||
|
import Data.List (isPrefixOf)
|
||||||
|
import Data.Maybe (fromMaybe)
|
||||||
|
import System.Environment (lookupEnv)
|
||||||
|
import System.IO (readFile')
|
||||||
|
|
||||||
|
readUptime :: String -> Int
|
||||||
|
readUptime "" = 0
|
||||||
|
readUptime uptime
|
||||||
|
| length (words uptime) > 1 = floor (read . head . words $ uptime :: Float)
|
||||||
|
| otherwise = floor (read uptime :: Float)
|
||||||
|
|
||||||
|
getUptime :: Int -> String
|
||||||
|
getUptime uptime
|
||||||
|
| uptime < 60 = remS
|
||||||
|
| uptime < 3600 = unwords [remM, remS]
|
||||||
|
| otherwise = unwords [remH, remM, remS]
|
||||||
|
where
|
||||||
|
totalM = uptime `div` 60
|
||||||
|
remS = show (uptime `mod` 60) ++ "s"
|
||||||
|
remM = show (totalM `mod` 60) ++ "m"
|
||||||
|
remH = show (totalM `div` 60) ++ "h"
|
||||||
|
|
||||||
|
getKVer :: String -> String
|
||||||
|
getKVer "" = ""
|
||||||
|
getKVer info
|
||||||
|
| length (words info) < 3 = head (words info)
|
||||||
|
| otherwise = (\(k : ks) -> k ++ " " ++ (head . tail) ks) . words $ info
|
||||||
|
|
||||||
|
findPrettyName :: [String] -> String
|
||||||
|
findPrettyName (o : os)
|
||||||
|
| "PRETTY_NAME" `isPrefixOf` o = (reverse . tail . init . takeWhile (/= '=') . reverse) o
|
||||||
|
| otherwise = findPrettyName os
|
||||||
|
|
||||||
|
parseKBFromMeminfo :: String -> Int
|
||||||
|
parseKBFromMeminfo "" = 0
|
||||||
|
parseKBFromMeminfo line = read (head . tail . words $ line) :: Int
|
||||||
|
|
||||||
|
getMemory :: String -> String
|
||||||
|
getMemory meminfo
|
||||||
|
| length (lines meminfo) < 2 = "N/A"
|
||||||
|
| otherwise = memAvail ++ "/" ++ memTotal
|
||||||
|
where
|
||||||
|
memTotal = show (parseKBFromMeminfo (head $ lines meminfo) `div` 1000) ++ "MB"
|
||||||
|
memAvail = show (parseKBFromMeminfo (head . tail . tail $ lines meminfo) `div` 1000) ++ "MB"
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
uptime <- readFile' "/proc/uptime"
|
||||||
|
version <- readFile' "/proc/version"
|
||||||
|
osRelease <- readFile' "/etc/os-release"
|
||||||
|
hostname <- readFile' "/proc/sys/kernel/hostname"
|
||||||
|
meminfo <- readFile' "/proc/meminfo"
|
||||||
|
username <- lookupEnv "USER"
|
||||||
|
putStr
|
||||||
|
( unlines
|
||||||
|
[ "\x1b[1;35m █ \x1b[1;34m" ++ fromMaybe "username" username ++ "@" ++ init hostname
|
||||||
|
, "\x1b[1;35m █ \x1b[1;34m"
|
||||||
|
, "\x1b[1;35m █ \x1b[1;34m" ++ "up\t" ++ (getUptime . readUptime) uptime
|
||||||
|
, "\x1b[1;35m ███ \x1b[1;34m" ++ "krl\t" ++ getKVer version
|
||||||
|
, "\x1b[1;35m █ ██ \x1b[1;34m" ++ "os\t" ++ (findPrettyName . lines) osRelease
|
||||||
|
, "\x1b[1;35m █ ██ \x1b[1;34m" ++ "mem\t" ++ getMemory meminfo
|
||||||
|
]
|
||||||
|
)
|
62
flake.lock
generated
Normal file
62
flake.lock
generated
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1733212471,
|
||||||
|
"narHash": "sha256-M1+uCoV5igihRfcUKrr1riygbe73/dzNnzPsmaLCmpo=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "55d15ad12a74eb7d4646254e13638ad0c4128776",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs_2": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731890469,
|
||||||
|
"narHash": "sha256-D1FNZ70NmQEwNxpSSdTXCSklBH1z2isPR84J6DQrJGs=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "5083ec887760adfe12af64830a66807423a859a7",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"treefmt": "treefmt"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"treefmt": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs_2"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1733222881,
|
||||||
|
"narHash": "sha256-JIPcz1PrpXUCbaccEnrcUS8jjEb/1vJbZz5KkobyFdM=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "treefmt-nix",
|
||||||
|
"rev": "49717b5af6f80172275d47a418c9719a31a78b53",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "treefmt-nix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
39
flake.nix
Normal file
39
flake.nix
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
description = "Haskell Project Template";
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
treefmt.url = "github:numtide/treefmt-nix";
|
||||||
|
};
|
||||||
|
outputs =
|
||||||
|
inputs@{ nixpkgs, ... }:
|
||||||
|
let
|
||||||
|
inherit (nixpkgs) lib;
|
||||||
|
systems = [ "x86_64-linux" ];
|
||||||
|
forAllSystems =
|
||||||
|
f:
|
||||||
|
lib.genAttrs systems (
|
||||||
|
system:
|
||||||
|
f {
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
treefmtEval = forAllSystems ({ pkgs }: inputs.treefmt.lib.evalModule pkgs ./flake/treefmt.nix);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
packages = forAllSystems (
|
||||||
|
{ pkgs }:
|
||||||
|
{
|
||||||
|
default = pkgs.callPackage ./flake/package.nix { };
|
||||||
|
}
|
||||||
|
);
|
||||||
|
devShells = forAllSystems (
|
||||||
|
{ pkgs }:
|
||||||
|
{
|
||||||
|
default = pkgs.callPackage ./flake/shell.nix { };
|
||||||
|
}
|
||||||
|
);
|
||||||
|
formatter = forAllSystems ({ pkgs }: treefmtEval.${pkgs.system}.config.build.wrapper);
|
||||||
|
};
|
||||||
|
}
|
4
flake/package.nix
Normal file
4
flake/package.nix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{ haskellPackages }:
|
||||||
|
haskellPackages.developPackage {
|
||||||
|
root = ../.;
|
||||||
|
}
|
14
flake/shell.nix
Normal file
14
flake/shell.nix
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
mkShell,
|
||||||
|
haskellPackages,
|
||||||
|
}:
|
||||||
|
mkShell {
|
||||||
|
name = "haskell";
|
||||||
|
packages = builtins.attrValues {
|
||||||
|
inherit (haskellPackages)
|
||||||
|
haskell-language-server
|
||||||
|
ormolu
|
||||||
|
ghc
|
||||||
|
;
|
||||||
|
};
|
||||||
|
}
|
5
flake/treefmt.nix
Normal file
5
flake/treefmt.nix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
_: {
|
||||||
|
projectRootFile = ".git/config";
|
||||||
|
programs.nixfmt.enable = true;
|
||||||
|
programs.ormolu.enable = true;
|
||||||
|
}
|
25
hetch.cabal
Normal file
25
hetch.cabal
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
cabal-version: 3.0
|
||||||
|
name: hetch
|
||||||
|
version: 0.1.0.0
|
||||||
|
-- synopsis:
|
||||||
|
-- description:
|
||||||
|
license: WTFPL
|
||||||
|
license-file: LICENSE
|
||||||
|
author: Artur Manuel
|
||||||
|
maintainer: balkenix@outlook.com
|
||||||
|
-- copyright:
|
||||||
|
build-type: Simple
|
||||||
|
extra-doc-files: CHANGELOG.md
|
||||||
|
-- extra-source-files:
|
||||||
|
|
||||||
|
common warnings
|
||||||
|
ghc-options: -Wall
|
||||||
|
|
||||||
|
executable hetch
|
||||||
|
import: warnings
|
||||||
|
main-is: Main.hs
|
||||||
|
-- other-modules:
|
||||||
|
-- other-extensions:
|
||||||
|
build-depends: base ^>=4.18.2.1
|
||||||
|
hs-source-dirs: app
|
||||||
|
default-language: GHC2021
|
Loading…
Add table
Add a link
Reference in a new issue