2022-12-09 00:31:56 +00:00
|
|
|
|
with import ./lib;
|
|
|
|
|
{ pkgs }:
|
2016-06-03 13:05:00 +00:00
|
|
|
|
let
|
|
|
|
|
q-cal = let
|
2017-03-06 11:45:56 +00:00
|
|
|
|
|
|
|
|
|
# Maximum width of cal's output.
|
|
|
|
|
calwidth = 23;
|
|
|
|
|
|
|
|
|
|
# Number of space characters between two calendars.
|
|
|
|
|
hspace = 2;
|
|
|
|
|
|
|
|
|
|
# Return number of columns required to print n calenders side by side.
|
2023-01-29 12:11:55 +00:00
|
|
|
|
need_width = n: assert n >= 1; n * calwidth + (n - 1) * hspace;
|
2017-03-06 11:45:56 +00:00
|
|
|
|
|
2019-01-16 19:24:53 +00:00
|
|
|
|
in /* sh */ ''
|
2017-03-06 11:45:56 +00:00
|
|
|
|
cols=$(${pkgs.ncurses}/bin/tput cols)
|
2023-01-29 12:11:55 +00:00
|
|
|
|
if test $cols -ge ${toString (need_width 3)}; then
|
|
|
|
|
${pkgs.utillinux}/bin/cal --color=always -mw3
|
|
|
|
|
elif test $cols -ge ${toString (need_width 2)}; then
|
|
|
|
|
${pkgs.utillinux}/bin/cal --color=always -mw -n 2
|
|
|
|
|
elif test $cols -ge ${toString (need_width 1)}; then
|
|
|
|
|
${pkgs.utillinux}/bin/cal --color=always -mw1
|
|
|
|
|
else
|
|
|
|
|
:
|
|
|
|
|
fi |
|
|
|
|
|
${pkgs.gnused}/bin/sed -r '
|
|
|
|
|
# dim week numbers
|
|
|
|
|
s/((^ *| )[ 1-5][0-9]( *)?)(([ 1-3][0-9])*)/[38;5;243m\1[m\4/g
|
|
|
|
|
# dim month and day names
|
|
|
|
|
s/^ *[A-Z].*/[38;5;243m&[m/
|
|
|
|
|
# highlight current date
|
|
|
|
|
s/\[7m/[38;5;009;1m/
|
|
|
|
|
s/\[27m/[m/
|
|
|
|
|
'
|
2016-06-03 13:05:00 +00:00
|
|
|
|
'';
|
|
|
|
|
|
2019-01-16 19:24:53 +00:00
|
|
|
|
q-isodate = /* sh */ ''
|
2016-06-03 13:05:00 +00:00
|
|
|
|
${pkgs.coreutils}/bin/date \
|
|
|
|
|
'+[1m%Y-%m-%d[;30mT[;38;5;085m%H:%M[m:%S%:z'
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
# Singapore's red is #ED2E38
|
2019-01-16 19:24:53 +00:00
|
|
|
|
q-sgtdate = /* sh */ ''
|
2016-06-03 13:05:00 +00:00
|
|
|
|
TZ=Asia/Singapore \
|
|
|
|
|
${pkgs.coreutils}/bin/date \
|
|
|
|
|
'+[1m%Y-%m-%d[;30mT[;38;5;088m%H:%M[m:%S%:z'
|
|
|
|
|
'';
|
|
|
|
|
|
2019-01-16 19:24:53 +00:00
|
|
|
|
q-utcdate = /* sh */ ''
|
2018-11-08 18:09:11 +00:00
|
|
|
|
${pkgs.coreutils}/bin/date -u \
|
|
|
|
|
'+[1m%Y-%m-%d[;30mT[;38;5;065m%H:%M[m:%S%:z'
|
|
|
|
|
'';
|
|
|
|
|
|
2019-01-16 19:24:53 +00:00
|
|
|
|
q-gitdir = /* sh */ ''
|
2016-06-03 13:05:00 +00:00
|
|
|
|
if test -d .git; then
|
|
|
|
|
#git status --porcelain
|
|
|
|
|
branch=$(
|
|
|
|
|
${pkgs.git}/bin/git branch \
|
|
|
|
|
| ${pkgs.gnused}/bin/sed -rn 's/^\* (.*)/\1/p'
|
|
|
|
|
)
|
|
|
|
|
echo "± $LOGNAME@''${HOSTNAME-$(${pkgs.nettools}/bin/hostname)}:$PWD .git $branch"
|
|
|
|
|
fi
|
|
|
|
|
'';
|
|
|
|
|
|
2019-01-16 19:24:53 +00:00
|
|
|
|
q-intel_backlight = /* sh */ ''
|
2016-11-07 00:16:11 +00:00
|
|
|
|
cd /sys/class/backlight/intel_backlight
|
|
|
|
|
</dev/null exec ${pkgs.gawk}/bin/awk '
|
|
|
|
|
END {
|
|
|
|
|
getline actual_brightness < "actual_brightness"
|
|
|
|
|
getline max_brightness < "max_brightness"
|
|
|
|
|
getline brightness < "brightness"
|
|
|
|
|
printf "intel_backlight %d%% %d/%d\n" \
|
|
|
|
|
, actual_brightness / max_brightness * 100 \
|
|
|
|
|
, actual_brightness \
|
|
|
|
|
, max_brightness
|
|
|
|
|
}
|
|
|
|
|
'
|
|
|
|
|
'';
|
|
|
|
|
|
2019-01-16 19:24:53 +00:00
|
|
|
|
q-virtualization = /* sh */ ''
|
2016-06-03 13:05:00 +00:00
|
|
|
|
echo "VT: $(${pkgs.systemd}/bin/systemd-detect-virt)"
|
|
|
|
|
'';
|
|
|
|
|
|
2019-01-16 19:24:53 +00:00
|
|
|
|
q-wireless = /* sh */ ''
|
2016-06-03 13:05:00 +00:00
|
|
|
|
for dev in $(
|
|
|
|
|
${pkgs.iw}/bin/iw dev \
|
|
|
|
|
| ${pkgs.gnused}/bin/sed -n 's/^\s*Interface\s\+\([0-9a-z]\+\)$/\1/p'
|
|
|
|
|
); do
|
|
|
|
|
inet=$(${pkgs.iproute}/bin/ip addr show $dev \
|
|
|
|
|
| ${pkgs.gnused}/bin/sed -n '
|
|
|
|
|
s/.*inet \([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/p
|
|
|
|
|
') \
|
|
|
|
|
|| unset inet
|
|
|
|
|
ssid=$(${pkgs.iw}/bin/iw dev $dev link \
|
|
|
|
|
| ${pkgs.gnused}/bin/sed -n '
|
|
|
|
|
s/.*\tSSID: \(.*\)/\1/p
|
|
|
|
|
') \
|
|
|
|
|
|| unset ssid
|
|
|
|
|
echo "$dev''${inet+ $inet}''${ssid+ $ssid}"
|
|
|
|
|
done
|
|
|
|
|
'';
|
|
|
|
|
|
2019-01-16 19:24:53 +00:00
|
|
|
|
q-online = /* sh */ ''
|
2016-06-03 13:05:00 +00:00
|
|
|
|
if ${pkgs.curl}/bin/curl -s google.com >/dev/null; then
|
|
|
|
|
echo '[32;1monline[m'
|
|
|
|
|
else
|
|
|
|
|
echo offline
|
|
|
|
|
fi
|
|
|
|
|
'';
|
|
|
|
|
|
2019-01-16 19:24:53 +00:00
|
|
|
|
q-thermal_zone = /* sh */ ''
|
2016-06-03 13:05:00 +00:00
|
|
|
|
for i in /sys/class/thermal/thermal_zone*; do
|
|
|
|
|
type=$(${pkgs.coreutils}/bin/cat $i/type)
|
|
|
|
|
temp=$(${pkgs.coreutils}/bin/cat $i/temp)
|
|
|
|
|
printf '%s %s°C\n' $type $(echo $temp / 1000 | ${pkgs.bc}/bin/bc)
|
|
|
|
|
done
|
|
|
|
|
'';
|
|
|
|
|
|
2019-01-16 19:24:53 +00:00
|
|
|
|
q-todo = /* sh */ ''
|
2017-09-20 09:58:04 +00:00
|
|
|
|
TODO_file=$PWD/TODO
|
2016-06-03 13:05:00 +00:00
|
|
|
|
if test -e "$TODO_file"; then
|
2019-01-16 19:25:17 +00:00
|
|
|
|
${pkgs.jq}/bin/jq -Rrs <"$TODO_file" -f ${pkgs.writeJq "q-todo.jq" ''
|
|
|
|
|
split("\n") | map(
|
|
|
|
|
(match("^([0-9]+-\\d{2}-\\d{2})\\s+(.*)$").captures | map(.string))
|
|
|
|
|
as $captures |
|
|
|
|
|
($captures[0] | strptime("%Y-%m-%d") | mktime) as $date |
|
|
|
|
|
$captures[1] as $text |
|
|
|
|
|
|
|
|
|
|
select(now >= $date) |
|
|
|
|
|
|
2019-01-16 19:34:10 +00:00
|
|
|
|
($text | test("\\[URGENT]"; "i")) as $urgent |
|
|
|
|
|
(if $urgent then "38;5;196" else "38;5;208" end) as $sgr |
|
|
|
|
|
if $urgent then sub("\\s*\\[URGENT]\\s*"; " "; "i") else . end |
|
|
|
|
|
|
|
|
|
|
"\u001b[\($sgr)m\(.)\u001b[m"
|
2019-01-16 19:25:17 +00:00
|
|
|
|
) |
|
|
|
|
|
if length == 0 then "nothing to remind" else .[] end
|
|
|
|
|
''}
|
2016-06-03 13:05:00 +00:00
|
|
|
|
else
|
|
|
|
|
echo "$TODO_file: no such file or directory"
|
|
|
|
|
fi
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
in
|
|
|
|
|
# bash needed for <(...)
|
|
|
|
|
pkgs.writeBashBin "q" ''
|
|
|
|
|
set -eu
|
|
|
|
|
export PATH=/var/empty
|
|
|
|
|
${q-cal}
|
2018-11-08 18:09:11 +00:00
|
|
|
|
${q-utcdate}
|
2016-06-03 13:05:00 +00:00
|
|
|
|
${q-isodate}
|
|
|
|
|
${q-sgtdate}
|
|
|
|
|
(${q-gitdir}) &
|
2016-11-07 00:16:11 +00:00
|
|
|
|
(${q-intel_backlight}) &
|
2019-03-29 17:14:39 +00:00
|
|
|
|
${pkgs.q-power_supply}/bin/q-power_supply &
|
2016-06-03 13:05:00 +00:00
|
|
|
|
(${q-virtualization}) &
|
|
|
|
|
(${q-wireless}) &
|
|
|
|
|
(${q-online}) &
|
|
|
|
|
(${q-thermal_zone}) &
|
|
|
|
|
wait
|
2017-09-20 09:58:04 +00:00
|
|
|
|
if test "$PWD" != "$HOME" && test -e "$HOME/TODO"; then
|
|
|
|
|
TODO_home_entries=$(cd; (${q-todo}) | ${pkgs.coreutils}/bin/wc -l)
|
|
|
|
|
if test "$TODO_home_entries" = 1; then
|
|
|
|
|
TODO_format='There is %d entry in ~/TODO'
|
|
|
|
|
else
|
|
|
|
|
TODO_format='There are %d entries in ~/TODO'
|
|
|
|
|
fi
|
|
|
|
|
printf "\x1b[38;5;238m$TODO_format\x1b[m\n" "$TODO_home_entries"
|
|
|
|
|
fi
|
|
|
|
|
(${q-todo}) || :
|
2016-06-03 13:05:00 +00:00
|
|
|
|
''
|