"errors"
"fmt"
"os"
+ "os/exec"
"path/filepath"
"regexp"
"strconv"
"memusage": Command{(*BufPane).MemUsageCmd, nil},
"retab": Command{(*BufPane).RetabCmd, nil},
"raw": Command{(*BufPane).RawCmd, nil},
+ "textfilter": Command{(*BufPane).TextFilterCmd, nil},
}
}
Tabs.SetActive(len(Tabs.List) - 1)
}
+// TextFilterCmd filters the selection through the command.
+// Selection goes to the command input.
+// On successfull run command output replaces the current selection.
+func (h *BufPane) TextFilterCmd(args []string) {
+ if len(args) == 0 {
+ InfoBar.Error("usage: textfilter arguments")
+ return
+ }
+ sel := h.Cursor.GetSelection()
+ if len(sel) == 0 {
+ h.Cursor.SelectWord()
+ sel = h.Cursor.GetSelection()
+ }
+ var bout, berr bytes.Buffer
+ cmd := exec.Command(args[0], args[1:]...)
+ cmd.Stdin = strings.NewReader(string(sel))
+ cmd.Stderr = &berr
+ cmd.Stdout = &bout
+ err := cmd.Run()
+ if err != nil {
+ InfoBar.Error(err.Error() + " " + berr.String())
+ return
+ }
+ h.Cursor.DeleteSelection()
+ h.Buf.Insert(h.Cursor.Loc, bout.String())
+}
+
// TabSwitchCmd switches to a given tab either by name or by number
func (h *BufPane) TabSwitchCmd(args []string) {
if len(args) > 0 {