First drop the format
and concat
, they don't do anything here.
(format "%s" (shell-command-to-string (concat "ls -1 %f")))
is essentially the same as
(shell-command-to-string "ls -1 %f")
%f
and other %-constructs are only meaningful at the time they are used to actually generate the frame title from the value of frame-title-format
. But you are using %f
at the time the value of that variable is set.
Just because you set the value of frame-title-format
to the value returned by (shell-command-to-string "ls -1 %f")
doesn't magically assign any special meaning to %f
. So essentially you do this:
$ ls -1 %f
ls: cannot access %f: No such file or directory
You are calling shell-command-to-string
once, when you set the value of frame-title-format
. But what you want to do is to add an element which causes shell-command-to-string
to be called every time the value of frame-title-format
is used, e.g.:
(setq frame-title-format
'((:eval (shell-command-to-string "echo -n 'hello frame'"))))
Moving on to the next issue.
As we have seen above you cannot use %f
because it has no meaning to ls
. But this isn't quite right either:
(setq frame-title-format
'((:eval (shell-command-to-string
(format "ls -1 '%s'" buffer-file-name)))))
because only buffers that visit a file have a non-nil buffer-file-name
. So you would have to use something else for other buffers:
(setq frame-title-format
'((:eval (if buffer-file-name
(shell-command-to-string
(format "ls -1 '%s'" buffer-file-name))
"something else"))))