Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't write until user saves #1

Open
kousu opened this issue Jul 3, 2020 · 0 comments
Open

Don't write until user saves #1

kousu opened this issue Jul 3, 2020 · 0 comments

Comments

@kousu
Copy link
Owner

kousu commented Jul 3, 2020

journal/journal

Lines 100 to 103 in 9687728

if [ ! -e "$TODAY" ]; then
mkdir -p "$(dirname "$TODAY")"
(header; echo; echo) >> "$TODAY"
fi

makes the journal get created on its first access, but what if the user makes a mistake (journal thursday when they meant friday) or wants to use a clever hack by setting $EDITOR to something that does data processing (e.g. EDITOR=head, EDITOR="wc -w" as in https://github.com/kousu/journal/blob/96877287c3da842cccc86847a80636e4281161d6/README.md#tips-and-tricks). It would be nice if non-existent files didn't get created just for looking at them -- reading shouldn't cause a write!. But I don't know how.

pass(1) solves this by a layer of indirection -- they first write to a tmp file, and after $EDITOR quits check what, if anything, was saved to it, and then only move it back in place if they want; they also have to use a tmpfile anyway because they need to temporarily decrypt the contents somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant