Opening different file types

85 views
Skip to first unread message

Tom

unread,
Aug 9, 2019, 10:15:41 PM8/9/19
to lf-fm
Hi,

Thanks for the awesome software. I'm currently using ranger and migrating to lf. I just have one question: is it possible to configure lf to open certain filetypes in vim, and then with others, default to mac os `open` option?

I have seen elsewhere that you recommended a command such as this: cmd open-file $rifle $f . Would you then define a rifle command within an lfrc file?

Other than this, lf is an amazing tool and I plan to use it daily.

Cheers,
Tom

Gokcehan Kara

unread,
Aug 12, 2019, 7:34:51 AM8/12/19
to Tom, lf-fm
Hi Tom,

We have changed the command name from `open-file` to `open` at some point. Other than that, that example should work as expected. We don't define a `rifle` command within a lfrc file. Instead `rifle` is the file opener provided by `ranger` so it should exist as an executable in your system if you have `ranger` installed. If you don't want to use `rifle`, you can define a custom command yourself. Please refer to "Opening Files" section in the documentation for more information.

Best,
Gokcehan

--
You received this message because you are subscribed to the Google Groups "lf-fm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lf-fm+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lf-fm/40461063-257d-4115-a607-0a869474d33a%40googlegroups.com.

Dave Mazzoni

unread,
May 2, 2021, 9:57:17 AM5/2/21
to LF file manager
I'm running lf on an Ubuntu 20.04 system. Something seems 'strange" when I try to edit or list a file. I always end up with what seems to be two commands (in a buffer?). So if I hit <enter> it calls vi. Great. But when I exit no matter what key I hit, it enters vi again. The same goes for exiting -- I always have to type q twice.

Any suggestions?

Gokcehan Kara

unread,
May 2, 2021, 10:59:43 AM5/2/21
to Dave Mazzoni, LF file manager
Dave,

That doesn't sound intentional. You need to provide more details about your setup. What command are you using for the `open` command? Also, what version are you using? We have been having some issues with terminal handling macos and bsd though I don't remember any problems on linux.

Gokcehan

You received this message because you are subscribed to the Google Groups "LF file manager" group.

To unsubscribe from this group and stop receiving emails from it, send an email to lf-fm+un...@googlegroups.com.

Gokcehan Kara

unread,
May 2, 2021, 1:55:12 PM5/2/21
to Dave Mazzoni, lf-fm
Dave,

You might want to use `$` command for `open` instead. I suspect what you're describing as hitting twice is the wait prompt after the command is finished. I don't think there is an issue here.

Gokcehan

On Sun, May 2, 2021 at 6:37 PM Dave Mazzoni <dav...@gmail.com> wrote:
More info:
  lf does work mostly as I would like with the lfrc I sent. 'open' does highlight a file and pipe to less. But I have to hit Ctrl-f twice to get open to work, then no matter what I type after 'returning' from highlight, it does the same thing again.

--

Facts are stubborn things.

John Adams

Gokcehan Kara

unread,
May 3, 2021, 8:35:05 AM5/3/21
to Dave Mazzoni, lf-fm
Dave,

There is an issue reported recently as https://github.com/gokcehan/lf/issues/616 which is similar to what you are describing as hitting twice. It is possible you are not building the program as a module. Feel free to follow that issue if that is the same issue you are experiencing.

Gokcehan

On Sun, May 2, 2021 at 10:13 PM Gokcehan Kara <gokceh...@gmail.com> wrote:
Dave,

I meant the command type `$` instead of `!`. I also think your open command is more appropriate as a pager command. You may want to get more familiar with the configuration before you make any changes. Feel free to have a look at the documentation and the wiki for more examples.

I can't reproduce the twice hit issue on my machine. A single <c-f> opens the file on my machine.

Gokcehan

On Sun, May 2, 2021 at 9:55 PM Dave Mazzoni <dav...@gmail.com> wrote:
I'm not sure what you were saying, did you mean it literally (open command would be $) or to use your example code:
# define a custom 'open' command
# This command is called when current file is not a directory. You may want to
# use either file extensions and/or mime types here. Below uses an editor for
# text files and a file opener for the rest.
cmd open ${{
    case $(file --mime-type $f -b) in
        text/*) $EDITOR $fx;;
        *) for f in $fx; do setsid $OPENER $f > /dev/null 2> /dev/null & done;;
    esac
}}

If I make the changes above (the #define a custom 'open' command...) and start up with vi exported as export EDITOR=/usr/bin/vi
there is always two command presses needed (Ctrl-f Ctrl-f) which does start vi on the file
But after exiting vi -- no matter what I type it goes BACK into the previous file used by vi above
puts me right back into a vi session (on the same file)
If I exit there, I can continue.

Gokcehan Kara

unread,
May 3, 2021, 1:16:16 PM5/3/21
to Dave Mazzoni, lf-fm
Dave,

You are not sending your mails to the list but only to me.

We have added that script to the repository since then using the name `lfcd` instead:


I'm glad to hear things worked out for you in the end.

Gokcehan

On Mon, May 3, 2021 at 7:31 PM Dave Mazzoni <dav...@gmail.com> wrote:
One other thing that is unrelated to the problem I had previously was a small script you sent many years ago that used 'lf' to change directory. So I added this to the end of my .bashrc:
lf () {
    tmp="$(mktemp)"
    command lf -last-dir-path="$tmp" "$@"
    if [ -f "$tmp" ]; then
        dir="$(cat "$tmp")"
        [ "$dir" != "$(pwd)" ] && cd "$dir"
    fi
    rm -f "$tmp"
}
which 'exits' lf in the directory that it is displaying.
I thought this might be of use to others.
Reply all
Reply to author
Forward
0 new messages