From e06f788658ddbd71e389b178876509738c6f155e Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sat, 26 Nov 2022 12:06:01 +0000 Subject: [PATCH] Fix the tailing newline issue --- .gitignore | 2 +- open.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index bcf89fe..1851203 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,4 @@ # Go workspace file go.work -filter \ No newline at end of file +open \ No newline at end of file diff --git a/open.go b/open.go index aae4974..4bf4660 100644 --- a/open.go +++ b/open.go @@ -26,7 +26,7 @@ func main() { if err != nil { log.Fatalf("%v", err) } - dirpath := home + "/.open/" + dirpath := home + "/.config/open/" os.MkdirAll(dirpath, 0775) opener_file := dirpath + mtype.Extension() @@ -35,7 +35,7 @@ func main() { if err != nil { log.Fatalf("%v", err) } - prog = string(content) + prog = strings.TrimSuffix(string(content), "\n") } else { fmt.Printf("Don't know how to open '%s' file. What program should I use? ", mtype.Extension()) reader := bufio.NewReader(os.Stdin) @@ -54,6 +54,9 @@ func main() { } command := strings.Split(prog, " ") + command = append(command, file) + + fmt.Printf("Running command: '%s'\n", command) out, err := exec.Command(command[0], command[1:]...).Output() if err != nil { log.Fatal(err)