]> git.bundesbrandschatzamt.de Git - emacsconfig.git/commitdiff
hidepw is great!
authorAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Fri, 12 Feb 2016 09:32:39 +0000 (10:32 +0100)
committerAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Fri, 12 Feb 2016 09:32:39 +0000 (10:32 +0100)
Thank you Chris Forno!

bba.org
lisp/hidepw.el [new file with mode: 0644]

diff --git a/bba.org b/bba.org
index c712adba61750058ce4d66f77f39f6a766f05415..6d0481d94c8c93ebe64fe90410567f673d325e56 100644 (file)
--- a/bba.org
+++ b/bba.org
@@ -538,6 +538,17 @@ Probably the best help to keep track of the not every day used keybindings.
     )
 #+END_SRC
 
+* [[https://github.com/jekor/hidepw][hidepw]]
+[2016-02-11 Thu 16:10]
+
+Hide passwords on the screen from shoulder surfing.
+Single pipes interfere with org tables. Just go double.
+
+#+BEGIN_SRC emacs-lisp
+  (load-file (expand-file-name "~/.emacs.d/lisp/hidepw.el"))
+  (add-hook 'org-mode-hook  'hidepw-mode)
+  (setq hidepw-pattern "||\\(.*\\)||")
+#+END_SRC
 * latex
 
 Use [[http://orgmode.org/manual/A-LaTeX-example.html#A-LaTeX-example][orgtbl]] to create tables.
diff --git a/lisp/hidepw.el b/lisp/hidepw.el
new file mode 100644 (file)
index 0000000..553e8db
--- /dev/null
@@ -0,0 +1,122 @@
+;;; hidepw.el --- Minor mode to hide passwords
+
+;; Author: Chris Forno <jekorNOSPAMjekor.com>
+;; Package-Version: 0.1.0
+;; Keywords: hide, hidden, password
+
+;; Copyright (C) 2014, Chris Forno
+;; All rights reserved.
+;;
+;; Redistribution and use in source and binary forms, with or without
+;; modification, are permitted provided that the following conditions are met:
+;;     * Redistributions of source code must retain the above copyright
+;;       notice, this list of conditions and the following disclaimer.
+;;     * Redistributions in binary form must reproduce the above copyright
+;;       notice, this list of conditions and the following disclaimer in the
+;;       documentation and/or other materials provided with the distribution.
+;;     * Neither the name of Chris Forno nor the names of his contributors may
+;;       be used to endorse or promote products derived from this software
+;;       without specific prior written permission.
+;;
+;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;; DISCLAIMED. IN NO EVENT SHALL CHRIS FORNO BE LIABLE FOR ANY
+;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+;; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+;;; Commentary:
+
+;; This is a minor mode for hiding passwords. It's useful if you
+;; manage your passwords in text files (perhaps automatically
+;; encrypted and decrypted by EasyPG) and want to prevent shoulder
+;; surfing.
+;;
+;; When enabled, any passwords will appear as ******, but you'll still
+;; be able to copy the password to the clipboard.
+;;
+;; By default, passwords are marked by delimiting them with pipes (|).
+;; For example:
+;;
+;; root: |supersecret|
+;;
+;; will display as
+;;
+;; root: |******|
+;;
+;; You can customize hidepw-pattern to match against arbitrary regular
+;; expressions. Just make sure to include one capturing group (\(\))
+;; since the group marks the actual password. You can also customize
+;; the mask (******) that obscures the password.
+;;
+;; You can enable hidepw-mode automatically on .gpg files with:
+;;
+;; (add-to-list 'auto-mode-alist
+;;              '("\\.gpg\\'" . (lambda () (hidepw-mode))))
+;;
+;; Notes:
+;;
+;; You won't be able to move the cursor within the password (it will
+;; behave like a single character), but deleting the delimiter from
+;; either side will reveal the password and make it editable. Just add
+;; the delimiter back to hide it again.
+;;
+;; This mode turns on font-lock-mode (and won't turn it off when you
+;; turn off this mode).
+
+;;; Code:
+
+\f
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;; User Variables:
+
+(defgroup hidepw nil "Settings for hiding passwords")
+
+(defcustom hidepw-pattern "|\\(.*\\)|"
+  "Pattern for identifying a password (must contain 1 capturing group)"
+  :type 'regexp
+  :group 'hidepw)
+
+(defcustom hidepw-mask "******"
+  "String to obscure passwords with"
+  :type 'string
+  :group 'hidepw)
+
+(defun hidepw-font-lock-keywords ()
+  `((,hidepw-pattern 1 (hidepw-render))))
+
+(defun hidepw-render ()
+  "Render a password (hidden)."
+  `(face font-lock-doc-face
+         display ,hidepw-mask))
+
+(defun hidepw-turn-on ()
+  "Turn on hidepw-mode."
+  (let ((props (make-local-variable 'font-lock-extra-managed-props)))
+    (add-to-list props 'display))
+  (font-lock-add-keywords nil (hidepw-font-lock-keywords)))
+
+(defun hidepw-turn-off ()
+  "Turn off hidepw-mode."
+  (font-lock-remove-keywords nil (hidepw-font-lock-keywords)))
+
+;;;###autoload
+(define-minor-mode
+  hidepw-mode
+  "Hide passwords."
+  :lighter " HidePW"
+  (progn
+    (if hidepw-mode
+        (hidepw-turn-on)
+      (hidepw-turn-off))
+    (font-lock-mode 1)))
+
+(provide 'hidepw)
+
+(run-hooks 'hidepw-load-hook)
+
+;;; hidepw.el ends here