diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 84a6bcf..56fcda5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ esv ESV.json esv.tsv esv.zip + +result/ +result +.direnv/ diff --git a/Makefile b/Makefile deleted file mode 100644 index 373961a..0000000 --- a/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -## -# esv command line bible -# Changelog: -# 2024-03-04 Added download feature to pull esv without distributing with source - -PREFIX = /usr/local - - -esv: esv.sh esv.awk esv.tsv - cat esv.sh > $@ - echo 'exit 0' >> $@ - echo '#EOF' >> $@ - tar czf - esv.awk esv.tsv >> $@ - chmod +x $@ - -test: esv.sh - shellcheck -s sh esv.sh - -clean: - rm -f esv ESV.json esv.zip - -install: esv - mkdir -p $(DESTDIR)$(PREFIX)/bin - cp -f esv $(DESTDIR)$(PREFIX)/bin - chmod 755 $(DESTDIR)$(PREFIX)/bin/esv - -uninstall: - rm -f $(DESTDIR)$(PREFIX)/bin/esv - -esv.tsv: download - -download: -ifeq ("$(wildcard ./esv.tsv)","") # Check if the file exists before downloading -ifeq ( $(strip $(unzip -v)), ) -ifeq ("$(wildcard ./ESV.json)","") # Check if the file exists before downloading - curl --location \ - --request GET "https://bolls.life/static/translations/ESV.json" \ - -o ESV.json -endif -else -ifeq ("$(wildcard ./esv.zip)","") # Check if the file exists before downloading - curl --location \ - --request GET "https://bolls.life/static/translations/ESV.zip" \ - -o esv.zip -endif - unzip esv.zip -endif - ./convert.py -endif - - -.PHONY: test clean install uninstall - -# end diff --git a/convert.py b/convert.py index 993d5d4..e1d3f58 100755 --- a/convert.py +++ b/convert.py @@ -19,6 +19,7 @@ import json import pandas import re import os +import sys titles = [ @@ -159,7 +160,7 @@ abbreviations = [ "Rev" ] -f = open('ESV.json') +f = open(sys.argv[1]) json_list = json.load(f) # The keys we need to extract from the json data @@ -189,4 +190,4 @@ if file_stats.st_size != 4616589: print("Recorded value: 4616589") print("Found value: ", file_stats.st_size) else: - print("Convertion successful!") + print("Conversion successful!") diff --git a/esv.sh b/esv.sh index 4f09a37..ed686ca 100644 --- a/esv.sh +++ b/esv.sh @@ -93,3 +93,4 @@ if [ $# -eq 0 ]; then fi get_data esv.tsv | awk -v cmd=ref -v ref="$*" "$(get_data esv.awk)" | ${PAGER} +exit 0 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3e6d5b1 --- /dev/null +++ b/flake.lock @@ -0,0 +1,41 @@ +{ + "nodes": { + "bible": { + "flake": false, + "locked": { + "lastModified": 1639253344, + "narHash": "sha256-0lAEyDmDz/DAQpbeQDr3UIw6bvZMLXYND+CMR86c8pw=", + "type": "tarball", + "url": "https://bolls.life/static/translations/ESV.zip" + }, + "original": { + "type": "tarball", + "url": "https://bolls.life/static/translations/ESV.zip" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1726463316, + "narHash": "sha256-gI9kkaH0ZjakJOKrdjaI/VbaMEo9qBbSUl93DnU7f4c=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "99dc8785f6a0adac95f5e2ab05cc2e1bf666d172", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "bible": "bible", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1c3fa1a --- /dev/null +++ b/flake.nix @@ -0,0 +1,52 @@ +{ + description = "Read the Word of God from your command line"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + bible = { + url = "https://bolls.life/static/translations/ESV.zip"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, bible }: + let + # Systems supported + allSystems = [ + "x86_64-linux" # 64-bit Intel/AMD Linux + "aarch64-linux" # 64-bit ARM Linux + "x86_64-darwin" # 64-bit Intel macOS + "aarch64-darwin" # 64-bit ARM macOS + ]; + + # Helper to provide system-specific attributes + forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f { + pkgs = import nixpkgs { inherit system; }; + }); + in + { + packages = forAllSystems ({ pkgs }: { + default = + let binName = "esv"; in + pkgs.stdenv.mkDerivation { + name = binName; + src = self; + buildInputs = [ ]; + nativeBuildInputs = with pkgs; [ shellcheck gawk unzip python3 python312Packages.pandas ]; + + buildPhase = '' + python3 ${./convert.py} ${bible} + cat ${./esv.sh} > ${binName} + echo '#EOF' >> ${binName} + tar czf - esv.awk esv.tsv >> ${binName} + chmod +x ${binName} + ''; + + installPhase = '' + mkdir -p $out/bin/ + cp ${binName} $out/bin/ + ''; + }; + }); + }; +}