mistakenelf / fm

A terminal based file manager
MIT License
565 stars 29 forks source link

[Feature Request] Add Ability to Write File Path Instead of Open File #58

Closed is0n closed 2 years ago

is0n commented 2 years ago

Lf for example has this feature that instead of opening files, it writes the path of the selected file onto a specified file.

For example, when using this Lf, if lf -selection-path /tmp/tempfile is used, then instead of doing something like...

$ $EDITOR /path/to/file

when opening a file, it writes the file's path to the file specified after -selection-path...

$ echo "/path/to/file" > /tmp/tempfile
$ cat /tmp/tempfile
/path/to/file

This is an excerpt from the lf --help...

-selection-path string path to the file to write selected files on open (to use as open file dialog)

I request this feature as I really like your file manager and would like to use it with my neovim plugin called fm-nvim.

mistakenelf commented 2 years ago

Just to make sure i'm understanding, so what you would like to see is if I were in FM's directory tree, press lets say W for example purposes, it would write whatever file is selected's path to a file that you could then type in? So that file you write to would contain whatever content it had along with the string of where the selected files path is?

is0n commented 2 years ago

Kind of...

mistakenelf commented 2 years ago

Sorry I dont think im following yet. So I would launch fm with fm -selection-path /tmp/tempfile what file would I assume is being opened to write its path to tempfile?

is0n commented 2 years ago

If fm is called with -selection-path followed by a path to a file (the file doesn’t have to exist), then whenever the user opens a file with E instead of doing something like…

$ $EDITOR /path/to/opened/file

it writes /path/to/opened/file to the file specified in the command.

mistakenelf commented 2 years ago

Ok I think I am getting it now. So if I open FM fm with -selection-path then instead of opening the file with E it will write that selection-path to the file that is currently selected. So for example I have a file called test.txt currently highlighted in the tree, if I press E, it wont open in the $EDITOR, it will write /path/to/some/file to it?

is0n commented 2 years ago

Seems good!

mistakenelf commented 2 years ago

Cool, that seems doable, will take a swing at it

mistakenelf commented 2 years ago

@is0n take a look at #59 and let me know if that's what your looking for

is0n commented 2 years ago

Just compiled fm with the new updates and I have found that when opening a file with E, the opened file gets overwritten with the file path specified in fm --selection-path.

https://user-images.githubusercontent.com/57725322/139540619-99ed15bd-3d7d-4ead-a0cf-7c10fe985e72.mov

As mentioned before, the path of the opened file (in the case of the video, those files would be LICENSE or Makefile) would be written to the file specified in the command (in the case of the video, that would be /tmp/tempfile). What happened instead was that /tmp/tempfile replaced the contents of the opened files.

I would also like to mention that fm should close once it opens a file when --selection-path is used.

mistakenelf commented 2 years ago

So your saying that the selection-path file should be created, and then the path of the selected file would be written to that newly created file, in your case, /tmp/tempfile would be created, and the paths would get appended to that file any time you press E and then each time you press E, it writes the path and then exits?

is0n commented 2 years ago

So your saying that the selection-path file should be created

The file should only be created after the file is opened, not before so that if no file is opened, there isn't an empty file lying around.

the paths would get appended to that file any time you press E and then each time you press E, it writes the path and then exits?

The path to the opened file would replace the contents of /tmp/tempfile once E is used and after that happens, fm would close.

mistakenelf commented 2 years ago

Ok I think I get it now, I’ll take another swing at it

mistakenelf commented 2 years ago

@is0n if you want to give that branch another go I updated it with what I believe to be the correct logic

is0n commented 2 years ago

It works perfectly! I've just updated the plugin to use your file manager.

mistakenelf commented 2 years ago

Awesome! Will cut a release