diff options
| author | Vineet Kumar <git@vineetk.net> | 2026-05-22 15:54:20 -0400 |
|---|---|---|
| committer | Vineet Kumar <git@vineetk.net> | 2026-05-22 15:54:20 -0400 |
| commit | f3e21ba9cdaec50f2a99f8d33e68204c694c7ac7 (patch) | |
| tree | 66b9b62ffdb9688ccbf2e7e5a22cfaaf82d7446b | |
| parent | e78d3c99640aa3c4f052b522a7cfc8ce8caf0d6f (diff) | |
fix some stuff
| -rw-r--r-- | kasi.el | 38 |
1 files changed, 27 insertions, 11 deletions
| @@ -36,14 +36,24 @@ | |||
| 36 | :type '(string) | 36 | :type '(string) |
| 37 | :group 'kasi) | 37 | :group 'kasi) |
| 38 | 38 | ||
| 39 | ;;;###autoload | ||
| 40 | (defcustom kasi-extension ".age" | ||
| 41 | "Default file extension for creating kasi secrets." | ||
| 42 | :type '(string) | ||
| 43 | :group 'kasi) | ||
| 44 | |||
| 39 | (defvar kasi-version "1.0") | 45 | (defvar kasi-version "1.0") |
| 40 | 46 | ||
| 47 | (defun kasi-filename-short (file) | ||
| 48 | "Returns shortened name of filename." | ||
| 49 | (file-name-sans-extension | ||
| 50 | (file-relative-name file kasi-dir))) | ||
| 51 | |||
| 41 | (defun kasi-filename () | 52 | (defun kasi-filename () |
| 42 | "Returns full filename of the secret file." | 53 | "Returns full filename of the secret file." |
| 43 | (let* ((filenames (file-expand-wildcards (format "%s/*/*" kasi-dir))) | 54 | (let* ((filenames (file-expand-wildcards (format "%s/*/*" kasi-dir))) |
| 44 | (options (mapcar (lambda (f) | 55 | (options (mapcar (lambda (f) |
| 45 | (file-name-sans-extension | 56 | (kasi-filename-short f)) |
| 46 | (file-relative-name f kasi-dir))) | ||
| 47 | filenames)) | 57 | filenames)) |
| 48 | (selected (completing-read "File: " options)) | 58 | (selected (completing-read "File: " options)) |
| 49 | (file (elt filenames (seq-position options selected)))) | 59 | (file (elt filenames (seq-position options selected)))) |
| @@ -57,18 +67,22 @@ | |||
| 57 | 67 | ||
| 58 | (defun kasi-totp (file) | 68 | (defun kasi-totp (file) |
| 59 | "Returns current TOTP code from secret file." | 69 | "Returns current TOTP code from secret file." |
| 60 | (let ((totp-code (kasi-get file 'totp))) | 70 | (let* ((totp-secret (kasi-get file 'totp)) |
| 71 | (totp-code (totp (base32-hex-decode totp-secret)))) | ||
| 61 | (kill-new totp-code) | 72 | (kill-new totp-code) |
| 62 | (message "TOTP copied to kill ring"))) | 73 | (message (format "TOTP %s for %s copied to kill ring" |
| 74 | totp-code | ||
| 75 | (kasi-filename-short file))))) | ||
| 63 | 76 | ||
| 64 | ;;;###autoload | 77 | ;;;###autoload |
| 65 | (defun kasi (command file) | 78 | (defun kasi (command file) |
| 66 | "Invoke the kasi secret manager." | 79 | "Invoke the kasi secret manager." |
| 67 | (interactive (list (intern (completing-read "Command: " '(edit | 80 | (interactive (list (intern (completing-read "Command: " |
| 68 | password | 81 | '(edit |
| 69 | username | 82 | password |
| 70 | 83 | username | |
| 71 | totp))) | 84 | |
| 85 | totp))) | ||
| 72 | (kasi-filename))) | 86 | (kasi-filename))) |
| 73 | (pcase command | 87 | (pcase command |
| 74 | ('edit (find-file-other-window file)) | 88 | ('edit (find-file-other-window file)) |
| @@ -76,6 +90,8 @@ | |||
| 76 | ((or 'password 'username 'email) | 90 | ((or 'password 'username 'email) |
| 77 | (progn | 91 | (progn |
| 78 | (kill-new (kasi-get file command)) | 92 | (kill-new (kasi-get file command)) |
| 79 | (message (format "Copied %s to kill ring." command)))))) | 93 | (message (format "Copied %s for %s to kill ring." |
| 94 | command | ||
| 95 | (kasi-filename-short file))))))) | ||
| 80 | 96 | ||
| 81 | (provide 'kasi) | 97 | (provide 'kasi) |
