mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 06:37:14 +09:00
autocomplete plugin commands
This commit is contained in:
@@ -149,3 +149,29 @@ func PluginComplete(complete Completion, input string) (chosen string, suggestio
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PluginCmdComplete(input string) (chosen string, suggestions []string) {
|
||||||
|
for _, cmd := range []string{"install", "remove", "search", "update"} {
|
||||||
|
if strings.HasPrefix(cmd, input) {
|
||||||
|
suggestions = append(suggestions, cmd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(suggestions) == 1 {
|
||||||
|
chosen = suggestions[0]
|
||||||
|
}
|
||||||
|
return chosen, suggestions
|
||||||
|
}
|
||||||
|
|
||||||
|
func PluginNameComplete(input string) (chosen string, suggestions []string) {
|
||||||
|
for _, pp := range GetAllPluginPackages() {
|
||||||
|
if strings.HasPrefix(pp.Name, input) {
|
||||||
|
suggestions = append(suggestions, pp.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(suggestions) == 1 {
|
||||||
|
chosen = suggestions[0]
|
||||||
|
}
|
||||||
|
return chosen, suggestions
|
||||||
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ func DefaultCommands() map[string]StrCommand {
|
|||||||
"help": {"Help", []Completion{HelpCompletion, NoCompletion}},
|
"help": {"Help", []Completion{HelpCompletion, NoCompletion}},
|
||||||
"eval": {"Eval", []Completion{NoCompletion}},
|
"eval": {"Eval", []Completion{NoCompletion}},
|
||||||
"log": {"ToggleLog", []Completion{NoCompletion}},
|
"log": {"ToggleLog", []Completion{NoCompletion}},
|
||||||
"plugin": {"Plugin", []Completion{NoCompletion}},
|
"plugin": {"Plugin", []Completion{PluginCmdCompletion, PluginNameCompletion}},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ func PluginCmd(args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "update":
|
case "update":
|
||||||
UpdatePlugins()
|
UpdatePlugins(args[1:])
|
||||||
case "search":
|
case "search":
|
||||||
searchText := strings.Join(args[1:], " ")
|
searchText := strings.Join(args[1:], " ")
|
||||||
plugins := SearchPlugin(searchText)
|
plugins := SearchPlugin(searchText)
|
||||||
|
|||||||
@@ -192,6 +192,8 @@ const (
|
|||||||
CommandCompletion
|
CommandCompletion
|
||||||
HelpCompletion
|
HelpCompletion
|
||||||
OptionCompletion
|
OptionCompletion
|
||||||
|
PluginCmdCompletion
|
||||||
|
PluginNameCompletion
|
||||||
)
|
)
|
||||||
|
|
||||||
// Prompt sends the user a message and waits for a response to be typed in
|
// Prompt sends the user a message and waits for a response to be typed in
|
||||||
@@ -255,6 +257,10 @@ func (m *Messenger) Prompt(prompt, historyType string, completionTypes ...Comple
|
|||||||
chosen, suggestions = HelpComplete(currentArg)
|
chosen, suggestions = HelpComplete(currentArg)
|
||||||
} else if completionType == OptionCompletion {
|
} else if completionType == OptionCompletion {
|
||||||
chosen, suggestions = OptionComplete(currentArg)
|
chosen, suggestions = OptionComplete(currentArg)
|
||||||
|
} else if completionType == PluginCmdCompletion {
|
||||||
|
chosen, suggestions = PluginCmdComplete(currentArg)
|
||||||
|
} else if completionType == PluginNameCompletion {
|
||||||
|
chosen, suggestions = PluginNameComplete(currentArg)
|
||||||
} else if completionType < NoCompletion {
|
} else if completionType < NoCompletion {
|
||||||
chosen, suggestions = PluginComplete(completionType, currentArg)
|
chosen, suggestions = PluginComplete(completionType, currentArg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -501,14 +501,19 @@ func (pl PluginPackage) Install() {
|
|||||||
selected.install()
|
selected.install()
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdatePlugins() {
|
func UpdatePlugins(plugins []string) {
|
||||||
|
// if no plugins are specified, update all installed plugins.
|
||||||
|
if len(plugins) == 0 {
|
||||||
|
plugins = loadedPlugins
|
||||||
|
}
|
||||||
|
|
||||||
messenger.AddLog("Checking for plugin updates")
|
messenger.AddLog("Checking for plugin updates")
|
||||||
microVersion := PluginVersions{
|
microVersion := PluginVersions{
|
||||||
newStaticPluginVersion(CorePluginName, Version),
|
newStaticPluginVersion(CorePluginName, Version),
|
||||||
}
|
}
|
||||||
|
|
||||||
var updates = make(PluginDependencies, 0)
|
var updates = make(PluginDependencies, 0)
|
||||||
for _, name := range loadedPlugins {
|
for _, name := range plugins {
|
||||||
pv := GetInstalledPluginVersion(name)
|
pv := GetInstalledPluginVersion(name)
|
||||||
r, err := semver.ParseRange(">=" + pv) // Try to get newer versions.
|
r, err := semver.ParseRange(">=" + pv) // Try to get newer versions.
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user