1 ;;; esh-util.el --- general utilities
3 ;; Copyright (C) 1999, 2000, 2001 Free Software Foundation
5 ;; Author: John Wiegley <johnw@gnu.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 (eval-when-compile (require 'esh-maint
))
28 (defgroup eshell-util nil
29 "This is general utility code, meant for use by Eshell itself."
30 :tag
"General utilities"
39 (defcustom eshell-stringify-t t
40 "*If non-nil, the string representation of t is 't'.
41 If nil, t will be represented only in the exit code of the function,
42 and not printed as a string. This causes Lisp functions to behave
43 similarly to external commands, as far as successful result output."
47 (defcustom eshell-group-file
"/etc/group"
48 "*If non-nil, the name of the group file on your system."
49 :type
'(choice (const :tag
"No group file" nil
) file
)
52 (defcustom eshell-passwd-file
"/etc/passwd"
53 "*If non-nil, the name of the passwd file on your system."
54 :type
'(choice (const :tag
"No passwd file" nil
) file
)
57 (defcustom eshell-hosts-file
"/etc/hosts"
58 "*The name of the /etc/hosts file."
59 :type
'(choice (const :tag
"No hosts file" nil
) file
)
62 (defcustom eshell-handle-errors t
63 "*If non-nil, Eshell will handle errors itself.
64 Setting this to nil is offered as an aid to debugging only."
68 (defcustom eshell-private-file-modes
384 ; umask 177
69 "*The file-modes value to use for creating \"private\" files."
73 (defcustom eshell-private-directory-modes
448 ; umask 077
74 "*The file-modes value to use for creating \"private\" directories."
78 (defcustom eshell-tar-regexp
79 "\\.t\\(ar\\(\\.\\(gz\\|bz2\\|Z\\)\\)?\\|gz\\|a[zZ]\\|z2\\)\\'"
80 "*Regular expression used to match tar file names."
84 (defcustom eshell-convert-numeric-arguments t
85 "*If non-nil, converting arguments of numeric form to Lisp numbers.
86 Numeric form is tested using the regular expression
87 `eshell-number-regexp'.
89 NOTE: If you find that numeric conversions are intefering with the
90 specification of filenames (for example, in calling `find-file', or
91 some other Lisp function that deals with files, not numbers), add the
92 following in your .emacs file:
94 (put 'find-file 'eshell-no-numeric-conversions t)
96 Any function with the property `eshell-no-numeric-conversions' set to
97 a non-nil value, will be passed strings, not numbers, even when an
98 argument matches `eshell-number-regexp'."
102 (defcustom eshell-number-regexp
"-?\\([0-9]*\\.\\)?[0-9]+\\(e[-0-9.]+\\)?"
103 "*Regular expression used to match numeric arguments.
104 If `eshell-convert-numeric-arguments' is non-nil, and an argument
105 matches this regexp, it will be converted to a Lisp number, using the
106 function `string-to-number'."
110 (defcustom eshell-ange-ls-uids nil
111 "*List of user/host/id strings, used to determine remote ownership."
112 :type
'(repeat (cons :tag
"Host for User/UID map"
113 (string :tag
"Hostname")
114 (repeat (cons :tag
"User/UID List"
115 (string :tag
"Username")
116 (repeat :tag
"UIDs" string
)))))
119 ;;; Internal Variables:
121 (defvar eshell-group-names nil
122 "A cache to hold the names of groups.")
124 (defvar eshell-group-timestamp nil
125 "A timestamp of when the group file was read.")
127 (defvar eshell-user-names nil
128 "A cache to hold the names of users.")
130 (defvar eshell-user-timestamp nil
131 "A timestamp of when the user file was read.")
133 (defvar eshell-host-names nil
134 "A cache the names of frequently accessed hosts.")
136 (defvar eshell-host-timestamp nil
137 "A timestamp of when the hosts file was read.")
141 (defsubst eshell-under-xemacs-p
()
142 "Return non-nil if we are running under XEmacs."
143 (boundp 'xemacs-logo
))
145 (defsubst eshell-under-windows-p
()
146 "Return non-nil if we are running under MS-DOS/Windows."
147 (memq system-type
'(ms-dos windows-nt
)))
149 (defmacro eshell-condition-case
(tag form
&rest handlers
)
150 "Like `condition-case', but only if `eshell-pass-through-errors' is nil."
151 (if eshell-handle-errors
152 `(condition-case ,tag
157 (put 'eshell-condition-case
'lisp-indent-function
2)
159 (defmacro eshell-deftest
(module name label
&rest forms
)
160 (if (and (fboundp 'cl-compiling-file
) (cl-compiling-file))
162 (let ((fsym (intern (concat "eshell-test--" (symbol-name name
)))))
165 (defun ,fsym
() ,label
166 (eshell-run-test (quote ,module
) (quote ,fsym
) ,label
167 (quote (progn ,@forms
)))))))))
169 (put 'eshell-deftest
'lisp-indent-function
2)
171 (defun eshell-find-delimiter
172 (open close
&optional bound reverse-p backslash-p
)
173 "From point, find the CLOSE delimiter corresponding to OPEN.
174 The matching is bounded by BOUND.
175 If REVERSE-P is non-nil, process the region backwards.
176 If BACKSLASH-P is non-nil, and OPEN and CLOSE are the same character,
177 then quoting is done by a backslash, rather than a doubled delimiter."
180 (bound (or bound
(point-max))))
182 (eq (char-before) close
)
183 (eq (char-after) open
))
184 (forward-char (if reverse-p -
1 1)))
185 (while (and (> depth
0)
186 (funcall (if reverse-p
'> '<) (point) bound
))
187 (let ((c (if reverse-p
(char-before) (char-after))) nc
)
188 (cond ((and (not reverse-p
)
189 (or (not (eq open close
))
192 (setq nc
(char-after (1+ (point))))
193 (or (eq nc open
) (eq nc close
)))
196 (or (not (eq open close
))
198 (or (eq c open
) (eq c close
))
199 (eq (char-before (1- (point)))
204 (if (and (not backslash-p
)
206 (char-before (1- (point)))
207 (char-after (1+ (point)))) open
))
208 (forward-char (if reverse-p -
1 1))
209 (setq depth
(1- depth
)))))
211 (setq depth
(+ depth
(if reverse-p -
1 1))))
213 (setq depth
(+ depth
(if reverse-p
1 -
1))))))
214 (forward-char (if reverse-p -
1 1)))
216 (if reverse-p
(point) (1- (point)))))))
218 (defun eshell-convert (string)
219 "Convert STRING into a more native looking Lisp object."
220 (if (not (stringp string
))
222 (let ((len (length string
)))
225 (if (eq (aref string
(1- len
)) ?
\n)
226 (setq string
(substring string
0 (1- len
))))
227 (if (string-match "\n" string
)
228 (split-string string
"\n")
229 (if (and eshell-convert-numeric-arguments
231 (concat "\\`\\s-*" eshell-number-regexp
233 (string-to-number string
)
236 (defun eshell-sublist (l &optional n m
)
237 "Return from LIST the N to M elements.
238 If N or M is nil, it means the end of the list."
239 (let* ((a (eshell-copy-list l
))
241 (if (and m
(consp (nthcdr m a
)))
242 (setcdr (nthcdr m a
) nil
))
244 (setq a
(nthcdr n a
))
245 (setq n
(1- (length a
))
249 (defun eshell-split-path (path)
250 "Split a path into multiple subparts."
251 (let ((len (length path
))
254 (if (and (eshell-under-windows-p)
256 (eq (aref path
0) directory-sep-char
)
257 (eq (aref path
1) directory-sep-char
))
260 (if (and (eq (aref path i
) directory-sep-char
)
261 (not (get-text-property i
'escaped path
)))
262 (setq parts
(cons (if (= li i
)
263 (char-to-string directory-sep-char
)
264 (substring path li
(1+ i
))) parts
)
268 (setq parts
(cons (substring path li i
) parts
)))
269 (if (and (eshell-under-windows-p)
270 (string-match "\\`[A-Za-z]:\\'" (car (last parts
))))
272 (concat (car (last parts
))
273 (char-to-string directory-sep-char
))))
276 (defun eshell-to-flat-string (value)
277 "Make value a string. If separated by newlines change them to spaces."
278 (let ((text (eshell-stringify value
)))
279 (if (string-match "\n+\\'" text
)
280 (setq text
(replace-match "" t t text
)))
281 (while (string-match "\n+" text
)
282 (setq text
(replace-match " " t t text
)))
285 (defmacro eshell-for
(for-var for-list
&rest forms
)
286 "Iterate through a list"
287 `(let ((list-iter ,for-list
))
289 (let ((,for-var
(car list-iter
)))
291 (setq list-iter
(cdr list-iter
)))))
293 (put 'eshell-for
'lisp-indent-function
2)
295 (defun eshell-flatten-list (args)
296 "Flatten any lists within ARGS, so that there are no sublists."
297 (let ((new-list (list t
)))
301 (nconc new-list
(eshell-flatten-list a
))
302 (nconc new-list
(list a
))))
305 (defun eshell-uniqify-list (l)
306 "Remove occurring multiples in L. You probably want to sort first."
316 (defun eshell-stringify (object)
317 "Convert OBJECT into a string value."
319 ((stringp object
) object
)
321 (not (eq object nil
)))
322 (let ((string (pp-to-string object
)))
323 (substring string
0 (1- (length string
)))))
325 (number-to-string object
))
327 (unless (and (eq object t
)
328 (not eshell-stringify-t
))
329 (pp-to-string object
)))))
331 (defsubst eshell-stringify-list
(args)
332 "Convert each element of ARGS into a string value."
333 (mapcar 'eshell-stringify args
))
335 (defsubst eshell-flatten-and-stringify
(&rest args
)
336 "Flatten and stringify all of the ARGS into a single string."
337 (mapconcat 'eshell-stringify
(eshell-flatten-list args
) " "))
339 ;; the next two are from GNUS, and really should be made part of Emacs
341 (defsubst eshell-time-less-p
(t1 t2
)
342 "Say whether time T1 is less than time T2."
343 (or (< (car t1
) (car t2
))
344 (and (= (car t1
) (car t2
))
345 (< (nth 1 t1
) (nth 1 t2
)))))
347 (defsubst eshell-time-to-seconds
(time)
348 "Convert TIME to a floating point number."
349 (+ (* (car time
) 65536.0)
351 (/ (or (car (cdr (cdr time
))) 0) 1000000.0)))
353 (defsubst eshell-directory-files
(regexp &optional directory
)
354 "Return a list of files in the given DIRECTORY matching REGEXP."
355 (directory-files (or directory default-directory
)
358 (defun eshell-regexp-arg (prompt)
359 "Return list of regexp and prefix arg using PROMPT."
360 (let* (;; Don't clobber this.
361 (last-command last-command
)
362 (regexp (read-from-minibuffer prompt nil nil nil
363 'minibuffer-history-search-history
)))
364 (list (if (string-equal regexp
"")
365 (setcar minibuffer-history-search-history
366 (nth 1 minibuffer-history-search-history
))
368 (prefix-numeric-value current-prefix-arg
))))
370 (defun eshell-printable-size (filesize &optional human-readable
371 block-size use-colors
)
372 "Return a printable FILESIZE."
373 (let ((size (float (or filesize
0))))
375 (if (< size human-readable
)
376 (if (= (round size
) 0)
380 (format "%.0f" size
)))
381 (setq size
(/ size human-readable
))
382 (if (< size human-readable
)
384 (format "%.1fk" size
)
385 (format "%.0fk" size
))
386 (setq size
(/ size human-readable
))
387 (if (< size human-readable
)
388 (let ((str (if (<= size
9.94)
389 (format "%.1fM" size
)
390 (format "%.0fM" size
))))
392 (put-text-property 0 (length str
)
395 (setq size
(/ size human-readable
))
396 (if (< size human-readable
)
397 (let ((str (if (<= size
9.94)
398 (format "%.1fG" size
)
399 (format "%.0fG" size
))))
401 (put-text-property 0 (length str
)
402 'face
'bold-italic str
))
405 (setq size
(/ size block-size
)))
406 (format "%.0f" size
))))
408 (defun eshell-winnow-list (entries exclude
&optional predicates
)
409 "Pare down the ENTRIES list using the EXCLUDE regexp, and PREDICATES.
410 The original list is not affected. If the result is only one element
411 long, it will be returned itself, rather than returning a one-element
413 (let ((flist (list t
))
415 (unless (listp entries
)
416 (setq entries
(list entries
)
418 (eshell-for entry entries
419 (unless (and exclude
(string-match exclude entry
))
420 (setq p predicates valid
(null p
))
422 (if (funcall (car p
) entry
)
424 (setq p nil valid nil
))
427 (nconc flist
(list entry
)))))
432 (defsubst eshell-redisplay
()
433 "Allow Emacs to redisplay buffers."
434 ;; for some strange reason, Emacs 21 is prone to trigger an
435 ;; "args out of range" error in `sit-for', if this function
436 ;; runs while point is in the minibuffer and the users attempt
437 ;; to use completion. Don't ask me.
438 (ignore-errors (sit-for 0 0)))
440 (defun eshell-read-passwd-file (file)
441 "Return an alist correlating gids to group names in FILE."
443 (when (file-readable-p file
)
445 (insert-file-contents file
)
446 (goto-char (point-min))
449 (split-string (buffer-substring
450 (point) (progn (end-of-line)
452 (if (and (and fields
(nth 0 fields
) (nth 2 fields
))
453 (not (assq (string-to-int (nth 2 fields
)) names
)))
454 (setq names
(cons (cons (string-to-int (nth 2 fields
))
460 (defun eshell-read-passwd (file result-var timestamp-var
)
461 "Read the contents of /etc/passwd for user names."
462 (if (or (not (symbol-value result-var
))
463 (not (symbol-value timestamp-var
))
465 (symbol-value timestamp-var
)
466 (nth 5 (file-attributes file
))))
468 (set result-var
(eshell-read-passwd-file file
))
469 (set timestamp-var
(current-time))))
470 (symbol-value result-var
))
472 (defun eshell-read-group-names ()
473 "Read the contents of /etc/group for group names."
474 (if eshell-group-file
475 (eshell-read-passwd eshell-group-file
'eshell-group-names
476 'eshell-group-timestamp
)))
478 (defsubst eshell-group-id
(name)
479 "Return the user id for user NAME."
480 (car (rassoc name
(eshell-read-group-names))))
482 (defsubst eshell-group-name
(gid)
483 "Return the group name for the given GID."
484 (cdr (assoc gid
(eshell-read-group-names))))
486 (defun eshell-read-user-names ()
487 "Read the contents of /etc/passwd for user names."
488 (if eshell-passwd-file
489 (eshell-read-passwd eshell-passwd-file
'eshell-user-names
490 'eshell-user-timestamp
)))
492 (defsubst eshell-user-id
(name)
493 "Return the user id for user NAME."
494 (car (rassoc name
(eshell-read-user-names))))
496 (defalias 'eshell-user-name
'user-login-name
)
498 (defun eshell-read-hosts-file (filename)
499 "Read in the hosts from the /etc/hosts file."
502 (insert-file-contents eshell-hosts-file
)
503 (goto-char (point-min))
504 (while (re-search-forward
505 "^\\(\\S-+\\)\\s-+\\(\\S-+\\)\\(\\s-*\\(\\S-+\\)\\)?" nil t
)
507 (add-to-list 'hosts
(match-string 1)))
509 (add-to-list 'hosts
(match-string 2)))
511 (add-to-list 'hosts
(match-string 4)))))
512 (sort hosts
'string-lessp
)))
514 (defun eshell-read-hosts (file result-var timestamp-var
)
515 "Read the contents of /etc/passwd for user names."
516 (if (or (not (symbol-value result-var
))
517 (not (symbol-value timestamp-var
))
519 (symbol-value timestamp-var
)
520 (nth 5 (file-attributes file
))))
522 (set result-var
(eshell-read-hosts-file file
))
523 (set timestamp-var
(current-time))))
524 (symbol-value result-var
))
526 (defun eshell-read-host-names ()
527 "Read the contents of /etc/hosts for host names."
528 (if eshell-hosts-file
529 (eshell-read-hosts eshell-hosts-file
'eshell-host-names
530 'eshell-host-timestamp
)))
532 (unless (fboundp 'line-end-position
)
533 (defsubst line-end-position
(&optional N
)
534 (save-excursion (end-of-line N
) (point))))
536 (unless (fboundp 'line-beginning-position
)
537 (defsubst line-beginning-position
(&optional N
)
538 (save-excursion (beginning-of-line N
) (point))))
540 (unless (fboundp 'subst-char-in-string
)
541 (defun subst-char-in-string (fromchar tochar string
&optional inplace
)
542 "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
543 Unless optional argument INPLACE is non-nil, return a new string."
544 (let ((i (length string
))
545 (newstr (if inplace string
(copy-sequence string
))))
548 (if (eq (aref newstr i
) fromchar
)
549 (aset newstr i tochar
)))
552 (defsubst eshell-copy-environment
()
553 "Return an unrelated copy of `process-environment'."
554 (mapcar 'concat process-environment
))
556 (defun eshell-subgroups (groupsym)
557 "Return all of the subgroups of GROUPSYM."
558 (let ((subgroups (get groupsym
'custom-group
))
561 (if (eq (cadr (car subgroups
)) 'custom-group
)
562 (nconc subg
(list (caar subgroups
))))
563 (setq subgroups
(cdr subgroups
)))
566 (defmacro eshell-with-file-modes
(modes &rest forms
)
567 "Evaluate, with file-modes set to MODES, the given FORMS."
568 `(let ((modes (default-file-modes)))
569 (set-default-file-modes ,modes
)
572 (set-default-file-modes modes
))))
574 (defmacro eshell-with-private-file-modes
(&rest forms
)
575 "Evaluate FORMS with private file modes set."
576 `(eshell-with-file-modes ,eshell-private-file-modes
,@forms
))
578 (defsubst eshell-make-private-directory
(dir &optional parents
)
579 "Make DIR with file-modes set to `eshell-private-directory-modes'."
580 (eshell-with-file-modes eshell-private-directory-modes
581 (make-directory dir parents
)))
583 (defsubst eshell-substring
(string sublen
)
584 "Return the beginning of STRING, up to SUBLEN bytes."
586 (if (> (length string
) sublen
)
587 (substring string
0 sublen
)
590 (unless (fboundp 'directory-files-and-attributes
)
591 (defun directory-files-and-attributes (dir &optional full match nosort
)
592 (documentation 'directory-files
)
593 (let ((dir (expand-file-name dir
)) ange-cache
)
597 (cons file
(eshell-file-attributes (expand-file-name file dir
)))))
598 (directory-files dir full match nosort
)))))
603 (defun eshell-directory-files-and-attributes (dir &optional full match nosort
)
604 "Make sure to use the handler for `directory-file-and-attributes'."
605 (let* ((dir (expand-file-name dir
))
606 (dfh (find-file-name-handler dir
'directory-files
)))
608 (directory-files-and-attributes dir full match nosort
)
609 (let ((files (funcall dfh
'directory-files dir full match nosort
))
610 (fah (find-file-name-handler dir
'file-attributes
)))
615 (eshell-file-attributes
616 (expand-file-name file dir
))
617 (file-attributes (expand-file-name file dir
))))))
620 (defun eshell-current-ange-uids ()
621 (if (string-match "/\\([^@]+\\)@\\([^:]+\\):" default-directory
)
622 (let* ((host (match-string 2 default-directory
))
623 (user (match-string 1 default-directory
))
624 (host-users (assoc host eshell-ange-ls-uids
)))
626 (setq host-users
(cdr host-users
))
627 (cdr (assoc user host-users
))))))
629 ;; Add an autoload for parse-time-string
630 (if (and (not (fboundp 'parse-time-string
))
631 (locate-library "parse-time"))
632 (autoload 'parse-time-string
"parse-time"))
637 (defun eshell-parse-ange-ls (dir)
640 (insert (ange-ftp-ls dir
"-la" nil
))
641 (goto-char (point-min))
642 (if (looking-at "^total [0-9]+$")
644 ;; Some systems put in a blank line here.
645 (if (eolp) (forward-line 1))
647 `,(concat "\\([dlscb-][rwxst-]+\\)"
648 "\\s-*" "\\([0-9]+\\)" "\\s-+"
649 "\\(\\S-+\\)" "\\s-+"
650 "\\(\\S-+\\)" "\\s-+"
651 "\\([0-9]+\\)" "\\s-+" "\\(.*\\)"))
652 (let* ((perms (match-string 1))
653 (links (string-to-number (match-string 2)))
654 (user (match-string 3))
655 (group (match-string 4))
656 (size (string-to-number (match-string 5)))
658 (if (fboundp 'parse-time-string
)
659 (let ((moment (parse-time-string
662 (setcar (nthcdr 5 moment
)
663 (nth 5 (decode-time (current-time))))
664 (setcar (nthcdr 0 moment
) 0)
665 (setcar (nthcdr 1 moment
) 0)
666 (setcar (nthcdr 2 moment
) 0))
667 (apply 'encode-time moment
))
668 (ange-ftp-file-modtime (expand-file-name name dir
))))
669 (name (ange-ftp-parse-filename))
671 (if (string-match "\\(.+\\) -> \\(.+\\)" name
)
672 (setq symlink
(match-string 2 name
)
673 name
(match-string 1 name
)))
677 (list (if (eq (aref perms
0) ?d
)
682 size perms nil nil
)) entry
)))
686 (defun eshell-file-attributes (file)
687 "Return the attributes of FILE, playing tricks if it's over ange-ftp."
688 (let* ((file (expand-file-name file
))
689 (handler (find-file-name-handler file
'file-attributes
))
692 (file-attributes file
)
693 (if (eq (find-file-name-handler (file-name-directory file
)
695 'ange-ftp-hook-function
)
696 (let ((base (file-name-nondirectory file
))
697 (dir (file-name-directory file
)))
698 (if (boundp 'ange-cache
)
699 (setq entry
(cdr (assoc base
(cdr (assoc dir ange-cache
))))))
701 (setq entry
(eshell-parse-ange-ls dir
))
702 (if (boundp 'ange-cache
)
704 (cons (cons dir entry
)
707 (let ((fentry (assoc base
(cdr entry
))))
709 (setq entry
(cdr fentry
))
710 (setq entry nil
)))))))
711 (or entry
(funcall handler
'file-attributes file
)))))
713 (defun eshell-copy-list (list)
714 "Return a copy of a list, which may be a dotted list.
715 The elements of the list are not copied, just the list structure itself."
718 (while (consp list
) (push (pop list
) res
))
719 (prog1 (nreverse res
) (setcdr res list
)))
722 (defun eshell-copy-tree (tree &optional vecp
)
723 "Make a copy of TREE.
724 If TREE is a cons cell, this recursively copies both its car and its cdr.
725 Contrast to copy-sequence, which copies only along the cdrs. With second
726 argument VECP, this copies vectors as well as conses."
728 (let ((p (setq tree
(eshell-copy-list tree
))))
730 (if (or (consp (car p
)) (and vecp
(vectorp (car p
))))
731 (setcar p
(eshell-copy-tree (car p
) vecp
)))
732 (or (listp (cdr p
)) (setcdr p
(eshell-copy-tree (cdr p
) vecp
)))
734 (if (and vecp
(vectorp tree
))
735 (let ((i (length (setq tree
(copy-sequence tree
)))))
736 (while (>= (setq i
(1- i
)) 0)
737 (aset tree i
(eshell-copy-tree (aref tree i
) vecp
))))))
740 (defsubst eshell-processp
(proc)
741 "If the `processp' function does not exist, PROC is not a process."
742 (and (fboundp 'processp
) (processp proc
)))
744 ; (defun eshell-copy-file
745 ; (file newname &optional ok-if-already-exists keep-date)
746 ; "Copy FILE to NEWNAME. See docs for `copy-file'."
748 ; (if (string-match "\\`\\([^:]+\\):\\(.*\\)" file)
749 ; (let ((front (match-string 1 file))
750 ; (back (match-string 2 file))
752 ; (if (and front (string-match eshell-tar-regexp front)
753 ; (setq buffer (find-file-noselect front)))
754 ; (with-current-buffer buffer
755 ; (goto-char (point-min))
756 ; (if (re-search-forward (concat " " (regexp-quote back)
759 ; (tar-copy (if (file-directory-p newname)
761 ; (file-name-nondirectory back) newname)
764 ; (error "%s not found in tar file %s" back front))))))
766 ; (copy-file file newname ok-if-already-exists keep-date))))
768 ; (defun eshell-file-attributes (filename)
769 ; "Return a list of attributes of file FILENAME.
770 ; See the documentation for `file-attributes'."
772 ; (when (string-match "\\`\\([^:]+\\):\\(.*\\)\\'" filename)
773 ; (let ((front (match-string 1 filename))
774 ; (back (match-string 2 filename))
776 ; (when (and front (string-match eshell-tar-regexp front)
777 ; (setq buffer (find-file-noselect front)))
778 ; (with-current-buffer buffer
779 ; (goto-char (point-min))
780 ; (when (re-search-forward (concat " " (regexp-quote back)
782 ; (let* ((descrip (tar-current-descriptor))
783 ; (tokens (tar-desc-tokens descrip)))
787 ; ((eq (tar-header-link-type tokens) 5)
789 ; ((eq (tar-header-link-type tokens) t)
790 ; (tar-header-link-name tokens)))
792 ; (tar-header-uid tokens)
793 ; (tar-header-gid tokens)
794 ; (tar-header-date tokens)
795 ; (tar-header-date tokens)
796 ; (tar-header-date tokens)
797 ; (tar-header-size tokens)
800 ; ((eq (tar-header-link-type tokens) 5) "d")
801 ; ((eq (tar-header-link-type tokens) t) "l")
803 ; (tar-grind-file-mode (tar-header-mode tokens)
804 ; (make-string 9 ? ) 0))
805 ; nil nil nil))))))))
807 ; (file-attributes filename))))
811 ;;; esh-util.el ends here