Compare commits

...

2 commits

Author SHA1 Message Date
Bram Schoenmakers 73a87ed767
Add function to generate QR codes 2024-02-09 20:09:31 +01:00
Bram Schoenmakers 741f9a98b1
Add tags 2024-02-09 19:58:48 +01:00
2 changed files with 62 additions and 1 deletions

View file

@ -843,7 +843,7 @@ Based on an answer at the [[https://emacs.stackexchange.com/a/77480/34645][Emacs
(add-to-list 'my/denote/url-functions #'my/elfeed/entry-url)
#+end_src
* Using gpg-agent inside Emacs in Termux
* Using gpg-agent inside Emacs in Termux :emacs:termux:
:PROPERTIES:
:URL: https://emacs.ch/@bram85/111580555195721041
:END:
@ -908,6 +908,40 @@ Finally, I attached this hook in three places:
#+end_src
Which covers my (potential) GPG/SSH usage within Emacs. Now, anytime a I perform a GPG / SSH operation, the $GPG_TTY variable is set properly and if needed, the passhprase prompt shows up in the minibuffer.
* Generate and show QR for the region or minibuffer input :emacs:
#+begin_src elisp :tangle gists/generate-qr.el
(defun my/generate-qr (text &optional img)
"Generate a QR code from the region or given TEXT.
If no region is active, the TEXT defaults to the clipboard content.
When IMG is non-nil, generate an image instead of the default
UTF-8 representation.
This function relies on qrencode(1) being present in your $PATH."
(interactive
(let ((default-text (if (use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(my/clipboard-get))))
(list
(read-string (format-prompt "Text" default-text) nil nil default-text)
current-prefix-arg)))
(with-current-buffer (get-buffer-create "*qr*")
;; in case the buffer still exists and image-mode is active
(fundamental-mode)
(erase-buffer)
(insert text)
(let ((file-format
(if (equal current-prefix-arg '(4)) "PNG" "UTF8")))
(call-process-region nil nil "qrencode" t t nil "-o" "-" "-t" file-format)
(when (and (display-graphic-p) (string= file-format "PNG"))
(image-mode)))
(display-buffer (current-buffer))))
#+end_src
* Meta
** License

27
gists/generate-qr.el Normal file
View file

@ -0,0 +1,27 @@
(defun my/generate-qr (text &optional img)
"Generate a QR code from the region or given TEXT.
If no region is active, the TEXT defaults to the clipboard content.
When IMG is non-nil, generate an image instead of the default
UTF-8 representation.
This function relies on qrencode(1) being present in your $PATH."
(interactive
(let ((default-text (if (use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(my/clipboard-get))))
(list
(read-string (format-prompt "Text" default-text) nil nil default-text)
current-prefix-arg)))
(with-current-buffer (get-buffer-create "*qr*")
;; in case the buffer still exists and image-mode is active
(fundamental-mode)
(erase-buffer)
(insert text)
(let ((file-format
(if (equal current-prefix-arg '(4)) "PNG" "UTF8")))
(call-process-region nil nil "qrencode" t t nil "-o" "-" "-t" file-format)
(when (and (display-graphic-p) (string= file-format "PNG"))
(image-mode)))
(display-buffer (current-buffer))))