From c08a289e59f27efb00c91c0276876a64925b9308 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Fri, 24 Feb 2023 17:11:48 +0800 Subject: 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. --- eshell-conf.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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) -- cgit v1.2.3-18-g5258