diff options
| author | Vineet Kumar <git@vineetk.net> | 2026-05-22 14:40:59 -0400 |
|---|---|---|
| committer | Vineet Kumar <git@vineetk.net> | 2026-05-22 14:40:59 -0400 |
| commit | 1d1de0dd6ab81c17667b43c4a7900efa3c262c0f (patch) | |
| tree | a6d30747e96d73e9ce9c3550261f0d3da73dd5f2 | |
initial payload
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | kasi.el | 44 |
2 files changed, 45 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f1fd86f --- /dev/null +++ b/.gitignore | |||
| @@ -0,0 +1 @@ | |||
| #* | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | (defcustom kasi-dir "/data/kasi" | ||
| 2 | "Default base directory for kasi-related functions." | ||
| 3 | :type '(string) | ||
| 4 | :group 'kasi) | ||
| 5 | |||
| 6 | (defun kasi-filename () | ||
| 7 | "Returns full filename of the secret file." | ||
| 8 | (let* ((filenames (file-expand-wildcards (format "%s/*/*" kasi-dir))) | ||
| 9 | (options (mapcar (lambda (f) | ||
| 10 | (file-name-sans-extension | ||
| 11 | (file-relative-name f kasi-dir))) | ||
| 12 | filenames)) | ||
| 13 | (selected (completing-read "File: " options)) | ||
| 14 | (file (elt filenames (seq-position options selected)))) | ||
| 15 | file)) | ||
| 16 | |||
| 17 | (defun kasi-get (file elem) | ||
| 18 | "Returns element from secret file." | ||
| 19 | (car (with-temp-buffer | ||
| 20 | (insert-file-contents file) | ||
| 21 | (alist-get elem (read (current-buffer)))))) | ||
| 22 | |||
| 23 | (defun kasi (command file) | ||
| 24 | "Invoke the kasi secret manager." | ||
| 25 | (interactive (list (intern (completing-read "Command: " '(edit | ||
| 26 | password | ||
| 27 | username | ||
| 28 | |||
| 29 | totp))) | ||
| 30 | (kasi-filename))) | ||
| 31 | (pcase command | ||
| 32 | ('edit (find-file-other-window file)) | ||
| 33 | ('totp (kasi-totp file)) | ||
| 34 | ((or 'password 'username 'email) | ||
| 35 | (progn | ||
| 36 | (kill-new (kasi-get file command)) | ||
| 37 | (message (format "Copied %s to kill ring." command)))))) | ||
| 38 | |||
| 39 | (defun kasi-totp (file) | ||
| 40 | "Returns current TOTP code from secret file." | ||
| 41 | (interactive (list (kasi-filename))) | ||
| 42 | (let ((totp (kasi-get file 'totp))) | ||
| 43 | (kill-new totp) | ||
| 44 | (message "TOTP copied to kill ring"))) | ||
