mirror of
https://github.com/itchyny/mmv.git
synced 2026-01-08 23:30:16 +08:00
close temporary file before starting editor
This commit is contained in:
parent
5ee3f57dff
commit
226133344a
1 changed files with 12 additions and 11 deletions
|
|
@ -85,28 +85,30 @@ func rename(args []string) error {
|
|||
}
|
||||
xs[src] = true
|
||||
}
|
||||
|
||||
f, err := ioutil.TempFile("", name+"-")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
f.Close()
|
||||
os.Remove(f.Name())
|
||||
}()
|
||||
defer os.Remove(f.Name())
|
||||
for _, arg := range args {
|
||||
f.WriteString(arg)
|
||||
f.WriteString("\n")
|
||||
}
|
||||
editor := os.Getenv("EDITOR")
|
||||
if editor == "" {
|
||||
editor = "vi"
|
||||
if err = f.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tty, err := tty.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tty.Close()
|
||||
|
||||
editor := os.Getenv("EDITOR")
|
||||
if editor == "" {
|
||||
editor = "vi"
|
||||
}
|
||||
editorWithArgs := strings.Fields(editor)
|
||||
editorWithArgs = append(editorWithArgs, f.Name())
|
||||
|
||||
|
|
@ -114,12 +116,10 @@ func rename(args []string) error {
|
|||
cmd.Stdin = tty.Input()
|
||||
cmd.Stdout = tty.Output()
|
||||
cmd.Stderr = tty.Output()
|
||||
if err := cmd.Run(); err != nil {
|
||||
if err = cmd.Run(); err != nil {
|
||||
return fmt.Errorf("abort renames: %s", err)
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cnt, err := ioutil.ReadFile(f.Name())
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -132,5 +132,6 @@ func rename(args []string) error {
|
|||
for i, src := range args {
|
||||
files[src] = got[i]
|
||||
}
|
||||
|
||||
return mmv.Rename(files)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue