micro icon indicating copy to clipboard operation
micro copied to clipboard

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

Open zeevro opened this issue 2 years ago • 1 comments

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

zeevro avatar Aug 01 '22 07:08 zeevro

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)

Gavin-Holt avatar Aug 09 '22 14:08 Gavin-Holt

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

octoshrimpy avatar Oct 26 '22 17:10 octoshrimpy

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

Gavin-Holt avatar Oct 29 '22 14:10 Gavin-Holt