docs(emacs/custom elisp): generate passwords in Emacs
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a95b01a923
commit
5d60bc1e1e
@ -119,3 +119,33 @@ APPEND and COMPARE-FN, see `add-to-list'."
|
|||||||
(dolist (elt elements return)
|
(dolist (elt elements return)
|
||||||
(setq return (add-to-list list-var elt append compare-fn)))))
|
(setq return (add-to-list list-var elt append compare-fn)))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
** Generate and insert random passwords
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(defun my/generate-password (nb-chars)
|
||||||
|
"Generate an alphanumeric password of NB-CHARS."
|
||||||
|
(shell-command-to-string
|
||||||
|
(concat "tr -dc 'A-Za-z0-9!@#$%^&*' < /dev/urandom | head -c "
|
||||||
|
(number-to-string nb-chars))))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(defun my/copy-generated-password (&optional prefix)
|
||||||
|
(interactive "P")
|
||||||
|
(kill-new
|
||||||
|
(my/generate-password (if prefix
|
||||||
|
(string-to-number
|
||||||
|
(completing-read "Amount of characters: " nil))
|
||||||
|
32))))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(defun my/insert-generated-password (&optional prefix)
|
||||||
|
(interactive "P")
|
||||||
|
(insert
|
||||||
|
(my/generate-password (if prefix
|
||||||
|
(string-to-number
|
||||||
|
(completing-read "Amount of characters: "
|
||||||
|
nil))
|
||||||
|
32))))
|
||||||
|
#+end_src
|
||||||
|
Loading…
Reference in New Issue
Block a user