Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editinacme: support editing multiple files #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions acme/editinacme/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
// Usage:
//
// editinacme <file>
// editinacme <file1> [<file2>...]
//
// Editinacme uses the plumber to ask acme to open the file,
// waits until the file's acme window is deleted, and exits.
Expand All @@ -27,41 +27,38 @@ func main() {
log.SetFlags(0)
log.SetPrefix("editinacme: ")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: editinacme file\n")
fmt.Fprintf(os.Stderr, "usage: editinacme file1 [file2]...\n")
os.Exit(2)
}
flag.Parse()
if flag.NArg() != 1 {
flag.Usage()
}

file := flag.Arg(0)

fullpath, err := filepath.Abs(file)
if err != nil {
log.Fatal(err)
}
file = fullpath

r, err := acme.Log()
if err != nil {
log.Fatal(err)
}
for _, file := range flag.Args() {
fullpath, err := filepath.Abs(file)
if err != nil {
log.Fatal(err)
}
file = fullpath

log.Printf("editing %s", file)
r, err := acme.Log()
if err != nil {
log.Fatal(err)
}

out, err := exec.Command("plumb", "-d", "edit", file).CombinedOutput()
if err != nil {
log.Fatalf("executing plumb: %v\n%s", err, out)
}
log.Printf("editing %s", file)

for {
ev, err := r.Read()
out, err := exec.Command("plumb", "-d", "edit", file).CombinedOutput()
if err != nil {
log.Fatalf("reading acme log: %v", err)
log.Fatalf("executing plumb: %v\n%s", err, out)
}
if ev.Op == "del" && ev.Name == file {
break

for {
ev, err := r.Read()
if err != nil {
log.Fatalf("reading acme log: %v", err)
}
if ev.Op == "del" && ev.Name == file {
break
}
}
}
}