Compare commits

...

8 Commits

Author SHA1 Message Date
98d3f2e655 rbw-get 2025-02-18 16:07:19 +01:00
f5b61c9e91 Update README.md 2025-01-24 14:53:57 +01:00
b5fe3f8550 fix 2024-11-22 23:24:30 +01:00
8a2a404cc6 totp support 2024-10-28 11:37:51 +01:00
517bb4361d fix 2023-07-14 11:16:46 +02:00
60e43d042a fix directory and lock vault 2023-07-13 18:26:52 +02:00
c76ce05ffe fix 2023-05-21 20:51:38 +02:00
934ff45672 fix? 2023-05-21 20:16:19 +02:00
2 changed files with 46 additions and 23 deletions

View File

@@ -1,2 +1 @@
# rbw-mode

68
rbw.el
View File

@@ -1,64 +1,88 @@
(defun rbw-get-password ()
(interactive)
(kill-new (rbw/list-all)))
(if (rbw/unlocked) (kill-new (rbw/list-all 'rbw/get-pass)) (message "locked vault")))
(defun rbw-get-totp ()
(interactive)
(if (rbw/unlocked) (kill-new (rbw/list-all 'rbw/get-totp)) (message "locked vault")))
(defun rbw-add ()
(interactive)
(let* ((name (read-string "password name: "))
(username (read-string "username: "))
(entry (concat name " " username))
(exists? (car (rbw/get entry))))
(exists? (car (rbw/get-pass entry))))
(message exists?)
(if exists? (message "entry already exists")
(let* ((length (read-number "length: ")))
(rbw/generate length name username)))))
;; TODO
;; (defun rbw-remove ()
;; (interactive)
;; )
(defun rbw-get-user ()
(interactive)
(let* ((output (rbw/list-all "--field user"))
(output (string-trim-left output "Username: ")))
(kill-new output)))
(if (rbw/unlocked)
(let* ((output (rbw/list-all 'rbw/get-pass "--field user"))
(output (string-trim-left output "Username: ")))
(kill-new output))
(message "locked vault")))
(defun rbw-generate ()
(interactive)
(let* ((length (read-number "password length: ")))
(kill-new (rbw/generate length))))
(defun rbw/sync () (shell-command "rbw sync"))
(defun rbw-sync ()
(interactive)
(let* ((default-directory "/home/luis/"))
(shell-command "rbw sync")))
(defun rbw/list-all (&optional options entries selected)
(defun rbw-get (entry &optional options)
(let* ((result (rbw/get-pass entry))
(output (car (last result)))
(result (car result)))
(if result output (message "error in rbw-get entry not found "))))
(defun rbw/list-all (getter &optional options entries selected)
(let* ((entries (if entries entries (rbw/list)))
(entry (completing-read "bitwarden entries: " entries))
(selected (concat selected " " entry))
(selected (string-trim selected))
(result (rbw/get selected options))
(result (funcall getter selected options)) ; TODO fix when getter fails
(output (car (last result)))
(result (car result)))
(if result output
(rbw/list-all options (rbw/extract-multiple output selected) selected))))
(rbw/list-all getter options (rbw/extract-multiple output selected) selected))))
(defun rbw/generate (length &optional name user)
(let* ((length (number-to-string length))
(let* ((default-directory "/home/luis/")
(length (number-to-string length))
(command (concat "rbw generate " length " " name " " user)))
(shell-command-to-string command)))
(defun rbw/unlocked ()
(if (string-empty-p (shell-command-to-string "rbw unlocked")) t nil))
(let* ((default-directory "/home/luis/"))
(if (string-empty-p (shell-command-to-string "rbw unlocked")) t nil)))
(defun rbw/list ()
(let* ((output (shell-command-to-string "rbw list"))
(let* ((default-directory "/home/luis/")
(output (shell-command-to-string "rbw list"))
(output (string-trim output))
(entries (split-string output "\n")))
entries))
(defun rbw/get (entry &optional options)
(let* ((command (concat "rbw get " options " " entry " ; echo $?"))
(defun rbw/get-pass (entry &optional options)
(let* ((default-directory "/home/luis/")
(command (concat "rbw get " options " " entry " ; echo $?"))
(output (shell-command-to-string command))
(output (string-trim output))
(output (split-string output "\n"))
(result (car (last output)))
(result (string-equal result "0"))
(output (car output)))
(list result output)))
(defun rbw/get-totp (entry &optional options)
(let* ((default-directory "/home/luis/")
(command (concat "rbw code " options " " entry " ; echo $?"))
(output (shell-command-to-string command))
(output (string-trim output))
(output (split-string output "\n"))
@@ -71,11 +95,11 @@
(string-match "\\([^:]*\\)$" output)
(let* ((trimmed (string-trim (match-string 1 output)))
(splitted (split-string trimmed ", "))
(splitted (cl-remove-if-not (lambda (x) (string-match "@" x)) splitted))
(ending (concat "@" selected))
(splitted (cl-remove-if-not (lambda (x) (string-match ending x)) splitted))
(result-list '()))
(dolist (element splitted)
(push (car (split-string element ending)) result-list))
(reverse result-list)))
(provide 'rbw-mode)
(provide 'rbw)