kasi.el

This package provides an easy way to manage secrets via M-x kasi.
Log | Files | Refs | LICENSE

commit 2edee246d1e44c462da26b2d9a43a8d9e499d353
parent 6cbb431459e9a0db73264c4144937a136fdb5b83
Author: Vineet Kumar <git@vineetk.net>
Date:   Fri, 22 May 2026 17:16:59 -0400

add create command to generate new secret files

closer in parity to kasi.sh now

Diffstat:
Mkasi.el | 37++++++++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/kasi.el b/kasi.el @@ -42,6 +42,17 @@ :type '(string) :group 'kasi) +;;;###autoload +(defcustom kasi-template "\ +; -*- mode: lisp -*- +((password \"%s\") + (username \"%s\") + (email \"\") + (totp \"\") + (extra-notes \"\"))\n" + "Template that gets filled in to newly created secret files. +Two %s are needed for password and username for now.") + (defvar kasi-version "1.0") (defun kasi--filename-short (file) @@ -93,32 +104,52 @@ Uses /dev/urandom for cryptographic security." charset-len)))))) result)) +(defun kasi--edit (file) + "Edits secret file." + (find-file-other-window file)) + +(defun kasi--create (file) + "Creates secret file." + (let* ((filename (format "%s/%s%s" + kasi-dir file kasi-extension))) + (mkdir (format "%s/%s" + kasi-dir + (car (f-split file))) + t) + (with-temp-file filename + (insert (format kasi-template + (kasi-generate-password) + (kasi-generate-username)))) + (kasi--edit filename))) + ;;;###autoload (defun kasi-generate-password (&optional length) "Generate a random password of LENGTH (default 32)." (interactive "P") (let ((charset "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"!#$%&'()*+,-./:;<=>?@[]^_`{|}~")) - (message (kasi--random-string (or length 32) charset)))) + (message "%s" (kasi--random-string (or length 32) charset)))) ;;;###autoload (defun kasi-generate-username (&optional length) "Generate a random username of LENGTH (default 12)." (interactive "P") (let ((charset "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")) - (message (kasi--random-string (or length 12) charset)))) + (message "%s" (kasi--random-string (or length 12) charset)))) ;;;###autoload (defun kasi (command file) "Invoke the kasi secret manager." (interactive (list (intern (completing-read "Command: " '(edit + create password username email totp))) (kasi--filename))) (pcase command - ('edit (find-file-other-window file)) + ('edit (kasi--edit file)) + ('create (kasi--create file)) ('totp (kasi--totp file)) ((or 'password 'username 'email) (progn