Large set of changes to improve history atomicity on filesystems that do not support locking
Should address https://github.com/fish-shell/fish-shell/issues/685