*** empty log message ***
[emacs.git] / lisp / pcmpl-linux.el
blob26e5373f66f41e6fb92bdfa21b31bc5aebc3b016
1 ;;; pcmpl-linux --- functions for dealing with cvs completions
3 ;; Copyright (C) 1999, 2000 Free Software Foundation
5 ;; This file is part of GNU Emacs.
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.
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.
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.
22 ;;; Commentary:
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.
28 ;;; Code:
30 (provide 'pcmpl-linux)
32 (require 'pcomplete)
34 (defgroup pcmpl-linux nil
35 "Functions for dealing with GNU/Linux completions."
36 :group 'pcomplete)
38 ;; Functions:
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)))
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)))
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)))
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$")))))
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))))
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))))))
108 ;;; pcmpl-linux.el ends here