diff options
| author | Jim Porter | 2024-11-08 23:12:53 -0800 |
|---|---|---|
| committer | Jim Porter | 2024-11-09 17:01:33 -0800 |
| commit | f26fb25ec8ca12901db6224973c7fef29ce938f9 (patch) | |
| tree | f33e4ab28b5500dbe90c3f51e1628439470f98b6 | |
| parent | f6a63e4b441424298f1239372ec50b528d343b65 (diff) | |
| download | emacs-f26fb25ec8ca12901db6224973c7fef29ce938f9.tar.gz emacs-f26fb25ec8ca12901db6224973c7fef29ce938f9.zip | |
Use the Lisp implemention of "du" in Eshell when querying remote dirs
* lisp/eshell/em-unix.el (eshell/du): If all directories are local, use
the external "du" instead.
| -rw-r--r-- | lisp/eshell/em-unix.el | 117 |
1 files changed, 57 insertions, 60 deletions
diff --git a/lisp/eshell/em-unix.el b/lisp/eshell/em-unix.el index 671573f38c5..17dd14d0f3e 100644 --- a/lisp/eshell/em-unix.el +++ b/lisp/eshell/em-unix.el | |||
| @@ -910,67 +910,64 @@ external command." | |||
| 910 | 910 | ||
| 911 | (defun eshell/du (&rest args) | 911 | (defun eshell/du (&rest args) |
| 912 | "Implementation of \"du\" in Lisp, passing ARGS." | 912 | "Implementation of \"du\" in Lisp, passing ARGS." |
| 913 | (setq args (if args | 913 | (let ((original-args args)) |
| 914 | (eshell-stringify-list (flatten-tree args)) | 914 | (eshell-eval-using-options |
| 915 | '("."))) | 915 | "du" args |
| 916 | (let ((ext-du (eshell-search-path "du"))) | 916 | '((?a "all" nil show-all |
| 917 | (if (and ext-du | 917 | "write counts for all files, not just directories") |
| 918 | (not (catch 'have-ange-path | 918 | (nil "block-size" t block-size |
| 919 | (dolist (arg args) | 919 | "use SIZE-byte blocks (i.e., --block-size SIZE)") |
| 920 | (if (string-equal | 920 | (?b "bytes" nil by-bytes |
| 921 | (file-remote-p (expand-file-name arg) 'method) "ftp") | 921 | "print size in bytes") |
| 922 | (throw 'have-ange-path t)))))) | 922 | (?c "total" nil grand-total |
| 923 | (throw 'eshell-external (eshell-external-command ext-du args)) | 923 | "produce a grand total") |
| 924 | (eshell-eval-using-options | 924 | (?d "max-depth" t max-depth |
| 925 | "du" args | 925 | "display data only this many levels of data") |
| 926 | '((?a "all" nil show-all | 926 | (?h "human-readable" 1024 human-readable |
| 927 | "write counts for all files, not just directories") | 927 | "print sizes in human readable format") |
| 928 | (nil "block-size" t block-size | 928 | (?H "si" 1000 human-readable |
| 929 | "use SIZE-byte blocks (i.e., --block-size SIZE)") | 929 | "likewise, but use powers of 1000 not 1024") |
| 930 | (?b "bytes" nil by-bytes | 930 | (?k "kilobytes" 1024 block-size |
| 931 | "print size in bytes") | 931 | "like --block-size 1024") |
| 932 | (?c "total" nil grand-total | 932 | (?L "dereference" nil dereference-links |
| 933 | "produce a grand total") | 933 | "dereference all symbolic links") |
| 934 | (?d "max-depth" t max-depth | 934 | (?m "megabytes" 1048576 block-size |
| 935 | "display data only this many levels of data") | 935 | "like --block-size 1048576") |
| 936 | (?h "human-readable" 1024 human-readable | 936 | (?s "summarize" 0 max-depth |
| 937 | "print sizes in human readable format") | 937 | "display only a total for each argument") |
| 938 | (?H "si" 1000 human-readable | 938 | (?x "one-file-system" nil only-one-filesystem |
| 939 | "likewise, but use powers of 1000 not 1024") | 939 | "skip directories on different filesystems") |
| 940 | (?k "kilobytes" 1024 block-size | 940 | (nil "help" nil nil |
| 941 | "like --block-size 1024") | 941 | "show this usage screen") |
| 942 | (?L "dereference" nil dereference-links | 942 | :external "du" |
| 943 | "dereference all symbolic links") | 943 | :usage "[OPTION]... FILE... |
| 944 | (?m "megabytes" 1048576 block-size | ||
| 945 | "like --block-size 1048576") | ||
| 946 | (?s "summarize" 0 max-depth | ||
| 947 | "display only a total for each argument") | ||
| 948 | (?x "one-file-system" nil only-one-filesystem | ||
| 949 | "skip directories on different filesystems") | ||
| 950 | (nil "help" nil nil | ||
| 951 | "show this usage screen") | ||
| 952 | :external "du" | ||
| 953 | :usage "[OPTION]... FILE... | ||
| 954 | Summarize disk usage of each FILE, recursively for directories.") | 944 | Summarize disk usage of each FILE, recursively for directories.") |
| 955 | (unless by-bytes | 945 | ;; If possible, use the external "du" command. |
| 956 | (setq block-size (or block-size 1024))) | 946 | (when-let* (((not (seq-some |
| 957 | (if (and max-depth (stringp max-depth)) | 947 | (lambda (i) (and (stringp i) (file-remote-p i))) |
| 958 | (setq max-depth (string-to-number max-depth))) | 948 | args))) |
| 959 | ;; filesystem support means nothing under Windows | 949 | (ext-du (eshell-search-path "du"))) |
| 960 | (if (eshell-under-windows-p) | 950 | (throw 'eshell-external (eshell-external-command ext-du original-args))) |
| 961 | (setq only-one-filesystem nil)) | 951 | (unless by-bytes |
| 962 | (let ((size 0.0)) | 952 | (setq block-size (or block-size 1024))) |
| 963 | (while args | 953 | (when (stringp block-size) |
| 964 | (if only-one-filesystem | 954 | (setq block-size (string-to-number block-size))) |
| 965 | (setq only-one-filesystem | 955 | (when (stringp max-depth) |
| 966 | (file-attribute-device-number (eshell-file-attributes | 956 | (setq max-depth (string-to-number max-depth))) |
| 967 | (file-name-as-directory (car args)))))) | 957 | ;; Filesystem support means nothing under MS-Windows. |
| 968 | (setq size (+ size (eshell-du-sum-directory | 958 | (when (eshell-under-windows-p) |
| 969 | (directory-file-name (car args)) 0))) | 959 | (setq only-one-filesystem nil)) |
| 970 | (setq args (cdr args))) | 960 | (let ((size 0.0)) |
| 971 | (if grand-total | 961 | (dolist (arg (or args '("."))) |
| 972 | (eshell-print (concat (eshell-du-size-string size) | 962 | (when only-one-filesystem |
| 973 | "total\n")))))))) | 963 | (setq only-one-filesystem |
| 964 | (file-attribute-device-number | ||
| 965 | (eshell-file-attributes (file-name-as-directory arg))))) | ||
| 966 | (setq size (+ size (eshell-du-sum-directory | ||
| 967 | (directory-file-name arg) 0)))) | ||
| 968 | (if grand-total | ||
| 969 | (eshell-print (concat (eshell-du-size-string size) | ||
| 970 | "total\n"))))))) | ||
| 974 | 971 | ||
| 975 | (put 'eshell/du 'eshell-filename-arguments t) | 972 | (put 'eshell/du 'eshell-filename-arguments t) |
| 976 | 973 | ||