Function: sops-find-file
sops-find-file is an interactive and natively compiled function
defined in sops.el.
Signature
(sops-find-file PATH)
Documentation
Visit PATH; if PATH does not exist, create it as a new SOPS-encrypted file.
For existing paths this delegates to find-file -- the v0.2
find-file-hook handles transparent decryption when global-sops-mode(var)/global-sops-mode(fun)
is active.
For non-existent paths, signals user-error before any buffer is
created if:
- PATH is empty, or names a directory (ends in /);
- PATH is remote (TRAMP);
- PATH's parent directory does not exist;
- no .sops.yaml is reachable in any ancestor of PATH's parent;
- sops binary is missing or older than 3.9.0.
Otherwise visits PATH (which creates an empty buffer with no file on
disk yet), seeds it with a format-appropriate SOPS example -- ported
from upstream sops's EmitExample -- and enables sops-mode(var)/sops-mode(fun) in
'creating state. On the first successful save-buffer, sops
encrypts the buffer's contents to PATH and the buffer transitions
to the normal 'decrypted state.
Interactive: prompts via read-file-name.
Key Bindings
This command is not in any keymaps.
Source Code
;; Defined in /nix/store/vihl6lkzddv9xrsrsznvqdjq27g2i30p-emacs-packages-deps/share/emacs/site-lisp/elpa/sops-20260920.2121/sops.el
;;;###autoload
(defun sops-find-file (path)
"Visit PATH; if PATH does not exist, create it as a new SOPS-encrypted file.
For existing paths this delegates to `find-file' -- the v0.2
`find-file-hook' handles transparent decryption when `global-sops-mode'
is active.
For non-existent paths, signals `user-error' before any buffer is
created if:
- PATH is empty, or names a directory (ends in `/');
- PATH is remote (TRAMP);
- PATH's parent directory does not exist;
- no `.sops.yaml' is reachable in any ancestor of PATH's parent;
- sops binary is missing or older than 3.9.0.
Otherwise visits PATH (which creates an empty buffer with no file on
disk yet), seeds it with a format-appropriate SOPS example -- ported
from upstream sops's `EmitExample' -- and enables `sops-mode' in
\\='creating state. On the first successful `save-buffer', sops
encrypts the buffer's contents to PATH and the buffer transitions
to the normal \\='decrypted state.
Interactive: prompts via `read-file-name'."
(interactive (list (read-file-name "Find SOPS file: ")))
(when (string-empty-p path)
(user-error "Sops-find-file: not a file path: %s" path))
(let ((path (expand-file-name path)))
(when (directory-name-p path)
(user-error "Sops-find-file: not a file path: %s" path))
(when (file-remote-p path)
(user-error "Sops-find-file: remote paths not supported: %s" path))
(if (file-exists-p path)
(find-file path)
(let ((parent (file-name-directory path)))
(unless (and parent (file-exists-p parent))
(user-error "Sops-find-file: parent directory does not exist: %s"
parent))
(unless (locate-dominating-file parent ".sops.yaml")
(user-error
"Sops-find-file: no .sops.yaml found in any ancestor of %s"
parent))
(sops--ensure-version)
(let ((format (sops--format-for path)))
(find-file path)
(sops--start-creation format))))))