+// TabSwitch switches to a given tab either by name or by number
+func TabSwitch(args []string) {
+ if len(args) > 0 {
+ num, err := strconv.Atoi(args[0])
+ if err != nil {
+ // Check for tab with this name
+
+ found := false
+ for _, t := range tabs {
+ v := t.views[t.CurView]
+ if v.Buf.GetName() == args[0] {
+ curTab = v.TabNum
+ found = true
+ }
+ }
+ if !found {
+ messenger.Error("Could not find tab: ", err)
+ }
+ } else {
+ num--
+ if num >= 0 && num < len(tabs) {
+ curTab = num
+ } else {
+ messenger.Error("Invalid tab index")
+ }
+ }
+ }
+}
+
+// Cd changes the current working directory
+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
+ }
+ }
+ }
+ }
+}
+
+// MemUsage prints micro's memory usage
+// Alloc shows how many bytes are currently in use
+// Sys shows how many bytes have been requested from the operating system
+// NumGC shows how many times the GC has been run
+// Note that Go commonly reserves more memory from the OS than is currently in-use/required
+// Additionally, even if Go returns memory to the OS, the OS does not always claim it because
+// there may be plenty of memory to spare
+func MemUsage(args []string) {
+ var mem runtime.MemStats
+ runtime.ReadMemStats(&mem)
+
+ messenger.Message(fmt.Sprintf("Alloc: %v, Sys: %v, NumGC: %v", humanize.Bytes(mem.Alloc), humanize.Bytes(mem.Sys), mem.NumGC))
+}
+
+// Pwd prints the current working directory
+func Pwd(args []string) {
+ wd, err := os.Getwd()
+ if err != nil {
+ messenger.Message(err.Error())
+ } else {
+ messenger.Message(wd)
+ }
+}
+
+// Open opens a new buffer with a given filename
+func Open(args []string) {
+ if len(args) > 0 {
+ filename := args[0]
+ // the filename might or might not be quoted, so unquote first then join the strings.
+ filename = strings.Join(SplitCommandArgs(filename), " ")
+
+ CurView().Open(filename)
+ } else {
+ messenger.Error("No filename")
+ }
+}
+
+// ToggleLog toggles the log view
+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)
+ }
+}
+
+// Reload reloads all files (syntax files, colorschemes...)
+func Reload(args []string) {
+ LoadAll()
+}
+