kkk-pass.el 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. ;;; kkk-pass.el --- Pass Related Code -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2023 Vinicius Teshima <vini.tes@pm.me>
  3. ;; Author: Vinicius Teshima <vini.tes@pm.me>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;; pass Related Code
  16. ;;; Code:
  17. (defgroup kkk-pass nil
  18. "Initial Tweaks to Emacs."
  19. :group 'info)
  20. (defconst kkk-pass--pass-cmd "pass"
  21. "The `pass` binary to be run.")
  22. (defun kkk-pass-get (NAME &optional LINE)
  23. "Gets the password NAME.
  24. Optionaly returns the line LINE.
  25. NAME is a string.
  26. LINE is a non zero positive integer."
  27. (catch 'early-return
  28. (unless (stringp NAME)
  29. (throw 'early-return "NAME has to be a string"))
  30. (when LINE
  31. (unless (integerp LINE)
  32. (throw 'early-return "LINE has to be an integer"))
  33. (when (= LINE 0)
  34. (throw 'early-return "LINE can't be zero"))
  35. (when (< LINE 0)
  36. (throw 'early-return "LINE can't be less than zero")))
  37. (let ((raw (shell-command-to-string
  38. (format "%s %s" kkk-pass--pass-cmd NAME))))
  39. (if LINE
  40. (nth (1- LINE) (string-lines raw t nil))
  41. raw))))
  42. (provide 'kkk-pass)
  43. ;;; kkk-pass.el ends here