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

[Feature Request] Turn the command bar into a "command palette" #2517

Open
zeevro opened this issue Aug 1, 2022 · 3 comments
Open

[Feature Request] Turn the command bar into a "command palette" #2517

zeevro opened this issue Aug 1, 2022 · 3 comments

Comments

@zeevro
Copy link

zeevro commented Aug 1, 2022

Have the command bar auto-complete or suggest commands like the VS Code command palette, and maybe also show bindings next to suggested commands.

@Gavin-Holt
Copy link

Hi

I love the fuzzyfind interface - you could shell out to select from a list of favourite commands. Windows implementation:

function io.exists(filename)
    if type(filename)~="string" then
	    return false
    end
    local fileinfo, err = osutil.Stat(filename)
    if osutil.IsNotExist(err) then
        return false
    else
        return true
    end
end

function cmdfzf(Current)
-- Select a command from a list
    -- Requires cat.exe and fzf.exe in your path
    -- (https://github.com/junegunn/fzf/releases)

    -- Locate completions - a list of your favourite commands (manual update)
    local target = config.ConfigDir..[[/commands.txt]]
    if not io.exists(target) then return end

    -- Run fzf (fails if history file does not exist)
    if not io.exists(config.ConfigDir.."/../history/cmd.fzf") then return end
    local sel, err = shell.RunInteractiveShell("cmd.exe /c cat.exe "..target.. " | fzf.exe --history='"..config.ConfigDir.."/../history/cmd.fzf' --prompt='> ' --color='dark' --tac", false, true)

    -- Check for selection
    if not sel or sel == ""  then return end

    -- Run the command
    Current:HandleCommand(sel)

end

I have not tried to automatically generate a list of all commands (would need to merge lists of colorschemes and plugins etc.)

Kind Regards Gavin Holt

NB This approach also works for other lists, and I have made several "fzf functions"

  • openfzf(Current)
  • snippetfzf(Current)
  • templatefzf(Current)
  • loadbackupfzf(Current)
  • switchbufferfzf(Current)
  • gobackfzf(Current)
  • gotofzf(Current)
  • findinfilefzf(Current)

@octoshrimpy
Copy link

@Gavin-Holt this looks like it would be a great plugin, and one I'd actively use. Something akin to fzf-speed in vim.

@Gavin-Holt
Copy link

Hi,

Happy to help if I can, but I am a very superficial user of git, I do not have it installed and have never made a PR. Also, the plugin repository does not seem to include scripts dependent upon third party utilities.

Personally I don't use plugins (other than those built-in) all my Lua code is in a single init.lua file in my micro config directory (settings.json contains "initlua": true,). The global functions defined in that file can be bound to keys or made into callable commands. Standing upon the shoulders of giants, I have added code from published plugins and from my experiments customizing SciTE.

If you place the code above in a file named init.lua, within your config directory, it will be loaded at startup. cmdfzf will fail if the command.txt or history/cmd.fzf files don't exist (please note my odd path to cmd.fzf - it's shared with other applications).

To bind this function include "F9": "lua:initlua.cmdfzf", or similar in your bindings.json.

The list of commands must be hand edited/maintained - my current copy attached below.

Kind Regards Gavin Holt

PS, I have attached all my current configuration files designed for Windows OS:

The key bindings are dependent upon Autohotkey to translate keypresses, so you will need to change for your own preferences.

The Lua script includes some Lua extensions, some general editor functions and then bindable functions. This does depend upon some third party Windows utilities. Afraid to say the init.lua file is best viewed in a folding editor (e.g. SciTE). Any help with my outstanding TODOs gratefully accepted.

NB renamed to allow upload

bindings.json.txt
settings.json.txt
init.lua.txt
commands.txt

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

No branches or pull requests

3 participants