diff --git a/modules/workspace/i3blocks/default.nix b/modules/workspace/i3blocks/default.nix
index e09c029..77260fa 100644
--- a/modules/workspace/i3blocks/default.nix
+++ b/modules/workspace/i3blocks/default.nix
@@ -38,9 +38,9 @@ in {
interval=60
markup=pango
'' + genIniOrdered (optional (!isNull config.secrets.mail) (scr "email")
- ++ [ (scrint "weather" 600) (scr "calendar") (scr "emacs") ]
+ ++ [ (scrint "weather" 600) (scr "calendar") (scr "emacs") (scr "nixos") ]
++ optional (!isNull config.secrets.wage) (scrint "youtrack-wage" 3600)
- ++ [ (scrint "music" 10) (scrint "sound" 5) ] ++ [
+ ++ [ (scrint "music" 3) (scrint "sound" 1) ] ++ [
(scrint "cpu" 5)
(scrint "freq" 10)
(scr "temperature")
@@ -50,5 +50,5 @@ in {
(scrint "brightness" 5)
]
++ optional (config.deviceSpecific.devInfo ? bigScreen) (scrint "network" 1)
- ++ [ (scrint "connections" 10) (scr "df") (scr "date") (scrint "time" 1) ]);
+ ++ [ (scrint "bluetooth" 3) (scrint "connections" 3) (scr "df") (scr "date") (scrint "time" 1) ]);
}
diff --git a/modules/workspace/i3blocks/scripts/battery.nix b/modules/workspace/i3blocks/scripts/battery.nix
index b2c494c..576a1b4 100644
--- a/modules/workspace/i3blocks/scripts/battery.nix
+++ b/modules/workspace/i3blocks/scripts/battery.nix
@@ -5,18 +5,18 @@
CHARGE=`awk -F'[,%] ' '{print $2}' <<< "$BATTERY" | tr -d "%"`
TIME=`awk -F', ' '{print $3}' <<< "$BATTERY" | cut -d " " -f 1 | cut -d: -f1-2`
case "$STATUS" in
- Full) ;& "Not charging") icon=; TEXT="FULL"; status=0
+ Full) ;& "Not charging") icon=; TEXT="FULL"; status=0
;;
Charging)
TEXT="$CHARGE% ($TIME)"
status=0
case $CHARGE in
- [2-3]*) icon=;;
- [4-5]*) icon=;;
- [6-7]*) icon=;;
- [8-9]*) icon=;;
- 100) icon=;;
- *) icon=;;
+ [2-3]*) icon=;;
+ [4-5]*) icon=;;
+ [6-7]*) icon=;;
+ [8-9]*) icon=;;
+ 100) icon=;;
+ *) icon=;;
esac
;;
Discharging)
@@ -28,17 +28,17 @@
fi
TEXT="$CHARGE% ($TIME)";
case $CHARGE in
- 1?) icon=;;
- 2?) icon=;;
- 3?) icon=;;
- 4?) icon=;;
- 5?) icon=;;
- 6?) icon=;;
- 7?) icon=;;
- 8?) icon=;;
- 9?) icon=;;
- 100) icon=;;
- *) ;;
+ 1?) icon=;;
+ 2?) icon=;;
+ 3?) icon=;;
+ 4?) icon=;;
+ 5?) icon=;;
+ 6?) icon=;;
+ 7?) icon=;;
+ 8?) icon=;;
+ 9?) icon=;;
+ 100) icon=;;
+ *) ;;
esac
;;
esac
diff --git a/modules/workspace/i3blocks/scripts/bluetooth.nix b/modules/workspace/i3blocks/scripts/bluetooth.nix
new file mode 100644
index 0000000..988347e
--- /dev/null
+++ b/modules/workspace/i3blocks/scripts/bluetooth.nix
@@ -0,0 +1,21 @@
+{ iconfont, bash, bluez, pulseaudio, utillinux, ... }:
+''
+ #!${bash}/bin/bash
+ if ${utillinux}/bin/rfkill | grep bluetooth > /dev/null; then
+ if ${utillinux}/bin/rfkill | grep bluetooth | grep blocked > /dev/null; then
+ if ${bluez}/bin/bluetoothctl info > /dev/null; then
+ if ${pulseaudio}/bin/pactl list sinks | grep bluez > /dev/null; then
+ echo ""
+ exit 33
+ else
+ echo ""
+ fi
+ else
+ echo ""
+ fi
+ else
+ echo ""
+ exit 33
+ fi
+ fi
+''
diff --git a/modules/workspace/i3blocks/scripts/connections.nix b/modules/workspace/i3blocks/scripts/connections.nix
index 455cddc..ef06187 100644
--- a/modules/workspace/i3blocks/scripts/connections.nix
+++ b/modules/workspace/i3blocks/scripts/connections.nix
@@ -5,56 +5,58 @@
for connection in $CONNECTIONS
do
grep wifi <<< $connection > /dev/null && {
- SIGNAL=$(${networkmanager}/bin/nmcli d w | grep '^\*' | tr -s ' ' | cut -d' ' -f7)
- if [[ $SIGNAL -lt 20 ]]
- then
- text+=冷
- elif [[ $SIGNAL -lt 40 ]]
- then
- text+=爛
- elif [[ $SIGNAL -lt 60 ]]
- then
- text+=嵐
- elif [[ $SIGNAL -lt 80 ]]
- then
- text+=襤
- else
- text+=蠟
- fi
+ # SIGNAL=$(${networkmanager}/bin/nmcli d w | grep '^\*' | tr -s ' ' | cut -d' ' -f7)
+ # if [[ $SIGNAL -lt 20 ]]
+ # then
+ # text+=冷
+ # elif [[ $SIGNAL -lt 40 ]]
+ # then
+ # text+=爛
+ # elif [[ $SIGNAL -lt 60 ]]
+ # then
+ # text+=嵐
+ # elif [[ $SIGNAL -lt 80 ]]
+ # then
+ # text+=襤
+ # else
+ # text+=蠟
+ # fi
+ text=
}
grep gsm <<< $connection >/dev/null && {
MODEM=$(${modemmanager}/bin/mmcli -K -L | tail -1 | cut -d: -f2 | tr -d ' ')
STATUS=$(${modemmanager}/bin/mmcli -K -m $MODEM)
TECH=$(grep "modem.generic.access-technologies.value\[1\]" <<< $STATUS | cut -d: -f2 | tr -d ' ')
-
- SIGNAL=$(grep "modem.generic.signal-quality.value" <<< $STATUS | cut -d: -f2 | tr -d ' ')
- if [[ $SIGNAL -lt 20 ]]
- then
- text+=""
- elif [[ $SIGNAL -lt 40 ]]
- then
- text+=""
- elif [[ $SIGNAL -lt 60 ]]
- then
- text+=""
- elif [[ $SIGNAL -lt 80 ]]
- then
- text+=""
- else
- text+=""
- fi
+
+ # SIGNAL=$(grep "modem.generic.signal-quality.value" <<< $STATUS | cut -d: -f2 | tr -d ' ')
+ # if [[ $SIGNAL -lt 20 ]]
+ # then
+ # text+=""
+ # elif [[ $SIGNAL -lt 40 ]]
+ # then
+ # text+=""
+ # elif [[ $SIGNAL -lt 60 ]]
+ # then
+ # text+=""
+ # elif [[ $SIGNAL -lt 80 ]]
+ # then
+ # text+=""
+ # else
+ # text+=""
+ # fi
+ text+=
if [[ $TECH == lte ]]
then
- text+=""
+ text+="ﰒ"
else
- text+=""
+ text+="ﰑ"
fi
}
- grep ethernet <<< $connection > /dev/null && text+=""
+ grep ethernet <<< $connection > /dev/null && text+=""
done
code=0
[[ $text == "" ]] && {
- text=
+ text=
code=33
}
echo "$text"
diff --git a/modules/workspace/i3blocks/scripts/default.nix b/modules/workspace/i3blocks/scripts/default.nix
index 3496aa6..30f3c02 100644
--- a/modules/workspace/i3blocks/scripts/default.nix
+++ b/modules/workspace/i3blocks/scripts/default.nix
@@ -1,33 +1,40 @@
p: c:
with p;
-builtins.mapAttrs (name: value:
-stdenv.mkDerivation {
- inherit name;
- src = value;
- unpackPhase = "true";
- buildInputs = [ghc];
- buildPhase = "ghc -o $out $src";
- installPhase = "true";
-}) {
+let
+ iconfont = "Material Icons";
+ buildHaskellScript = name: script:
+ stdenv.mkDerivation {
+ inherit name;
+ src = script;
+ unpackPhase = "true";
+ buildInputs = [ghc];
+ buildPhase = "ghc -o $out $src";
+ installPhase = "true";
+ ICONFONT = iconfont;
+ };
+ writeScript = name: script:
+ writeTextFile {
+ inherit name;
+ text = callPackage script {
+ inherit iconfont;
+ config = c;
+ };
+ executable = true;
+ checkPhase =
+ "${bash}/bin/bash -n $src || ${python3}/bin/python3 -m compileall $src";
+ };
+in
+builtins.mapAttrs buildHaskellScript {
free = ./free.hs;
temperature = ./temperature.hs;
network = ./network.hs;
-} // builtins.mapAttrs (name: value:
-writeTextFile {
- inherit name;
- text = callPackage value {
- iconfont = "Material Design Icons";
- config = c;
- };
- executable = true;
- checkPhase =
- "${bash}/bin/bash -n $src || ${python3}/bin/python3 -m compileall $src";
-}) {
+} // builtins.mapAttrs writeScript {
battery = ./battery.nix;
brightness = ./brightness.nix;
calendar = ./calendar.nix;
email = ./email.nix;
emacs = ./emacs.nix;
+ bluetooth = ./bluetooth.nix;
connections = ./connections.nix;
weather = ./weather.nix;
sound = ./sound.nix;
@@ -35,9 +42,10 @@ writeTextFile {
youtrack-wage = ./youtrack-wage.nix;
cpu = {...}: ''top -b -n1 -p 1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' -v prefix="$prefix" '{ split($1, vs, ","); v=vs[length(vs)]; sub("%", "", v); printf "%s%.1f%%\n", prefix, 100 - v }' '';
freq = {...}: ''echo $(${pkgs.bc}/bin/bc -l <<< "scale=2; `cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq|sort|tail -1`/1000000") GHz'';
- df = {...}: ''echo '' `df / | tail -1 | grep -o '..%'`'';
- date = {...}: "${pkgs.coreutils}/bin/date +' %a %y-%m-%d'";
- time = {...}: "${pkgs.coreutils}/bin/date +' %T'";
+ df = {...}: ''echo '' `df / | tail -1 | grep -o '..%'`'';
+ date = {...}: "${pkgs.coreutils}/bin/date +' %a %y-%m-%d'";
+ time = {...}: "${pkgs.coreutils}/bin/date +' %T'";
+ nixos = {...}: "echo -n ''; cat /run/current-system/nixos-version | cut -d. -f3";
#temperature = ./temperature.nix;
#free = ./free.nix;
}
diff --git a/modules/workspace/i3blocks/scripts/emacs.nix b/modules/workspace/i3blocks/scripts/emacs.nix
index d5c3aa6..53c3cd8 100644
--- a/modules/workspace/i3blocks/scripts/emacs.nix
+++ b/modules/workspace/i3blocks/scripts/emacs.nix
@@ -1,4 +1,7 @@
-{...}: ''
- [[ $BLOCK_BUTTON -eq 2 ]] && emacsclient --eval "(org-clock-out)" > /dev/null
- emacsclient --eval "org-mode-line-string" | head -1 | cut -d\" -f 2
+{ config, ... }:
+let ec = "${config.home-manager.users.balsoft.programs.emacs.finalPackage}/bin/emacsclient";
+in
+''
+ [[ $BLOCK_BUTTON -eq 2 ]] && ${ec} --eval "(org-clock-out)" > /dev/null
+ ${ec} --eval "org-mode-line-string" | head -1 | cut -d\" -f 2
''
diff --git a/modules/workspace/i3blocks/scripts/email.nix b/modules/workspace/i3blocks/scripts/email.nix
index 139a39b..556deca 100644
--- a/modules/workspace/i3blocks/scripts/email.nix
+++ b/modules/workspace/i3blocks/scripts/email.nix
@@ -5,6 +5,9 @@
obj.login("${config.secrets.mail.user}@${config.secrets.mail.host}", "${config.secrets.mail.password}")
obj.select()
l = len(obj.search(None, 'unseen')[1][0].split())
- print(' %s' % str(l))
- exit(33 if l != 0 else 0)
+ if l == 0:
+ print('')
+ else:
+ print(' %s' % str(l))
+ exit(33)
''
diff --git a/modules/workspace/i3blocks/scripts/music.nix b/modules/workspace/i3blocks/scripts/music.nix
index be995e6..af2fa33 100644
--- a/modules/workspace/i3blocks/scripts/music.nix
+++ b/modules/workspace/i3blocks/scripts/music.nix
@@ -8,12 +8,11 @@
if BLOCK_BUTTON == "1": call(["${playerctl}/bin/playerctl", "play-pause"])
if BLOCK_BUTTON == "2": call(["${playerctl}/bin/playerctl", "stop"])
if BLOCK_BUTTON == "3": call(["${playerctl}/bin/playerctl", "next"])
- if status == "Paused":
- icon=""
- elif status == "Playing":
- icon=""
- else:
- icon = ""
- text = getoutput("${playerctl}/bin/playerctl metadata title")[:20:]
+ if status == "Paused" or status == "Playing":
+ text = getoutput("${playerctl}/bin/playerctl metadata title")[:20:]
+ icon = ""
+ else:
+ text = ""
+ icon = ""
print("%s %s" % (icon, text.replace('&', '&')))
''
diff --git a/modules/workspace/i3blocks/scripts/network.hs b/modules/workspace/i3blocks/scripts/network.hs
index 663e0c2..3454610 100644
--- a/modules/workspace/i3blocks/scripts/network.hs
+++ b/modules/workspace/i3blocks/scripts/network.hs
@@ -1,9 +1,12 @@
-{-# LANGUAGE BangPatterns #-}
+{-# LANGUAGE BangPatterns, TemplateHaskell #-}
import Control.Concurrent (threadDelay)
-import Control.Monad (mapM)
+import Control.Monad (mapM, join)
import System.Directory (listDirectory)
import Data.Bool (bool)
+import Language.Haskell.TH.Syntax (liftString, runIO)
+import System.Environment (getEnv)
+import Control.Monad.IO.Class (liftIO)
path :: String
path = "/sys/class/net/"
@@ -17,7 +20,7 @@ instance Monoid Statistics where
mempty = Statistics 0 0
icon :: String -> String
-icon i = "" ++ i ++ ""
+icon i = "" ++ i ++ ""
readInterface :: FilePath -> IO Statistics
readInterface interface = do
diff --git a/modules/workspace/i3blocks/scripts/sound.nix b/modules/workspace/i3blocks/scripts/sound.nix
index f78254c..e021a96 100644
--- a/modules/workspace/i3blocks/scripts/sound.nix
+++ b/modules/workspace/i3blocks/scripts/sound.nix
@@ -9,19 +9,19 @@
then
volume=""
end=""
- icon=""
+ icon="婢"
else
volume=`${pamixer}/bin/pamixer --get-volume`
end="%"
if [[ $volume -lt 33 ]]
then
- icon=""
+ icon="奄"
else
if [[ $volume -lt 66 ]]
then
- icon=""
+ icon="奔"
else
- icon=""
+ icon="墳"
code=33
fi
fi
diff --git a/modules/workspace/i3blocks/scripts/temperature.hs b/modules/workspace/i3blocks/scripts/temperature.hs
index 722b7b9..9f0a28d 100644
--- a/modules/workspace/i3blocks/scripts/temperature.hs
+++ b/modules/workspace/i3blocks/scripts/temperature.hs
@@ -1,11 +1,19 @@
+{-# LANGUAGE TemplateHaskell, OverloadedStrings #-}
+
+import Prelude hiding (readFile)
import System.Directory
import System.FilePath
-import Control.Monad (forM)
+import Control.Monad (forM, join)
import System.Posix.Files
import Data.List (isPrefixOf, isInfixOf)
import System.Exit
-
-
+import Language.Haskell.TH.Syntax (liftString, runIO)
+import System.Environment (getEnv)
+import Control.Monad.IO.Class (liftIO)
+import Data.Maybe (catMaybes)
+import Control.Exception
+import Data.Text (unpack)
+import Data.Text.IO (readFile)
-- | Traverse from 'top' directory and return all the files by
-- filtering with 'include' predicate.
@@ -31,7 +39,7 @@ getTemps = do
-> ("hwmon" `isPrefixOf` name)
|| ("temp" `isInfixOf` name) && ("input" `isInfixOf` name)
)
- fmap (round .(/1000) . read) <$> traverse (readFile) hwmons
+ fmap (round . (/1000) . read . unpack) <$> traverse (handle (\e -> do pure (e :: IOException); pure "0") . readFile) hwmons
-- | Get a symbol corresponding to the temperature
getSymbol :: Integral n => n -> String
@@ -40,6 +48,9 @@ getSymbol t
| t < 80 = "\57866" --
| otherwise = "\57867" --
+icon :: String -> String
+icon s = "" ++ s ++ ""
+
main :: IO ()
main = do
maxTemp <- maximum <$> getTemps
diff --git a/modules/workspace/i3blocks/scripts/youtrack-wage.nix b/modules/workspace/i3blocks/scripts/youtrack-wage.nix
index 99de5cb..4d58289 100644
--- a/modules/workspace/i3blocks/scripts/youtrack-wage.nix
+++ b/modules/workspace/i3blocks/scripts/youtrack-wage.nix
@@ -1,6 +1,11 @@
{ bash, yt-utilities, libqalculate, config, lib, ... }:
+let ec = config.home-manager.users.balsoft.programs.emacs.finalPackage;
+in
''
#!${bash}/bin/bash
+ set -euo pipefail
+ export PATH="$PATH:${yt-utilities}/bin:${ec}/bin:${libqalculate}/bin"
+
HOURS_DAY=$(yt org local --since $(date +'%Y-%m-%d') | tail -1)
HOURS_MONTH=$(yt org local --since $(date +'%Y-%m-01') | tail -1)
HOURS_YEAR=$(yt org local --since $(date +'%Y-01-01') | tail -1)