-
Notifications
You must be signed in to change notification settings - Fork 1
/
pcmpl-apt.el
110 lines (96 loc) · 3.6 KB
/
pcmpl-apt.el
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
107
108
109
110
;;; pcmpl-apt.el --- functions for dealing with Debian apt completions
;;
;; Copyright (C) 2012 Damien Cassou
;;
;; Author: Damien Cassou <damien.cassou@gmail.com>
;; Url: https://github.com/DamienCassou/emacs-pcomplete-plugins
;; GIT: https://github.com/DamienCassou/emacs-pcomplete-plugins
;; Version: 0.1
;; Created: 2012-09-07
;; Keywords: emacs package eshell pcomplete completion apt apt-get
;;
;; This file is NOT part of GNU Emacs.
;;
;; 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 2, 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 ; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;
;;; Commentary:
;;
;; This code provides eshell completion for apt-get, apt-cache and
;; aptitude Debian tools.
;;
;;; Code:
(require 'pcomplete)
(defgroup pcmpl-apt-get nil
"Functions for dealing with APT-GET completions."
:group 'pcomplete)
;; User Variables:
(defcustom pcmpl-apt-get-binary (or (executable-find "apt-get") "apt-get")
"The full path of the 'apt-get' binary."
:type 'file
:group 'pcmpl-apt-get)
;; Functions:
;;;###autoload
(defun pcomplete/apt-get ()
"Completion rules for the `apt-get' command."
(let ((pcomplete-help "(apt-get)Invoking APT-GET"))
(pcomplete-opt (pcmpl-apt-get-options))
(pcomplete-here* (pcmpl-apt-get-commands))
(cond ((or (pcomplete-test "remove")
(pcomplete-test "autoremove")
(pcomplete-test "purge"))
(setq pcomplete-help "(apt-get)Removing packages")
(while (pcomplete-here
(pcmpl-apt-get-installed-packages))))
((pcomplete-test "source")
(setq pcomplete-help "(apt-get)Downloading sources")
(while (pcomplete-here
(pcmpl-apt-get-source-packages))))
(t
(while (pcomplete-here
(pcmpl-apt-get-installable-packages)))))))
(defun pcmpl-apt-get-commands ()
"Return a list of available APT-GET commands."
(pcomplete-uniqify-list
(list "update" "upgrade" "dselect-upgrade" "dist-upgrade" "install"
"remove" "purge" "source" "build-dep" "check" "download"
"clean" "autoclean" "autoremove" "changelog")))
(defun pcmpl-apt-get-installed-packages ()
"Return a list of all packages installed through apt."
(pcmpl-apt-get-shell-command-to-list
(concat
"grep -A 1 \"Package: \" /var/lib/dpkg/status | "
"grep -B 1 -Ee "
"\"ok installed|half-installed|unpacked|half-configured|"
"config-files\" -Ee \"^Essential: yes\" | "
"grep \"Package: \" | cut -d\\ -f2")))
(defun pcmpl-apt-get-source-packages ()
(append
(pcmpl-apt-get-shell-command-to-list
"apt-cache --no-generate pkgnames 2>/dev/null | head -n 2")
(pcmpl-apt-get-shell-command-to-list
(concat
"apt-cache dumpavail | "
"grep \"^Source: \" | sort -u | cut -f2 -d' ' | head -n 2"))))
(defun pcmpl-apt-get-installable-packages ()
(pcmpl-apt-get-shell-command-to-list
"apt-cache --no-generate pkgnames 2>/dev/null"))
(defun pcmpl-apt-get-options ()
"sqdyfmubVvh")
(defun pcmpl-apt-get-shell-command-to-list (command)
(pcomplete-uniqify-list
(split-string (shell-command-to-string command))))
(provide 'pcmpl-apt)
;;; pcmpl-apt.el ends here