Last active
June 4, 2022 19:45
-
-
Save Laura7089/bf51ddee37d23cc46281b5e59194bbef to your computer and use it in GitHub Desktop.
EMF 2022 Badge Programming Justfile, requires `just` and `hush` (installable with `cargo`)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set positional-arguments | |
BADGE_PATH := "/dev/ttyACM0" | |
PB := `pwd` + "/pyboard.py --no-soft-reset -d '" + BADGE_PATH + "'" | |
# Download and install | |
hatch app_name: (download app_name) && (flash app_name) | |
# Download an app from the hatchery | |
download app_name: | |
curl $( \ | |
curl "https://2022.badge.emfcamp.org/eggs/get/{{ app_name }}/json" \ | |
| jq -r '.releases[.releases | keys | max][0].url' \ | |
) \ | |
| tar xzv | |
# Copy an app's files to the badge | |
flash app_path: (pyboard_nf "mkdir :/apps") | |
-just delete "{{ app_path }}" | |
just pyboard_nf mkdir ":/apps/$(basename {{ app_path }})" | |
find "{{ app_path }}" -type f -and -not -iname "*__pycache__*" -exec \ | |
just pyboard cp "{}" ":/apps/{}" \; | |
@echo | |
@echo | |
@echo "Don't forget to do a soft reset to update your menu!" | |
# List apps on the badge | |
list: (pyboard_ls "/apps") | |
# Delete an app's files on the badge | |
delete app_path: | |
#!/bin/env hush | |
let files = std.split(${just pyboard_ls "/apps/{{ app_path }}"}.stdout, "\n") | |
let app = std.trim(${basename "{{ app_path }}"}.stdout) | |
for file in std.iter(files) do | |
if std.len(file) != 0 then | |
{just pyboard rm ":/apps/$app/$file"} | |
end | |
end | |
{just pyboard rmdir ":/apps/$app"} | |
std.print("\n\nDon't forget to do a soft reset to update your menu!") | |
# Execute a filesystem cmd with pyboard | |
pyboard *cmd="": | |
{{ PB }} -f {{ cmd }} | |
# Version of `pyboard` that doesn't fail | |
pyboard_nf *cmd="": | |
-{{ PB }} -f {{ cmd }} | |
# Get an `ls` on the badge without guff | |
pyboard_ls path: | |
#!/bin/env hush | |
let files = std.split(${just pyboard ls ":{{ path }}" | grep -v ls}.stdout, "\n") | |
for line in std.iter(files) do | |
if std.len(line) != 0 then | |
let linef = std.split(std.trim(line), " ") | |
if std.len(linef) != 0 then | |
std.print(linef[1]) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment