gpt4 book ai didi

linux - 将 "ls"从 emacs dired 更改为其他应用程序

转载 作者:太空狗 更新时间:2023-10-29 12:07:17 26 4
gpt4 key购买 nike

我用 elisp 写了一些脚本,它合并了 ls -l 和 du(显示真实的文件夹大小,而不是 ls 中写的)。我将它命名为 lsd。这是屏幕截图:

http://i.imgur.com/PfSq6.png

现在我将列出实现。我不是一个好的编码员,所以我会很感激任何关于错误和可以做得更好的东西的信息。

lsd.el

#!/usr/bin/emacs --script
(progn
(setq argz command-line-args-left)
(setq folder "./")
(while argz
;; (message (car argz))
(if (/= ?- (aref (car argz) 0))
(setq folder (car argz)))
(setq argz (cdr argz)))
(if (/= ?/ (aref folder (1- (length folder)))) (setq folder (concat folder "/")))
(switch-to-buffer " *lsd*")
(erase-buffer)
(shell-command (concat "ls -l -h --color=always " " " (apply 'concat (mapcar '(lambda(arg) (concat arg " ")) command-line-args-left))) (current-buffer))
(switch-to-buffer " *du*")
(erase-buffer)
(shell-command (concat "du -h -d 1 " folder) (current-buffer))
(goto-char 1)
(while (search-forward "Permission denied" (point-max) t nil)
(goto-char (point-at-bol))
(let ((beg (point)))
(forward-line)
(delete-region beg (point)))) ; Remove all permission denied lines, thus show only permitted size.
(goto-char 1)
(while (and (search-forward folder (point-max) t nil) (/= (point-max) (1+ (point-at-eol)))) ; we do not need last line(the folder itself), so this line is something complex.
(setq DIR (buffer-substring (point) (point-at-eol)))
(goto-char (point-at-bol))
(setq SIZE (buffer-substring (point) (1- (search-forward " " (point-at-eol) nil nil))))
(goto-char (point-at-eol))
(switch-to-buffer " *lsd*")
(goto-char 1)
(if (search-forward DIR (point-max) t nil)
(progn
(goto-char (point-at-bol))
(search-forward-regexp "[0-9]+" (point-at-eol) nil nil)
(search-forward-regexp " *[0-9]+[^ \n]*[ \n]*" (point-at-eol) nil nil)
;; If ls have options, that makes some numbers before size column - we are doomed. (-s, for example)
(setq SIZE (concat SIZE " "))
(while (< (length SIZE) (length (match-string 0))) (setq SIZE (concat " " SIZE)))
(replace-match SIZE)))
(switch-to-buffer " *du*"))
(switch-to-buffer " *lsd*")
(message "%s" (buffer-substring (point-min) (point-max)))
(defun error(&rest args) args)
(defun message(&rest args) args)) ; Do not show any messages.

极光(我制作了这个脚本来启动 emacs,除了脚本之外没有加载任何东西。如果可以更容易地完成,请指出这一点)

#/bin/bash
emacs -Q --script /usr/local/bin/lsd.el $@

问题来了:如何在 dired 中使用这个 lsd?

我可以更改 dired 中的某些内容以使用 lsd 而不是 ls 吗?

我能否在 oldls 中重命名 ls,并制作一些 ls bash 脚本,如果没有 --lsd 标志,则将所有参数传递给 ls,如果这里有 --lsd,则将所有参数传递给 lsd?

这是个好主意吗?

最佳答案

在 Emacs24 中还有 `insert-directory-program'设置 ls 可执行文件。放

(setq insert-directory-program "/usr/local/bin/lsd")

(相应地调整路径)在您的 .emacs 或 init.el 和 dired 中获取您的 lsd 脚本。

关于linux - 将 "ls"从 emacs dired 更改为其他应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6524521/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com