1

I try to do a shell command in frame-title-format.

(setq frame-title-format
      (list (format "%s" (shell-command-to-string (concat "ls -1 %f")))))

ls: cannot access filename: No such file or directory

is shown up on the frame-title.

Is it due to the white space? How can I fix this?

-Ben

2

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"))))
-1

The problem is that %f is ambigous You can try this:

(setq frame-title-format (format "%s" (shell-command-to-string(concat "ls -l " (buffer-file-name)))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.