initial commit

This commit is contained in:
Thorn Avery 2020-10-03 21:37:21 +13:00
commit 29f294cae0
5 changed files with 117 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/old
/result
/init.nix

21
README.md Normal file
View File

@ -0,0 +1,21 @@
# Swatch
Swatch Internet Time
## Requirements
* `getopts`
* `gawk`
## Usage
`swatch` returns current swatch beats in format @XXX.YYY
`swatch -s` returns in format @XXX
`swatch -h` displays help
## Installation
`swatch.sh` contains the script, and can be added to your path.
### Nix Flake
`flake.nix` and `flake.lock` define a working nix flake for installing the script.
## Author
Shaun Kerr - [s@p7.co.nz](mailto:s@p7.co.nz)

27
flake.lock Normal file
View File

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1601475821,
"narHash": "sha256-7AI8j/xq5slauMGwC3Dp2K9TKDyDtBXBebeyWsE9euE=",
"owner": "Nixos",
"repo": "nixpkgs",
"rev": "b4db68ff563895eea6aab4ff24fa04ef403dfe14",
"type": "github"
},
"original": {
"owner": "Nixos",
"ref": "nixos-20.03",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

29
flake.nix Normal file
View File

@ -0,0 +1,29 @@
{
description = "swatch beat internet time";
inputs.nixpkgs.url = github:Nixos/nixpkgs/nixos-20.03;
outputs = { self, nixpkgs }: {
defaultPackage.x86_64-linux =
with import nixpkgs { system = "x86_64-linux"; };
stdenv.mkDerivation rec {
name = "swatch-${version}";
version = "1.0.0";
meta = {
description = "Display the current swatch beats";
longDescription = ''
Prints the current Swatch Internet Time.
Optional short form.
'';
homepage = https://github.com/techieAgnostic/swatch;
maintainers = [ "Shaun Kerr - s@p7.co.nz" ];
platforms = stdenv.lib.platforms.all;
};
src = self;
buildInputs = [
gawk
utillinux
];
buildPhase = "cp ./swatch.sh ./swatch";
installPhase = "mkdir -p $out/bin; install -t $out/bin swatch";
};
};
}

37
swatch.sh Executable file
View File

@ -0,0 +1,37 @@
#!/bin/bash
##
# Displays the current Swatch Internet Time
#
# -shaun kerr.
##
set -e
function usage {
cat <<EOF
Usage: $0 [-s -h]
Displays the current Swatch Internet Time
-s | Do not display fractions
-h | Show help
EOF
}
while getopts "sh" o; do
case $o in
s) fmt="@%03d\n" ;;
h) usage; exit 0 ;;
*) usage; exit 1 ;;
esac
done
seconds=$(date -u +"%-S")
minutes=$(date -u +"%-M")
hours=$((($(date -u +"%-H")+1)%24))
if [ -z $fmt ]; then fmt="@%07.3f\n"; fi
awk -v b="$((seconds + minutes*60 + hours*3600 ))" \
-v fmt="$fmt" \
'BEGIN { printf(fmt,b/86.4); }'