summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-02-24 17:11:48 +0800
committerJSDurand <mmemmew@gmail.com>2023-02-24 17:11:48 +0800
commitc08a289e59f27efb00c91c0276876a64925b9308 (patch)
tree9ca4a561935601e5e840ff7d0e173fb30a5c4336
parentb4ca140005dec52532e5b93a59ceef08d63abfe8 (diff)
eshell: group directories first in ls
* eshell-conf.el: Add an advice to `eshell-ls-sort-entries` so that directories always come before non-directories.
-rw-r--r--eshell-conf.el20
1 files changed, 20 insertions, 0 deletions
diff --git a/eshell-conf.el b/eshell-conf.el
index 1d0871f..866d4bf 100644
--- a/eshell-conf.el
+++ b/eshell-conf.el
@@ -377,6 +377,26 @@ candidates."
If called without ARGS, then use ./ instead."
(eshell/ls "-hal" (or args "./")))
+;;; Group directories first in `eshell/ls'
+
+(defun durand-eshell-group-entries-by-directory (entries)
+ "Sort ENTRIES so that directories come before non-directories."
+ (sort entries
+ (lambda (l r)
+ (cond
+ ((string= (car l) "."))
+ ((string= (car r) ".") nil)
+ ((string= (car l) ".."))
+ ((string= (car r) "..") nil)
+ ((and (file-directory-p (car l))
+ (file-directory-p (car r)))
+ (string-lessp (car l) (car r)))
+ ((file-directory-p (car l)))
+ ((file-directory-p (car r)) nil)))))
+
+(advice-add #'eshell-ls-sort-entries
+ :after #'durand-eshell-group-entries-by-directory)
+
;;; Integration with Tramp
(add-to-list 'eshell-modules-list 'eshell-tramp)