Update bar

This commit is contained in:
Alexander Bantyev 2020-07-27 00:16:19 +03:00
parent 3813989cf0
commit 89e7ee5166
Signed by: balsoft
GPG Key ID: E081FF12ADCB4AD5
12 changed files with 159 additions and 104 deletions

View File

@ -38,9 +38,9 @@ in {
interval=60 interval=60
markup=pango markup=pango
'' + genIniOrdered (optional (!isNull config.secrets.mail) (scr "email") '' + 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) ++ 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 "cpu" 5)
(scrint "freq" 10) (scrint "freq" 10)
(scr "temperature") (scr "temperature")
@ -50,5 +50,5 @@ in {
(scrint "brightness" 5) (scrint "brightness" 5)
] ]
++ optional (config.deviceSpecific.devInfo ? bigScreen) (scrint "network" 1) ++ 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) ]);
} }

View File

@ -5,18 +5,18 @@
CHARGE=`awk -F'[,%] ' '{print $2}' <<< "$BATTERY" | tr -d "%"` CHARGE=`awk -F'[,%] ' '{print $2}' <<< "$BATTERY" | tr -d "%"`
TIME=`awk -F', ' '{print $3}' <<< "$BATTERY" | cut -d " " -f 1 | cut -d: -f1-2` TIME=`awk -F', ' '{print $3}' <<< "$BATTERY" | cut -d " " -f 1 | cut -d: -f1-2`
case "$STATUS" in case "$STATUS" in
Full) ;& "Not charging") icon=; TEXT="FULL"; status=0 Full) ;& "Not charging") icon=; TEXT="FULL"; status=0
;; ;;
Charging) Charging)
TEXT="$CHARGE% ($TIME)" TEXT="$CHARGE% ($TIME)"
status=0 status=0
case $CHARGE in case $CHARGE in
[2-3]*) icon=;; [2-3]*) icon=;;
[4-5]*) icon=;; [4-5]*) icon=;;
[6-7]*) icon=;; [6-7]*) icon=;;
[8-9]*) icon=;; [8-9]*) icon=;;
100) icon=;; 100) icon=;;
*) icon=;; *) icon=;;
esac esac
;; ;;
Discharging) Discharging)
@ -28,17 +28,17 @@
fi fi
TEXT="$CHARGE% ($TIME)"; TEXT="$CHARGE% ($TIME)";
case $CHARGE in case $CHARGE in
1?) icon=;; 1?) icon=;;
2?) icon=;; 2?) icon=;;
3?) icon=;; 3?) icon=;;
4?) icon=;; 4?) icon=;;
5?) icon=;; 5?) icon=;;
6?) icon=;; 6?) icon=;;
7?) icon=;; 7?) icon=;;
8?) icon=;; 8?) icon=;;
9?) icon=;; 9?) icon=;;
100) icon=;; 100) icon=;;
*) ;; *) ;;
esac esac
;; ;;
esac esac

View File

@ -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
''

View File

@ -5,56 +5,58 @@
for connection in $CONNECTIONS for connection in $CONNECTIONS
do do
grep wifi <<< $connection > /dev/null && { grep wifi <<< $connection > /dev/null && {
SIGNAL=$(${networkmanager}/bin/nmcli d w | grep '^\*' | tr -s ' ' | cut -d' ' -f7) # SIGNAL=$(${networkmanager}/bin/nmcli d w | grep '^\*' | tr -s ' ' | cut -d' ' -f7)
if [[ $SIGNAL -lt 20 ]] # if [[ $SIGNAL -lt 20 ]]
then # then
text+= # text+=冷
elif [[ $SIGNAL -lt 40 ]] # elif [[ $SIGNAL -lt 40 ]]
then # then
text+= # text+=爛
elif [[ $SIGNAL -lt 60 ]] # elif [[ $SIGNAL -lt 60 ]]
then # then
text+= # text+=嵐
elif [[ $SIGNAL -lt 80 ]] # elif [[ $SIGNAL -lt 80 ]]
then # then
text+= # text+=襤
else # else
text+= # text+=蠟
fi # fi
text=
} }
grep gsm <<< $connection >/dev/null && { grep gsm <<< $connection >/dev/null && {
MODEM=$(${modemmanager}/bin/mmcli -K -L | tail -1 | cut -d: -f2 | tr -d ' ') MODEM=$(${modemmanager}/bin/mmcli -K -L | tail -1 | cut -d: -f2 | tr -d ' ')
STATUS=$(${modemmanager}/bin/mmcli -K -m $MODEM) STATUS=$(${modemmanager}/bin/mmcli -K -m $MODEM)
TECH=$(grep "modem.generic.access-technologies.value\[1\]" <<< $STATUS | cut -d: -f2 | tr -d ' ') 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 ' ') # SIGNAL=$(grep "modem.generic.signal-quality.value" <<< $STATUS | cut -d: -f2 | tr -d ' ')
if [[ $SIGNAL -lt 20 ]] # if [[ $SIGNAL -lt 20 ]]
then # then
text+="" # text+=""
elif [[ $SIGNAL -lt 40 ]] # elif [[ $SIGNAL -lt 40 ]]
then # then
text+="" # text+=""
elif [[ $SIGNAL -lt 60 ]] # elif [[ $SIGNAL -lt 60 ]]
then # then
text+="" # text+=""
elif [[ $SIGNAL -lt 80 ]] # elif [[ $SIGNAL -lt 80 ]]
then # then
text+="" # text+=""
else # else
text+="" # text+=""
fi # fi
text+=
if [[ $TECH == lte ]] if [[ $TECH == lte ]]
then then
text+="" text+=""
else else
text+="" text+=""
fi fi
} }
grep ethernet <<< $connection > /dev/null && text+="" grep ethernet <<< $connection > /dev/null && text+=""
done done
code=0 code=0
[[ $text == "" ]] && { [[ $text == "" ]] && {
text= text=
code=33 code=33
} }
echo "<span font='${iconfont}'>$text</span>" echo "<span font='${iconfont}'>$text</span>"

View File

@ -1,33 +1,40 @@
p: c: p: c:
with p; with p;
builtins.mapAttrs (name: value: let
stdenv.mkDerivation { iconfont = "Material Icons";
inherit name; buildHaskellScript = name: script:
src = value; stdenv.mkDerivation {
unpackPhase = "true"; inherit name;
buildInputs = [ghc]; src = script;
buildPhase = "ghc -o $out $src"; unpackPhase = "true";
installPhase = "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; free = ./free.hs;
temperature = ./temperature.hs; temperature = ./temperature.hs;
network = ./network.hs; network = ./network.hs;
} // builtins.mapAttrs (name: value: } // builtins.mapAttrs writeScript {
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";
}) {
battery = ./battery.nix; battery = ./battery.nix;
brightness = ./brightness.nix; brightness = ./brightness.nix;
calendar = ./calendar.nix; calendar = ./calendar.nix;
email = ./email.nix; email = ./email.nix;
emacs = ./emacs.nix; emacs = ./emacs.nix;
bluetooth = ./bluetooth.nix;
connections = ./connections.nix; connections = ./connections.nix;
weather = ./weather.nix; weather = ./weather.nix;
sound = ./sound.nix; sound = ./sound.nix;
@ -35,9 +42,10 @@ writeTextFile {
youtrack-wage = ./youtrack-wage.nix; 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 }' ''; 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''; 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 '<span font="Material Icons 11"></span>' `df / | tail -1 | grep -o '..%'`''; df = {...}: ''echo '<span font="${iconfont}"></span>' `df / | tail -1 | grep -o '..%'`'';
date = {...}: "${pkgs.coreutils}/bin/date +'<span font=\"Material Icons 11\"></span> %a %y-%m-%d'"; date = {...}: "${pkgs.coreutils}/bin/date +'<span font=\"${iconfont}\"></span> %a %y-%m-%d'";
time = {...}: "${pkgs.coreutils}/bin/date +'<span font=\"Material Icons 11\"></span> %T'"; time = {...}: "${pkgs.coreutils}/bin/date +'<span font=\"${iconfont}\"></span> %T'";
nixos = {...}: "echo -n '<span font=\"Material Icons 13\"></span>'; cat /run/current-system/nixos-version | cut -d. -f3";
#temperature = ./temperature.nix; #temperature = ./temperature.nix;
#free = ./free.nix; #free = ./free.nix;
} }

View File

@ -1,4 +1,7 @@
{...}: '' { config, ... }:
[[ $BLOCK_BUTTON -eq 2 ]] && emacsclient --eval "(org-clock-out)" > /dev/null let ec = "${config.home-manager.users.balsoft.programs.emacs.finalPackage}/bin/emacsclient";
emacsclient --eval "org-mode-line-string" | head -1 | cut -d\" -f 2 in
''
[[ $BLOCK_BUTTON -eq 2 ]] && ${ec} --eval "(org-clock-out)" > /dev/null
${ec} --eval "org-mode-line-string" | head -1 | cut -d\" -f 2
'' ''

View File

@ -5,6 +5,9 @@
obj.login("${config.secrets.mail.user}@${config.secrets.mail.host}", "${config.secrets.mail.password}") obj.login("${config.secrets.mail.user}@${config.secrets.mail.host}", "${config.secrets.mail.password}")
obj.select() obj.select()
l = len(obj.search(None, 'unseen')[1][0].split()) l = len(obj.search(None, 'unseen')[1][0].split())
print('<span font="${iconfont}"></span> %s' % str(l)) if l == 0:
exit(33 if l != 0 else 0) print('')
else:
print('<span font="${iconfont}"></span> %s' % str(l))
exit(33)
'' ''

View File

@ -8,12 +8,11 @@
if BLOCK_BUTTON == "1": call(["${playerctl}/bin/playerctl", "play-pause"]) if BLOCK_BUTTON == "1": call(["${playerctl}/bin/playerctl", "play-pause"])
if BLOCK_BUTTON == "2": call(["${playerctl}/bin/playerctl", "stop"]) if BLOCK_BUTTON == "2": call(["${playerctl}/bin/playerctl", "stop"])
if BLOCK_BUTTON == "3": call(["${playerctl}/bin/playerctl", "next"]) if BLOCK_BUTTON == "3": call(["${playerctl}/bin/playerctl", "next"])
if status == "Paused": if status == "Paused" or status == "Playing":
icon="" text = getoutput("${playerctl}/bin/playerctl metadata title")[:20:]
elif status == "Playing": icon = ""
icon="" else:
else: text = ""
icon = "" icon = ""
text = getoutput("${playerctl}/bin/playerctl metadata title")[:20:]
print("<span font='${iconfont}'>%s</span> %s" % (icon, text.replace('&', '&amp;'))) print("<span font='${iconfont}'>%s</span> %s" % (icon, text.replace('&', '&amp;')))
'' ''

View File

@ -1,9 +1,12 @@
{-# LANGUAGE BangPatterns #-} {-# LANGUAGE BangPatterns, TemplateHaskell #-}
import Control.Concurrent (threadDelay) import Control.Concurrent (threadDelay)
import Control.Monad (mapM) import Control.Monad (mapM, join)
import System.Directory (listDirectory) import System.Directory (listDirectory)
import Data.Bool (bool) import Data.Bool (bool)
import Language.Haskell.TH.Syntax (liftString, runIO)
import System.Environment (getEnv)
import Control.Monad.IO.Class (liftIO)
path :: String path :: String
path = "/sys/class/net/" path = "/sys/class/net/"
@ -17,7 +20,7 @@ instance Monoid Statistics where
mempty = Statistics 0 0 mempty = Statistics 0 0
icon :: String -> String icon :: String -> String
icon i = "<span font='Material Icons 11'>" ++ i ++ "</span>" icon i = "<span font='"++ $(join $ liftIO $ liftString <$> getEnv "ICONFONT") ++ "'>" ++ i ++ "</span>"
readInterface :: FilePath -> IO Statistics readInterface :: FilePath -> IO Statistics
readInterface interface = do readInterface interface = do

View File

@ -9,19 +9,19 @@
then then
volume="" volume=""
end="" end=""
icon="" icon=""
else else
volume=`${pamixer}/bin/pamixer --get-volume` volume=`${pamixer}/bin/pamixer --get-volume`
end="%" end="%"
if [[ $volume -lt 33 ]] if [[ $volume -lt 33 ]]
then then
icon="" icon=""
else else
if [[ $volume -lt 66 ]] if [[ $volume -lt 66 ]]
then then
icon="" icon="奔"
else else
icon="" icon=""
code=33 code=33
fi fi
fi fi

View File

@ -1,11 +1,19 @@
{-# LANGUAGE TemplateHaskell, OverloadedStrings #-}
import Prelude hiding (readFile)
import System.Directory import System.Directory
import System.FilePath import System.FilePath
import Control.Monad (forM) import Control.Monad (forM, join)
import System.Posix.Files import System.Posix.Files
import Data.List (isPrefixOf, isInfixOf) import Data.List (isPrefixOf, isInfixOf)
import System.Exit 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 -- | Traverse from 'top' directory and return all the files by
-- filtering with 'include' predicate. -- filtering with 'include' predicate.
@ -31,7 +39,7 @@ getTemps = do
-> ("hwmon" `isPrefixOf` name) -> ("hwmon" `isPrefixOf` name)
|| ("temp" `isInfixOf` name) && ("input" `isInfixOf` 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 -- | Get a symbol corresponding to the temperature
getSymbol :: Integral n => n -> String getSymbol :: Integral n => n -> String
@ -40,6 +48,9 @@ getSymbol t
| t < 80 = "\57866" --  | t < 80 = "\57866" -- 
| otherwise = "\57867" --  | otherwise = "\57867" -- 
icon :: String -> String
icon s = "<span font='"++ $(join $ liftIO $ liftString <$> getEnv "ICONFONT") ++ "'>" ++ s ++ "</span>"
main :: IO () main :: IO ()
main = do main = do
maxTemp <- maximum <$> getTemps maxTemp <- maximum <$> getTemps

View File

@ -1,6 +1,11 @@
{ bash, yt-utilities, libqalculate, config, lib, ... }: { bash, yt-utilities, libqalculate, config, lib, ... }:
let ec = config.home-manager.users.balsoft.programs.emacs.finalPackage;
in
'' ''
#!${bash}/bin/bash #!${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_DAY=$(yt org local --since $(date +'%Y-%m-%d') | tail -1)
HOURS_MONTH=$(yt org local --since $(date +'%Y-%m-01') | 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) HOURS_YEAR=$(yt org local --since $(date +'%Y-01-01') | tail -1)