I’ve created the un*x bash script below to semi-automate making a commits.to link when I notice that I’ve written a promise in a piece of text anywhere.
I copy the text to the clipboad (it can be the whole body of text, not just the promise itself) then run this script. The script reads what’s in the clipboard, parses it to find the actual promise, creates a commits.to URL, shows it to me, then gives me the option of opening the URL in a browser or cancelling. If I choose to open it, the URL is also copied to the clipboard so I can paste it wherever I’d written the text.
The parsing to find the promise inside the text is pretty basic. The script looks for “I will / I shall / I’ll / I should” then copies everything after that up to the first full stop or to the end of the text if no full stop is found.
If anyone improves on it, I’d love to see what you do!
#!/bin/bash
####
#### Customise these settings:
####
#
# Enter your commits.to URL including protocol.
# Don't put a slash at the end.
# E.g., 'http://alice.commits.to'
#
BASE_URL='http://alys.commits.to'
#
# Edit this to contain a command that will PASTE text FROM your clipboard:
#
CLIPBOARD_PASTE_COMMAND='/usr/bin/clipit -c'
#
# Edit this to contain a command that will COPY text from standard input TO your clipboard:
#
CLIPBOARD_COPY_COMMAND='/usr/bin/clipit'
#
# Edit this to contain a command that will open a URL in your default browser:
#
URL_OPEN_COMMAND='/usr/bin/xdg-open'
####
#### End of customisation.
####
# get contents of clipboard:
text=$($CLIPBOARD_PASTE_COMMAND)
# text="These are some words that you can use instead of the above line to test the regex below. I'll do some action by 11pm tomorrow. This sentence is not part of the commitment. Nor this"
# match the first string that starts with "I will" or similar and ends with . or end of string; also remove bad characters:
commitment=$(echo $text | perl -pe "s/.*(I will|I shall|I'll|I should)\s*(.+?)(\.|\!|$).*/\$2/i; s/ +/_/g; s/[^a-zA-Z0-9._-]//g")
url=$BASE_URL/$commitment
# display the URL:
echo
echo "$url"
echo
read -p "Want to make this commitment? [Y/n] " proceed
proceed=${proceed:-Y}
if [ "$proceed" == "Y" ] || [ "$proceed" == "y" ] ; then
# open the URL in your browser:
$($URL_OPEN_COMMAND "$url")
# copy the URL to your clipboard:
echo "$url" | $($CLIPBOARD_COPY_COMMAND)
echo
echo "Great! Copied to clipboard: $url"
else
echo
echo "Commitment not made."
fi