cooklang / cookcli

Command line program which provides a suite of tools to create shopping lists and maintain recipes.
https://cooklang.org
MIT License
690 stars 33 forks source link

Sync shopping list #103

Open SkepticMystic opened 4 months ago

SkepticMystic commented 4 months ago

Possibly more of a question.

In my setup, I cook server from a raspberry pi, then tailscale serve that to my other devices. If I add a recipe to my shopping list on one device, it doesn't show up on the shopping list of a different device. I assume the list is stored locally in the browser, or something.

Is this possible to achieve? Please let me know if there is more info I can share to assist.

dubadub commented 4 months ago

Yes, as of now the shopping list is stored in browser's local storage, not on a server. That's an interesting use-case, I don't mind changing CLI to store the shopping list on server side, but I don't have time at the moment to do that.

SkepticMystic commented 4 months ago

OK cool, good to know! I might give it a try, but I don't know Rust yet. Would you store the shopping list in/next to config in the recipes folder, or somewhere else entirely?

SkepticMystic commented 4 months ago

This is what I'm using as a workaround for now, quite happy with it! Read all recipes from my Obsidian vault (can be anywhere though), fzf the ones to create a shopping list for, then pipe those into a file in Markdown format:

function cook-sl
    set ingredients $(
        # Get all recipes from vault
        find ~/obsidian/Recipes/*.cook \
            # fzf, showing just the basename as a label, with a cooklang preview on the side
        | fzf --delimiter / --with-nth 6 --multi --preview "cook recipe {}" \
            # Send those chosen recipes to `cook`, with the given aisle config
        | xargs -d "\n" cook shopping-list --aisle ~/obsidian/Recipes/config/aisle.conf
    )

    for ingredient in $ingredients
        # Lines starting with [ are aisle groupings
        if test $(string sub -l 1 $ingredient) = '['
            echo ""
            echo "**$( string sub -s 2 -e -1 $ingredient )**"
            echo ""
        else
            echo "- [ ] $ingredient"
        end
        # Pipe echos into shopping list, overwriting the file
    end >~/obsidian/Recipes/Shopping\ List.md

    echo "Shopping list updated"
end
dubadub commented 4 months ago

Cool, that's smart!