Repository navigation
Expand file tree
/
Copy patheshell-command-not-found.el
More file actions
106 lines (89 loc) · 3.7 KB
/
Copy patheshell-command-not-found.el
File metadata and controls
106 lines (89 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
;;; eshell-command-not-found.el --- Integrate command-not-found in eshell -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Jaehyun Yeom
;; Author: Jaehyun Yeom <jae.yeom@gmail.com>
;; Package-Requires: ((emacs "25.1"))
;; Keywords: convenience
;; URL: https://github.com/jaeyeom/eshell-command-not-found
;; Version: 0.1.2
;; SPDX-License-Identifier: GPL-3.0-or-later
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;; This file is NOT part of GNU Emacs.
;;; Commentary:
;; This package integrates command-not-found in eshell. It suggests
;; packages to install when a command is not found.
;;
;; Requirements:
;; - command-not-found
;;
;; Usage:
;;
;; In `eshell' buffer, if you type a command that is not found, it would suggest
;; you to install the package that provides the command.
;;
;; You can customize `eshell-command-not-found-command' to set the path to the
;; command-not-found executable. The default value is determined by checking a
;; few common paths.
;;
;; To enable this feature, you can either use `eshell-command-not-found-mode' or
;; customize `eshell-command-not-found-mode' to `t'.
;;; Code:
(require 'esh-ext)
(require 'seq)
(require 'subr-x)
;;;###autoload
(defcustom eshell-command-not-found-command
(seq-find #'file-executable-p
'("/data/data/com.termux/files/usr/libexec/termux/command-not-found"
"/usr/lib/command-not-found"
"/usr/libexec/pk-command-not-found"
"/usr/bin/command-not-found"))
"Path to command-not-found executable."
:type 'string
:group 'eshell-mode)
(defun eshell-command-not-found (command)
"Hook to run command-not-found script in eshell.
Argument COMMAND is the not found command."
(error "%s" (string-trim-right
(shell-command-to-string
(format "%s %s"
eshell-command-not-found-command
(shell-quote-argument command))))))
;;;###autoload
(define-minor-mode eshell-command-not-found-mode
"Toggle command-not-found integration on `eshell-mode'."
:group 'eshell-mode
:init-value nil
:lighter nil
(if eshell-command-not-found-mode
(if eshell-command-not-found-command
(add-hook 'eshell-alternate-command-hook #'eshell-command-not-found)
(progn
(setq eshell-command-not-found-mode nil)
(error "Variable eshell-command-not-found-command is not properly set")))
(remove-hook 'eshell-alternate-command-hook #'eshell-command-not-found)))
(defun eshell-command-not-found-mode-on ()
"Turn on `eshell-command-not-found-mode'."
(when (derived-mode-p 'eshell-mode)
(eshell-command-not-found-mode 1)))
;;;###autoload
(defcustom eshell-command-not-found-mode nil
"Toggle command-not-found integration on `eshell-mode'.
Setting this variable directly does not take effect;
use either \\[customize] or function `eshell-command-not-found-mode'."
:set (lambda (_ value)
(eshell-command-not-found-mode (if value 1 -1)))
:initialize 'custom-initialize-default
:type 'boolean
:group 'eshell-mode
:require 'eshell-command-not-found)
(provide 'eshell-command-not-found)
;;; eshell-command-not-found.el ends here