Commit | Line | Data |
---|---|---|
60370d40 | 1 | ;;; pcmpl-linux.el --- functions for dealing with GNU/Linux completions |
4fa9f636 GM |
2 | |
3 | ;; Copyright (C) 1999, 2000 Free Software Foundation | |
4 | ||
5 | ;; This file is part of GNU Emacs. | |
6 | ||
7 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 | ;; it under the terms of the GNU General Public License as published by | |
9 | ;; the Free Software Foundation; either version 2, or (at your option) | |
10 | ;; any later version. | |
11 | ||
12 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ;; GNU General Public License for more details. | |
16 | ||
17 | ;; You should have received a copy of the GNU General Public License | |
18 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
19 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | ;; Boston, MA 02111-1307, USA. | |
21 | ||
22 | ;;; Commentary: | |
23 | ||
24 | ;; These functions are for use with GNU/Linux. Since they depend on a | |
25 | ;; certain knowledge of the layout of such systems, they probably | |
26 | ;; won't work very well on other operating systems. | |
27 | ||
28 | ;;; Code: | |
29 | ||
30 | (provide 'pcmpl-linux) | |
31 | ||
32 | (require 'pcomplete) | |
33 | ||
34 | (defgroup pcmpl-linux nil | |
35 | "Functions for dealing with GNU/Linux completions." | |
36 | :group 'pcomplete) | |
37 | ||
38 | ;; Functions: | |
39 | ||
40 | ;;;###autoload | |
41 | (defun pcomplete/kill () | |
42 | "Completion for GNU/Linux `kill', using /proc filesystem." | |
43 | (if (pcomplete-match "^-\\(.*\\)" 0) | |
44 | (pcomplete-here | |
45 | (pcomplete-uniqify-list | |
46 | (split-string | |
47 | (pcomplete-process-result "kill" "-l"))) | |
48 | (pcomplete-match-string 1 0))) | |
49 | (while (pcomplete-here | |
50 | (if (file-directory-p "/proc") | |
51 | (let ((default-directory "/proc/")) | |
52 | (mapcar 'directory-file-name | |
53 | (pcomplete-entries "[0-9]+/$")))) | |
54 | nil 'identity))) | |
55 | ||
56 | ;;;###autoload | |
57 | (defun pcomplete/umount () | |
58 | "Completion for GNU/Linux `umount'." | |
59 | (pcomplete-opt "hVafrnvt(pcmpl-linux-fs-types)") | |
60 | (while (pcomplete-here (pcmpl-linux-mounted-directories) | |
61 | nil 'identity))) | |
62 | ||
63 | ;;;###autoload | |
64 | (defun pcomplete/mount () | |
65 | "Completion for GNU/Linux `mount'." | |
66 | (pcomplete-opt "hVanfFrsvwt(pcmpl-linux-fs-types)o?L?U?") | |
67 | (while (pcomplete-here (pcomplete-entries) nil 'identity))) | |
68 | ||
69 | (defun pcmpl-linux-fs-types () | |
70 | "Return a list of available fs modules on GNU/Linux systems." | |
71 | (let ((kernel-ver (pcomplete-process-result "uname" "-r"))) | |
72 | (mapcar | |
73 | (function | |
74 | (lambda (fsobj) | |
75 | (substring fsobj 0 (- (length fsobj) 2)))) | |
76 | (let ((default-directory | |
77 | (concat "/lib/modules/" kernel-ver "/fs/"))) | |
78 | (pcomplete-entries "\\.o$"))))) | |
79 | ||
80 | (defun pcmpl-linux-mounted-directories () | |
81 | "Return a list of mounted directory names." | |
82 | (let (points) | |
83 | (when (file-readable-p "/etc/mtab") | |
84 | (with-temp-buffer | |
85 | (insert-file-contents-literally "/etc/mtab") | |
86 | (while (not (eobp)) | |
87 | (let* ((line (buffer-substring (point) (line-end-position))) | |
88 | (args (split-string line " "))) | |
89 | (setq points (cons (nth 1 args) points))) | |
90 | (forward-line))) | |
91 | (pcomplete-uniqify-list points)))) | |
92 | ||
93 | (defun pcmpl-linux-mountable-directories () | |
94 | "Return a list of mountable directory names." | |
95 | (let (points) | |
96 | (when (file-readable-p "/etc/fstab") | |
97 | (with-temp-buffer | |
98 | (insert-file-contents-literally "/etc/fstab") | |
99 | (while (not (eobp)) | |
100 | (let* ((line (buffer-substring (point) (line-end-position))) | |
101 | (args (split-string line "\\s-+"))) | |
102 | (setq points (cons (nth 1 args) points))) | |
103 | (forward-line))) | |
104 | (pcomplete-pare-list | |
105 | (pcomplete-uniqify-list points) | |
106 | (cons "swap" (pcmpl-linux-mounted-directories)))))) | |
107 | ||
108 | ;;; pcmpl-linux.el ends here |