0

In the terminal, I can do:

$ readlink -f docker-compose.yml

Which outputs:

/home/pedro/projects/docker-stuff/docker-compose.yml

I would like to have something like that in Emacs so that I can find the file (a similar interface to the great C-x C-f) and then the full file location goes to the clipboard or kill ring. Or the full path is echoed in the mini buffer. Later, it would be possible to find it on messages.

Is there a way to do it?

Obs.: My first instinct was trying to use C-x C-f which is bounded to counsel-find-file in config file. After I find the file and before pressing return, I cannot move the cursor to select the whole file path and copy it. For some reason, it is blocked. See the image below - I can only move the cursor to the white characters:

enter image description here

2 Answers 2

1

expand-file-name do the similar things like readlink -f.

If you want to copy file path with a similar interface like find-file, here are two options to achieve it:

  1. use expand-file-name to write your copy path function and add it to counsel-find-file actions and call it through M-o when you select the file. For more details, see ivy actions
  2. use embark and run embark-action w.
4
  • Is this an Emacs command? I can't find it with M-x expand-file-name. Or, is this an Elisp function? Jun 3 at 12:30
  • If it is an Elisp thing, how do you use it to achieve my desire? I tried using eval-expression, opening the parens (expand-file-name ....) . But, it did not work out. Jun 3 at 12:30
  • Ok, I did it in the eshell. But, it was painful. There was no auto-complete to find the file. There must be a better way! Take in notice that I am not even using vanilla Emacs eshell. Jun 3 at 12:33
  • 1
    Hi, I have updated my answer. Jun 4 at 4:45
1

I think you're looking for file-truename which also does an expand in default-directory unless the input filename is absolute.

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.