"os"
"os/exec"
"os/signal"
+ "path/filepath"
"regexp"
"strings"
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
"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}},
}
}
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 {
if matches != nil && len(matches) > 0 {
prevMatchCount := runePos(matches[0][0], bufStr)
searchCount := runePos(matches[0][1], bufStr) - prevMatchCount
- prevMatch := matches[0]
- from := FromCharPos(prevMatch[0], view.Buf)
+ from := FromCharPos(matches[0][0], view.Buf)
to := from.Move(searchCount, view.Buf)
adjust := Count(replace) - searchCount
view.Buf.Replace(from, to, replace)
from = from.Move(matchCount-prevMatchCount+adjust, view.Buf)
to = from.Move(searchCount, view.Buf)
view.Buf.Replace(from, to, replace)
- prevMatch = match
prevMatchCount = matchCount
adjust = Count(replace) - searchCount
}