I want to write a function that will write the output of wc -l <file-name>
next to each file in dired mode.
I got to this point:
(defun my-dired-insert-add-wc (beg end)
(save-excursion
(goto-char beg)
(while (< (point) end)
(condition-case nil
(when (dired-move-to-filename)
(shell-command "wc -l *")) ;; <--- `shell-command` contains what I need
(error nil))
(forward-line 1))))
(advice-add 'dired-insert-set-properties
:after #'my-dired-insert-add-wc)
Now, running this outputs wc -l *
into another buffer. So I decided to read shell-command
to see how it works internally.
There are two things I dont understand:
What role does this program play in the
shell-command
function? I mean, I understand that it read from the mini-buffer, but where is that fed into? Like, it's not an argument to anything else. So how does the rest of the program uses it? It's right in the beginning of the function shell-command:(interactive (list (read-shell-command "Async shell command: " nil nil (let ((filename (cond (buffer-file-name) ((eq major-mode 'dired-mode) (dired-get-filename nil t))))) (and filename (file-relative-name filename)))) current-prefix-arg shell-command-default-error-buffer))
Where does the variable
command
gets it's value? It doesnt seems to be assigned to anywhere.(call-process shell-file-name nil (if error-file (list t error-file) t) nil shell-command-switch command)
So, to recapitaluete, I want to write the number of lines each file has in a dired buffer. I have written a small program that does something like what I want but the downside is that it outputs it into another buffer instead of the dired buffer. So I went to study the function shell-command
to learn more about how to achieve my goal. I now have two question about the function shell-command
.
Can someone please answer my two questions about the shell-command
?
interactive
. What am I missing? Should the title make clear that you are asking about this particularinteractive
form? Or are you in fact asking a question about the meaning ofinteractive
?interactive
works. The functionshell-command-to-string
is exactly what I needed. Thanks a lot everyone!!!