Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export mode for use in scripting keybindings #1594

Merged
merged 3 commits into from
Feb 11, 2024
Merged

Export mode for use in scripting keybindings #1594

merged 3 commits into from
Feb 11, 2024

Conversation

joelim-work
Copy link
Collaborator

Related:

For certain keybindings, it can be useful to modify the behavior based on what mode lf is currently in. Right now there is no way to track the current mode except for using user-defined variables, which is more complex and error-prone.

Examples:

Using filter to select and open a file:

set incfilter

map f filter

cmap <enter> &{{
    # select and open file
    if [ "$lf_mode" = "filter" ]; then
        lf -remote "send $id :cmd-enter; setfilter; open"
    else
        lf -remote "send $id cmd-enter"
    fi
}}

cmap <a-n> &{{
    # go to next file
    if [ "$lf_mode" = "filter" ]; then
        lf -remote "send $id down"
    fi
}}

cmap <a-p> &{{
    # go to previous file
    if [ "$lf_mode" = "filter" ]; then
        lf -remote "send $id up"
    fi
}}

Expand partially-typed commands before executing them (e.g. type :del as a shorthand for :delete):

cmap <enter> &{{
    if [ "$lf_mode" = "command" ]; then
        lf -remote "send $id complete-cmd"
    else
        lf -remote "send $id cmd-enter"
    fi
}}

cmd complete-cmd :{{
    # position cursor at the end of the first word
    cmd-home
    cmd-word

    # perform tab completion before running the command
    cmd-complete
    cmd-enter
}}

@joelim-work joelim-work merged commit cf99626 into gokcehan:master Feb 11, 2024
4 checks passed
@joelim-work joelim-work deleted the mode branch February 11, 2024 23:28
@gokcehan gokcehan mentioned this pull request Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants