X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=cmd%2Fmicro%2Fcommand.go;h=b36df74bd46cfcfc4b2a5f961778f62b9fd75fef;hb=3ecdd96931ac75039105b5a4ac2fdd3b5526dbf6;hp=3cb3ff7ac3b1a9c792daaff70543cc8f4ce9c4fd;hpb=1b9bb31dd64c80a7e132b72a3ef7d9870c6f0547;p=micro.git diff --git a/cmd/micro/command.go b/cmd/micro/command.go index 3cb3ff7a..b36df74b 100644 --- a/cmd/micro/command.go +++ b/cmd/micro/command.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "os/signal" + "path/filepath" "regexp" "strings" @@ -26,22 +27,29 @@ type StrCommand struct { var commands map[string]Command -var commandActions = map[string]func([]string){ - "Set": Set, - "SetLocal": SetLocal, - "Show": Show, - "Run": Run, - "Bind": Bind, - "Quit": Quit, - "Save": Save, - "Replace": Replace, - "VSplit": VSplit, - "HSplit": HSplit, - "Tab": NewTab, - "Help": Help, - "Eval": Eval, - "ToggleLog": ToggleLog, - "Plugin": PluginCmd, +var commandActions map[string]func([]string) + +func init() { + commandActions = map[string]func([]string){ + "Set": Set, + "SetLocal": SetLocal, + "Show": Show, + "Run": Run, + "Bind": Bind, + "Quit": Quit, + "Save": Save, + "Replace": Replace, + "VSplit": VSplit, + "HSplit": HSplit, + "Tab": NewTab, + "Help": Help, + "Eval": Eval, + "ToggleLog": ToggleLog, + "Plugin": PluginCmd, + "Reload": Reload, + "Cd": Cd, + "Pwd": Pwd, + } } // InitCommands initializes the default commands @@ -89,6 +97,9 @@ func DefaultCommands() map[string]StrCommand { "eval": {"Eval", []Completion{NoCompletion}}, "log": {"ToggleLog", []Completion{NoCompletion}}, "plugin": {"Plugin", []Completion{PluginCmdCompletion, PluginNameCompletion}}, + "reload": {"Reload", []Completion{NoCompletion}}, + "cd": {"Cd", []Completion{FileCompletion}}, + "pwd": {"Pwd", []Completion{NoCompletion}}, } } @@ -162,22 +173,66 @@ func PluginCmd(args []string) { ToggleLog([]string{}) } } + case "available": + packages := GetAllPluginPackages() + messenger.AddLog("Available Plugins:") + for _, pkg := range packages { + messenger.AddLog(pkg.Name) + } + if CurView().Type != vtLog { + ToggleLog([]string{}) + } } } else { messenger.Error("Not enough arguments") } } +func Cd(args []string) { + if len(args) > 0 { + home, _ := homedir.Dir() + path := strings.Replace(args[0], "~", home, 1) + os.Chdir(path) + for _, tab := range tabs { + for _, view := range tab.views { + wd, _ := os.Getwd() + view.Buf.Path, _ = MakeRelative(view.Buf.AbsPath, wd) + if p, _ := filepath.Abs(view.Buf.Path); !strings.Contains(p, wd) { + view.Buf.Path = view.Buf.AbsPath + } + } + } + } +} + +func Pwd(args []string) { + wd, err := os.Getwd() + if err != nil { + messenger.Message(err.Error()) + } else { + messenger.Message(wd) + } +} + func ToggleLog(args []string) { buffer := messenger.getBuffer() if CurView().Type != vtLog { CurView().HSplit(buffer) CurView().Type = vtLog + RedrawAll() + buffer.Cursor.Loc = buffer.Start() + CurView().Relocate() + buffer.Cursor.Loc = buffer.End() + CurView().Relocate() } else { CurView().Quit(true) } } +func Reload(args []string) { + LoadAll() +} + // Help tries to open the given help page in a horizontal split func Help(args []string) { if len(args) < 1 {