我刚在维基百科上看到了这个dired模式屏幕截图。 我正在研究这些自定义设置。
关于颜色,我想只需指定正确的面孔即可,但是如何使dired默认显示文件大小为kbytes?以及MBs中的可用空间(顶部行)?
我刚在维基百科上看到了这个dired模式屏幕截图。 我正在研究这些自定义设置。
关于颜色,我想只需指定正确的面孔即可,但是如何使dired默认显示文件大小为kbytes?以及MBs中的可用空间(顶部行)?
我遇到了同样的问题,并找到了如何在运行时更改开关的方法。
因此,在dired缓冲区中
C-u s
您现在可以更改ls使用的开关。添加h
可获取人类可读的文件大小
您还可以添加其他开关,例如我将其更改为-alsh
,它现在按文件大小排序
describe-key
在C-u处停止,因此它返回universal-argument
。 - nephewtomdired-sort-toggle-or-edit
命令。在dired缓冲区中按下C-x k
,然后再按s
。这样您确实会将通用参数u发送到dired-sort-toggle-or-edit
命令中。 - Aurélien Bottazinidired-listing-switches
并使用 -k
选项:(setq dired-listing-switches "-alk")
要获取MB中的总数/可用数量需要多做一些工作。这个方法在我的Linux系统上可行,但在我的Windows系统上获取可用数量失败了:
(setq directory-free-space-args "-Pm")
(defadvice insert-directory (after insert-directory-adjust-total-by-1024 activate)
"modify the total number by dividing it by 1024"
(save-excursion
(save-match-data
(goto-char (point-min))
(when (re-search-forward "^ *total used in directory \\([0-9]+\\) ")
(replace-match (number-to-string (/ (string-to-number (match-string 1)) 1024)) nil nil nil 1)))))
h
选项会生成易读的输出,而不是使用固定大小(如请求所示)。总的来说,我还是喜欢h
选项的。 - Trey JacksonM-x customize-group Dired-Plus
。虽然您没有问,但我想补充一下...
我希望能够轻松地按大小和扩展名、名称和时间对dired输出进行排序。我知道可以使用M-x universal-argument dired-sort-toggle-or-edit
来实现这一点,但是我希望将其放在s
键上以便快速使用。
;; Redefine the sorting in dired to flip between sorting on name, size,
;; time, and extension, rather than simply on name and time.
(defun dired-sort-toggle ()
;; Toggle between sort by date/name. Reverts the buffer.
(setq dired-actual-switches
(let (case-fold-search)
(cond
((string-match " " dired-actual-switches) ;; contains a space
;; New toggle scheme: add/remove a trailing " -t" " -S",
;; or " -U"
(cond
((string-match " -t\\'" dired-actual-switches)
(concat
(substring dired-actual-switches 0 (match-beginning 0))
" -X"))
((string-match " -X\\'" dired-actual-switches)
(concat
(substring dired-actual-switches 0 (match-beginning 0))
" -S"))
((string-match " -S\\'" dired-actual-switches)
(substring dired-actual-switches 0 (match-beginning 0)))
(t
(concat dired-actual-switches " -t"))))
(t
;; old toggle scheme: look for a sorting switch, one of [tUXS]
;; and switch between them. Assume there is only ONE present.
(let* ((old-sorting-switch
(if (string-match (concat "[t" dired-ls-sorting-switches "]")
dired-actual-switches)
(substring dired-actual-switches (match-beginning 0)
(match-end 0))
""))
(new-sorting-switch
(cond
((string= old-sorting-switch "t")
"X")
((string= old-sorting-switch "X")
"S")
((string= old-sorting-switch "S")
"")
(t
"t"))))
(concat
"-l"
;; strip -l and any sorting switches
(dired-replace-in-string (concat "[-lt"
dired-ls-sorting-switches "]")
""
dired-actual-switches)
new-sorting-switch))))))
(dired-sort-set-modeline)
(revert-buffer))
;; redefine this function, to fix the formatting of file sizes in dired mode
(defun ls-lisp-format-file-size (file-size human-readable)
(if (or (not human-readable)
(< file-size 1024))
(format (if (floatp file-size) " %11.0f" " %11d") file-size)
(do ((file-size (/ file-size 1024.0) (/ file-size 1024.0))
;; kilo, mega, giga, tera, peta, exa
(post-fixes (list "k" "M" "G" "T" "P" "E") (cdr post-fixes)))
((< file-size 1024) (format " %10.0f%s" file-size (car post-fixes))))))
它只是将格式字符串中的9.0替换为11.0,将8.0替换为10.0。