1 4f7fe71a 2020-08-02 op // acmetag is a tool to programmatically interact with acme(1) tag
2 4f7fe71a 2020-08-02 op // bar. It provides two flag:
4 4f7fe71a 2020-08-02 op // * -g prints the tag content (mnemonic: get)
5 4f7fe71a 2020-08-02 op // * -c clears the tag content (mnemonic: clear)
7 4f7fe71a 2020-08-02 op // Any other argument (if passed) will be appended to the tag bar.
9 4f7fe71a 2020-08-02 op // Of course, you can combine the flags:
11 4f7fe71a 2020-08-02 op // acmetag -g -c fmt
14 b4e3e59c 2020-08-02 op // BUG(op) it cannot change the text before the | character.
23 14b3f96d 2019-10-26 op "9fans.net/go/acme"
27 14b3f96d 2019-10-26 op cl = flag.Bool("c", false, `Clear the tag`)
28 6c2d529b 2019-10-26 op gt = flag.Bool("g", false, `Get the content of the tag`)
31 14b3f96d 2019-10-26 op func open() (*acme.Win, error) {
32 14b3f96d 2019-10-26 op winid := os.Getenv("winid")
33 14b3f96d 2019-10-26 op id, err := strconv.Atoi(winid)
34 14b3f96d 2019-10-26 op if err != nil {
35 14b3f96d 2019-10-26 op return nil, err
37 14b3f96d 2019-10-26 op win, err := acme.Open(id, nil)
38 14b3f96d 2019-10-26 op return win, err
41 14b3f96d 2019-10-26 op func usage() {
42 14b3f96d 2019-10-26 op me := os.Args[0]
43 14b3f96d 2019-10-26 op fmt.Println(me, "- manage acme(1) tag")
44 8e6a76fc 2020-06-10 op fmt.Println("Usage:", me, " [-cg] [entries...]")
45 8e6a76fc 2020-06-10 op fmt.Println(" where entries are words to be added to the acme tag bar")
46 14b3f96d 2019-10-26 op flag.PrintDefaults()
51 14b3f96d 2019-10-26 op flag.Usage = usage
54 14b3f96d 2019-10-26 op win, err := open()
55 14b3f96d 2019-10-26 op if err != nil {
58 14b3f96d 2019-10-26 op defer win.CloseFiles()
61 6c2d529b 2019-10-26 op tag, err := win.ReadAll("tag")
62 6c2d529b 2019-10-26 op if err != nil {
63 6c2d529b 2019-10-26 op log.Fatalln(err)
65 6c2d529b 2019-10-26 op fmt.Println(string(tag))
69 14b3f96d 2019-10-26 op win.Ctl("cleartag")
73 14b3f96d 2019-10-26 op for _, arg := range flag.Args() {
74 14b3f96d 2019-10-26 op _, err = win.Write("tag", []byte(sep+arg))