loading...

Ingredient list as QR code

mafflerbach profile image mafflerbach ・2 min read

As a good housewife I have a personal cookbook with all the favourite meals of my family.
Usually we are doing our weekly grocery shopping, for the whole week, on Saturday . On this day I also create a meal plan for the upcoming week and think about what i have to buy.

I'm using an App to manage my shopping list and I have to add the items by hand. But this App has a feature to import lists from the clipboard. And if I want to cook something new, I have to copy and pasting this in to my note App, reformatting as list, finally after this, I can use the import feature.
It is quite tedious and sometime painful do everything on my phone.

After thinking about how to optimize this work flow, I come up with following script:

#!/bin/bash

tickCount=0
ingredient=""
# read the recipe file 
while IFS= read -r line
do

    # checking for ticks as hint for the ingredient list start
    if [ "$line" == "\`\`\`" ] && [ "$tickCount" == "0" ]
    then 
        tickCount=1
        continue
    fi

    # checking for ticks as hint for the ingredient list end
    if [ "$line" == "\`\`\`" ] && [ "$tickCount" == "1" ]
    then 
        tickCount=0
        continue
    fi

    # as long as i am between ticks append the current line to the variable
    if [ "$tickCount" == "1" ]
    then
        lf=$'\n'
        ingredient="$ingredient$lf$line"
    fi

done < "$1"

# show the list
echo "$ingredient"
# print out the ingredient list as qr code in to the terminal
qrencode -t UTF8 $"$ingredient" -s 1 -o -

Enter fullscreen mode Exit fullscreen mode

Now, I have to digitalize all my cooking recipes in to markdown format, cause for the moment they are only handwritten in a book.

But the copy/pasting part of new recipes, are easier on a pc instead of a mobile phone. And if I am going further, I can write a scraper script which converting the html into markdown for me.

Discussion

pic
Editor guide