bitwarden.el 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. ;;; bitwarden.el --- Bitwarden command wrapper -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2018 Sean Farley
  3. ;; Author: Sean Farley
  4. ;; URL: https://github.com/seanfarley/emacs-bitwarden
  5. ;; Version: 0.1.3
  6. ;; Created: 2018-09-04
  7. ;; Package-Requires: ((emacs "24.4"))
  8. ;; Keywords: extensions processes bw bitwarden
  9. ;;; License
  10. ;; This program is free software: you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; This program is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. ;;; Commentary:
  21. ;; This package wraps the bitwarden command-line program.
  22. ;;; Code:
  23. (require 'auth-source)
  24. (require 'json)
  25. (require 'seq)
  26. (require 'subr-x)
  27. (require 'tree-widget)
  28. ;=============================== custom variables ==============================
  29. (defgroup bitwarden nil
  30. "Bitwarden functions and settings."
  31. :group 'external
  32. :tag "bitwarden"
  33. :prefix "bitwarden-")
  34. (defcustom bitwarden-bw-executable (executable-find "bw")
  35. "The bw cli executable used by Bitwarden."
  36. :group 'bitwarden
  37. :type 'string)
  38. (defcustom bitwarden-data-file
  39. (expand-file-name "Bitwarden CLI/data.json"
  40. (cond
  41. ((getenv "BITWARDENCLI_APPDATA_DIR")
  42. (getenv "BITWARDENCLI_APPDATA_DIR"))
  43. ((eq system-type 'darwin)
  44. "~/Library/Application Support")
  45. ((eq system-type 'windows-nt)
  46. (getenv "APPDATA"))
  47. ((getenv "XDG_CONFIG_HOME")
  48. (getenv "XDG_CONFIG_HOME"))
  49. (t
  50. "~/.config")))
  51. "The bw data file used by Bitwarden."
  52. :group 'bitwarden
  53. :type 'string)
  54. (defcustom bitwarden-user nil
  55. "Bitwarden user e-mail."
  56. :group 'bitwarden
  57. :type 'string)
  58. (defcustom bitwarden-automatic-unlock nil
  59. "Optional function to be called to attempt to unlock the vault.
  60. Set this to a lamdba that will evaluate to a password. For
  61. example, this can be the :secret plist from
  62. `auth-source-search'."
  63. :group 'bitwarden
  64. :type 'function)
  65. (defconst bitwarden--err-logged-in "you are not logged in")
  66. (defconst bitwarden--err-multiple "more than one result found")
  67. (defconst bitwarden--err-locked "vault is locked")
  68. ;===================================== util ====================================
  69. (defun bitwarden-logged-in-p ()
  70. "Check if `bitwarden-user' is logged in.
  71. Returns nil if not logged in."
  72. (let* ((ret (apply #'bitwarden--raw-runcmd "login" '("--check")))
  73. (exit-code (nth 0 ret)))
  74. (eq exit-code 0)))
  75. (defun bitwarden-unlocked-p ()
  76. "Check if `bitwarden-user' is loged in.
  77. Returns nil if not unlocked."
  78. (let* ((ret (apply #'bitwarden--raw-runcmd "unlock" '("--check")))
  79. (exit-code (nth 0 ret)))
  80. (eq exit-code 0)))
  81. (defun bitwarden--raw-runcmd (cmd &rest args)
  82. "Run bw command CMD with ARGS.
  83. Returns a list with the first element being the exit code and the
  84. second element being the output."
  85. (with-temp-buffer
  86. (list (apply 'call-process
  87. bitwarden-bw-executable
  88. nil (current-buffer) nil
  89. (cons cmd args))
  90. (replace-regexp-in-string "\n$" ""
  91. (buffer-string)))))
  92. (defun bitwarden-runcmd (cmd &rest args)
  93. "Run bw command CMD with ARGS.
  94. This is a wrapper for `bitwarden--raw-runcmd' that also checks
  95. for common errors."
  96. (if (bitwarden-logged-in-p)
  97. (if (bitwarden-unlocked-p)
  98. (let* ((ret (apply #'bitwarden--raw-runcmd cmd args))
  99. (exit-code (nth 0 ret))
  100. (output (nth 1 ret)))
  101. (if (eq exit-code 0)
  102. output
  103. (cond ((string-match "^More than one result was found." output)
  104. bitwarden--err-multiple)
  105. (t nil))))
  106. bitwarden--err-locked)
  107. bitwarden--err-logged-in))
  108. (defun bitwarden--login-proc-filter (proc string print-message)
  109. "Interacts with PROC by sending line-by-line STRING.
  110. If PRINT-MESSAGE is set then messages are printed to minibuffer."
  111. ;; read username if not defined
  112. (when (string-match "^? Email address:" string)
  113. (let ((user (read-string "Bitwarden email: ")))
  114. ;; if we are here then the user forgot to fill in this field so let's do
  115. ;; that now
  116. (setq bitwarden-user user)
  117. (process-send-string proc (concat bitwarden-user "\n"))))
  118. ;; read master password
  119. (when (string-match "^? Master password:" string)
  120. (process-send-string
  121. proc (concat (read-passwd "Bitwarden master password: ") "\n")))
  122. ;; check for bad password
  123. (when (string-match "^Username or password is incorrect" string)
  124. (bitwarden--message "incorrect master password" nil print-message))
  125. ;; if trying to unlock, check if logged in
  126. (when (string-match "^You are not logged in" string)
  127. (bitwarden--message "cannot unlock: not logged in" nil print-message))
  128. ;; read the 2fa code
  129. (when (string-match "^? Two-step login code:" string)
  130. (process-send-string
  131. proc (concat (read-passwd "Bitwarden two-step login code: ") "\n")))
  132. ;; check for bad code
  133. (when (string-match "^Login failed" string)
  134. (bitwarden--message "incorrect two-step code" nil print-message))
  135. ;; check for already logged in
  136. (when (string-match "^You are already logged in" string)
  137. (string-match "You are already logged in as \\(.*\\)\\." string)
  138. (bitwarden--message
  139. "already logged in as %s" (match-string 1 string) print-message))
  140. ;; success! now save the BW_SESSION into the environment so spawned processes
  141. ;; inherit it
  142. (when (string-match "^\\(You are logged in\\|Your vault is now unlocked\\)"
  143. string)
  144. ;; set the session env variable so spawned processes inherit
  145. (string-match "export BW_SESSION=\"\\(.*\\)\"" string)
  146. (setenv "BW_SESSION" (match-string 1 string))
  147. (bitwarden--message
  148. "successfully logged in as %s" bitwarden-user print-message)))
  149. (defun bitwarden--raw-unlock (cmd print-message)
  150. "Raw CMD to either unlock a vault or login.
  151. The only difference between unlock and login is just the name of
  152. the command and whether to pass the user.
  153. If PRINT-MESSAGE is set then messages are printed to minibuffer."
  154. (when (get-process "bitwarden")
  155. (delete-process "bitwarden"))
  156. (make-process :name "bitwarden"
  157. :buffer nil
  158. :connection-type 'pipe
  159. :command (append (list bitwarden-bw-executable)
  160. cmd)
  161. :filter (lambda (proc string)
  162. (bitwarden--login-proc-filter
  163. proc string print-message)))
  164. ;; suppress output to the minibuffer when running this programatically
  165. nil)
  166. ;================================= interactive =================================
  167. (defun bitwarden-unlock (&optional print-message)
  168. "Unlock bitwarden vault.
  169. It is not sufficient to check the env variable for BW_SESSION
  170. since that could be set yet could be expired or incorrect.
  171. If run interactively PRINT-MESSAGE gets set and messages are
  172. printed to minibuffer."
  173. (interactive "p")
  174. (let ((pass (if bitwarden-automatic-unlock
  175. (funcall bitwarden-automatic-unlock)
  176. "")))
  177. (bitwarden--raw-unlock (list "unlock" pass) print-message)))
  178. ;;;###autoload
  179. (defun bitwarden-login (&optional print-message)
  180. "Prompts user for password if not logged in.
  181. If run interactively PRINT-MESSAGE gets set and messages are
  182. printed to minibuffer."
  183. (interactive "p")
  184. (unless bitwarden-user
  185. (setq bitwarden-user (read-string "Bitwarden email: ")))
  186. (let ((pass (when bitwarden-automatic-unlock
  187. (funcall bitwarden-automatic-unlock))))
  188. (bitwarden--raw-unlock (list "login" bitwarden-user pass) print-message)))
  189. (defun bitwarden-lock ()
  190. "Lock the bw vault. Does not ask for confirmation."
  191. (interactive)
  192. (when (bitwarden-unlocked-p)
  193. (setenv "BW_SESSION" nil)))
  194. (defun bitwarden-logout ()
  195. "Log out bw. Does not ask for confirmation."
  196. (interactive)
  197. (when (bitwarden-logged-in-p)
  198. (bitwarden-runcmd "logout")
  199. (bitwarden-lock)))
  200. (defun bitwarden--message (msg args &optional print-message)
  201. "Print MSG using `message' and `format' with ARGS if non-nil.
  202. PRINT-MESSAGE is an optional parameter to control whether this
  203. method should print at all. If nil then nothing will be printed
  204. at all.
  205. This method will prepend 'Bitwarden: ' before each MSG as a
  206. convenience. Also, return a value of nil so that no strings
  207. are mistaken as a password (e.g. accidentally interpreting
  208. 'Bitwarden: error' as the password when in fact, it was an error
  209. message but happens to be last on the method stack)."
  210. (when print-message
  211. (let ((msg (if args (format msg args) msg)))
  212. (message (concat "Bitwarden: " msg))))
  213. nil)
  214. (defun bitwarden--handle-message (msg &optional print-message)
  215. "Handle return MSG of `bitwarden--auto-cmd'.
  216. Since `bitwarden--auto-cmd' returns a list of (err-code message),
  217. this function exists to handle that. Printing the error message
  218. is entirely dependent on PRINT-MESSAGE (see below for more info
  219. on PRINT-MESSAGE).
  220. If the error code is 0, then print the password based on
  221. PRINT-MESSAGE or just return it.
  222. If the error code is non-zero, then print the message based on
  223. PRINT-MESSAGE and return nil.
  224. PRINT-MESSAGE is an optional parameter to control whether this
  225. method should print at all. If nil then nothing will be printed
  226. at all but password will be returned (e.g. when run
  227. non-interactively)."
  228. (let* ((err (nth 0 msg))
  229. (pass (nth 1 msg)))
  230. (cond
  231. ((eq err 0)
  232. (if print-message
  233. (message "%s" pass)
  234. pass))
  235. (t
  236. (bitwarden--message "%s" pass print-message)
  237. nil))))
  238. (defun bitwarden--auto-cmd (cmd &optional recursive-pass)
  239. "Run Bitwarden CMD and attempt to auto unlock.
  240. If RECURSIVE-PASS is set, then treat this call as a second
  241. attempt after trying to auto-unlock.
  242. Returns a tuple of the error code and the error message or
  243. password if successful."
  244. (let* ((res (or recursive-pass (apply 'bitwarden-runcmd cmd))))
  245. (cond
  246. ((string-match bitwarden--err-locked res)
  247. ;; try to unlock automatically, if possible
  248. (if (not bitwarden-automatic-unlock)
  249. (list 1 (format "error: %s" res))
  250. ;; only attempt a retry once; to prevent infinite recursion
  251. (when (not recursive-pass)
  252. ;; because I don't understand how emacs is asyncronous here nor
  253. ;; how to tell it to wait until the process is done, we do so here
  254. ;; manually
  255. (bitwarden-unlock)
  256. (while (get-process "bitwarden")
  257. (sleep-for 0.1))
  258. (bitwarden--auto-cmd cmd (apply 'bitwarden-runcmd cmd)))))
  259. ((or (string-match bitwarden--err-logged-in res)
  260. (string-match bitwarden--err-multiple res))
  261. (list 2 (format "error: %s" res)))
  262. (t (list 0 res)))))
  263. ;;;###autoload
  264. (defun bitwarden-getpass (account &optional print-message)
  265. "Get password associated with ACCOUNT.
  266. If run interactively PRINT-MESSAGE gets set and password is
  267. printed to minibuffer."
  268. (interactive "MBitwarden account name: \np")
  269. (bitwarden--handle-message
  270. (bitwarden--auto-cmd (list "get" "password" account))
  271. print-message))
  272. ;;;###autoload
  273. (defun bitwarden-search (&optional search-str)
  274. "Search for vault for items containing SEARCH-STR.
  275. Returns a vector of hashtables of the results."
  276. (let* ((args (and search-str (list "--search" search-str)))
  277. (ret (bitwarden--auto-cmd (append (list "list" "items") args)))
  278. (result (bitwarden--handle-message ret)))
  279. (when result
  280. (let* ((json-object-type 'hash-table)
  281. (json-key-type 'string)
  282. (json (json-read-from-string result)))
  283. json))))
  284. (defun bitwarden-search-filter-username (accounts &optional username)
  285. "Filter results of `bitwarden-search' ACCOUNTS by USERNAME.
  286. ACCOUNTS can be the results of `bitwarden-search' or a string to
  287. search which will call `bitwarden-search' as a convenience."
  288. (let* ((accounts (if (vectorp accounts)
  289. accounts (bitwarden-search accounts)))
  290. ;; filter out matches that are not logins
  291. (accounts (seq-filter (lambda (elt) (gethash "login" elt)) accounts)))
  292. (if (and (stringp username) (not (string= username "")))
  293. (seq-filter (lambda (elt)
  294. (when-let* ((login (gethash "login" elt)))
  295. (string= (gethash "username" login) username)))
  296. accounts)
  297. accounts)))
  298. (defun bitwarden-folders ()
  299. "List bitwarden folders."
  300. (let* ((ret (bitwarden--auto-cmd (list "list" "folders")))
  301. (result (bitwarden--handle-message ret)))
  302. (when result
  303. (let* ((json-object-type 'hash-table)
  304. (json-key-type 'string)
  305. (json (json-read-from-string result)))
  306. json))))
  307. (defun bitwarden-sync ()
  308. "Sync local store with server."
  309. (interactive)
  310. (let ((res (bitwarden--auto-cmd (list "sync"))))
  311. (message (nth 1 res))))
  312. ;================================= auth-source =================================
  313. (defun bitwarden-auth-source-search (&rest spec)
  314. "Search Bitwarden according to SPEC.
  315. See `auth-source-search' for a description of the plist SPEC."
  316. (let* ((host (plist-get spec :host))
  317. (max (plist-get spec :max))
  318. (user (plist-get spec :user))
  319. (res (mapcar #'bitwarden-auth-source--build-result
  320. (bitwarden-search-filter-username host user))))
  321. (seq-take res max)))
  322. (defun bitwarden-auth-source--build-result (elt)
  323. "Build a auth-source result for ELT.
  324. This is meant to be used by `mapcar' for the results from
  325. `bitwarden-search-filter-username'."
  326. (let* ((host (gethash "name" elt))
  327. (login (gethash "login" elt)) ;; always present since
  328. ;; `bitwarden-search-filter-username'
  329. ;; tests for it
  330. (user (gethash "username" login))
  331. (pass (gethash "password" login)))
  332. `(:host ,host
  333. :user ,user
  334. :secret (lambda () ,pass))))
  335. (defvar bitwarden-auth-source-backend
  336. (auth-source-backend :type 'bitwarden
  337. :source "." ;; not used
  338. :search-function #'bitwarden-auth-source-search)
  339. "Auth-source backend variable for Bitwarden.")
  340. (defun bitwarden-auth-source-backend-parse (entry)
  341. "Create auth-source backend from ENTRY."
  342. (when (eq entry 'bitwarden)
  343. (auth-source-backend-parse-parameters entry bitwarden-auth-source-backend)))
  344. ;; advice to add custom auth-source function
  345. (if (boundp 'auth-source-backend-parser-functions)
  346. (add-hook 'auth-source-backend-parser-functions
  347. #'bitwarden-auth-source-backend-parse)
  348. (advice-add 'auth-source-backend-parse
  349. :before-until #'bitwarden-auth-source-backend-parse))
  350. ;;;###autoload
  351. (defun bitwarden-auth-source-enable ()
  352. "Enable Bitwarden auth-source by adding it to `auth-sources'."
  353. (interactive)
  354. (add-to-list 'auth-sources 'bitwarden)
  355. (auth-source-forget-all-cached)
  356. (message "Bitwarden: auth-source enabled"))
  357. ;================================= widget utils ================================
  358. (defun bitwarden-list-next ()
  359. "Move to the next item."
  360. (interactive)
  361. (forward-line)
  362. (beginning-of-line)
  363. (widget-forward 1))
  364. (defun bitwarden-list-prev ()
  365. "Move to the previous item."
  366. (interactive)
  367. (widget-backward 2)
  368. (beginning-of-line)
  369. (widget-forward 1))
  370. ;; bitwarden-list-dialog-mode
  371. (defvar bitwarden-list-dialog-mode-map
  372. (let ((map (make-sparse-keymap)))
  373. (set-keymap-parent map widget-keymap)
  374. (define-key map "n" 'bitwarden-list-next)
  375. (define-key map "p" 'bitwarden-list-prev)
  376. (define-key map "q" 'bitwarden-list-cancel-dialog)
  377. map)
  378. "Keymap used in recentf dialogs.")
  379. (define-derived-mode bitwarden-list-dialog-mode nil "bitwarden-list-dialog"
  380. "Major mode of recentf dialogs.
  381. \\{bitwarden-list-dialog-mode-map}"
  382. :syntax-table nil
  383. :abbrev-table nil
  384. (setq truncate-lines t))
  385. (defsubst bitwarden-list-all-get-item-at-pos ()
  386. "Get hashtable from widget at current pos in dialog widget."
  387. (let ((widget (get-char-property (point) 'button)))
  388. (widget-value widget)))
  389. (defsubst bitwarden-list-all-make-spaces (spaces)
  390. "Create a string with SPACES number of whitespaces."
  391. (mapconcat 'identity (make-list spaces " ") ""))
  392. (defsubst bitwarden-pad-to-width (item width)
  393. "Create a string with ITEM padded to WIDTH."
  394. (if (= (length item) width)
  395. item
  396. (if (>= (length item) width)
  397. (concat (substring item 0 (- width 1)) "…")
  398. (concat item (bitwarden-list-all-make-spaces (- width (length item)))))))
  399. ;================================ widget actions ===============================
  400. ;; Dialog settings and actions
  401. (defun bitwarden-list-cancel-dialog (&rest _ignore)
  402. "Cancel the current dialog.
  403. IGNORE arguments."
  404. (interactive)
  405. (kill-buffer (current-buffer))
  406. (bitwarden--message "dialog canceled" nil t))
  407. (defun bitwarden-list-all-kill-ring-save (&optional widget-item)
  408. "Bitwarden `kill-ring-save', insert password to kill ring.
  409. If WIDGET-ITEM is not supplied then look for the widget at the
  410. current point."
  411. (interactive)
  412. (let* ((item (or widget-item
  413. (bitwarden-list-all-get-item-at-pos)))
  414. (type (gethash "type" item))
  415. (login (gethash "login" item)))
  416. (if (not (eq type 1))
  417. (bitwarden--message "error: not a login item" nil t)
  418. (kill-new (gethash "password" login))
  419. (message "Password added to kill ring"))))
  420. (defun bitwarden-list-all-item-action (widget &rest _ignore)
  421. "Do action to element associated with WIDGET's value.
  422. IGNORE other arguments."
  423. (bitwarden-list-all-kill-ring-save (widget-value widget))
  424. (kill-buffer (current-buffer)))
  425. ;=================================== widgets ===================================
  426. (defmacro bitwarden-list-dialog (name &rest forms)
  427. "Show a dialog buffer with NAME, setup with FORMS."
  428. (declare (indent 1) (debug t))
  429. `(with-current-buffer (get-buffer-create ,name)
  430. ;; Cleanup buffer
  431. (let ((inhibit-read-only t)
  432. (ol (overlay-lists)))
  433. (mapc 'delete-overlay (car ol))
  434. (mapc 'delete-overlay (cdr ol))
  435. (erase-buffer))
  436. (bitwarden-list-dialog-mode)
  437. ,@forms
  438. (widget-setup)
  439. (switch-to-buffer (current-buffer))))
  440. (defsubst bitwarden-list-all-make-element (item)
  441. "Create a new cons list from ITEM."
  442. (let* ((folder-id (gethash "folderId" item))
  443. (login-item (gethash "login" item)))
  444. (cons folder-id
  445. (list (cons (concat
  446. (bitwarden-pad-to-width (gethash "name" item) 40)
  447. (bitwarden-pad-to-width
  448. (if login-item (gethash "username" login-item) "")
  449. 32)
  450. (format-time-string
  451. "%Y-%m-%d %T"
  452. (date-to-time (bitwarden-pad-to-width
  453. (gethash "revisionDate" item) 24))))
  454. item)))))
  455. (defun bitwarden-list-all-tree (key val)
  456. "Return a `tree-widget' of folders.
  457. Creates a widget with text KEY and items VAL."
  458. ;; Represent a sub-menu with a tree widget
  459. `(tree-widget
  460. :open t
  461. :match ignore
  462. :node (item :tag ,key
  463. :sample-face bold
  464. :format "%{%t%}\n")
  465. ,@(mapcar 'bitwarden-list-all-item val)))
  466. (defun bitwarden-list-all-item (pass-element)
  467. "Return a widget to display PASS-ELEMENT in a dialog buffer."
  468. ;; Represent a single file with a link widget
  469. `(link :tag ,(car pass-element)
  470. :button-prefix ""
  471. :button-suffix ""
  472. :button-face default
  473. :format "%[%t\n%]"
  474. :help-echo ,(concat "Viewing item " (gethash "id" (cdr pass-element)))
  475. :action bitwarden-list-all-item-action
  476. ,(cdr pass-element)))
  477. (defun bitwarden-list-all-items (items)
  478. "Return a list of widgets to display ITEMS in a dialog buffer."
  479. (let* ((folders (mapcar (lambda (e)
  480. (cons
  481. (gethash "id" e)
  482. (gethash "name" e)))
  483. (bitwarden-folders)))
  484. (hash (make-hash-table :test 'equal)))
  485. ;; create hash table where the keys are the folders and each value is a list
  486. ;; of the password items
  487. (dolist (x (mapcar 'bitwarden-list-all-make-element items))
  488. (let* ((folder-id (car x))
  489. (key (cdr (assoc folder-id folders)))
  490. (val (cdr x))
  491. (klist (gethash key hash)))
  492. (puthash key (append klist val) hash)))
  493. (mapcar (lambda (key)
  494. (bitwarden-list-all-tree key (gethash key hash)))
  495. (sort (hash-table-keys hash) #'string<))))
  496. ;;;###autoload
  497. (defun bitwarden-list-all ()
  498. "Show a dialog, listing all entries associated with `bitwarden-user'.
  499. If optional argument GROUP is given, only entries in GROUP will be listed."
  500. (interactive)
  501. (if (bitwarden-unlocked-p)
  502. (bitwarden-list-dialog "*bitwarden-list*"
  503. ;; Use a L&F that looks like the recentf menu.
  504. (tree-widget-set-theme "folder")
  505. (apply 'widget-create
  506. `(group
  507. :indent 0
  508. :format "%v\n"
  509. ,@(bitwarden-list-all-items
  510. (bitwarden-search))))
  511. (widget-create
  512. 'push-button
  513. :notify 'bitwarden-list-cancel-dialog
  514. "Cancel")
  515. (goto-char (point-min)))
  516. (bitwarden--message "not logged in!" nil t)))
  517. (provide 'bitwarden)
  518. ;;; bitwarden.el ends here