diff --git a/pkg/cmd/gist/view/view.go b/pkg/cmd/gist/view/view.go index 31b48325f..4f95af803 100644 --- a/pkg/cmd/gist/view/view.go +++ b/pkg/cmd/gist/view/view.go @@ -89,6 +89,11 @@ func viewRun(opts *ViewOptions) error { return err } + cs := opts.IO.ColorScheme() + if gist.Description != "" && opts.Filename == "" { + fmt.Fprintf(opts.IO.Out, "%s\n", cs.Bold(gist.Description)) + } + if opts.Filename != "" { gistFile, ok := gist.Files[opts.Filename] if !ok { @@ -102,11 +107,6 @@ func viewRun(opts *ViewOptions) error { showFilenames := len(gist.Files) > 1 - cs := opts.IO.ColorScheme() - if gist.Description != "" && showFilenames { - fmt.Fprintf(opts.IO.Out, "%s\n", cs.Bold(gist.Description)) - } - outs := []string{} // to ensure consistent ordering for filename, gistFile := range gist.Files { @@ -122,7 +122,10 @@ func viewRun(opts *ViewOptions) error { content = rendered } } - out += fmt.Sprintf("%s\n\n", content) + out += fmt.Sprintf("%s", content) + if opts.Filename == "" { + out += fmt.Sprintf("\n\n") + } outs = append(outs, out) } diff --git a/pkg/cmd/gist/view/view_test.go b/pkg/cmd/gist/view/view_test.go index 832a9ae01..4ecd86538 100644 --- a/pkg/cmd/gist/view/view_test.go +++ b/pkg/cmd/gist/view/view_test.go @@ -129,7 +129,7 @@ func Test_viewRun(t *testing.T) { }, }, }, - wantOut: "bwhiizzzbwhuiiizzzz\n\n", + wantOut: "bwhiizzzbwhuiiizzzz", }, { name: "filename selected, raw", @@ -150,7 +150,7 @@ func Test_viewRun(t *testing.T) { }, }, }, - wantOut: "bwhiizzzbwhuiiizzzz\n\n", + wantOut: "bwhiizzzbwhuiiizzzz", }, { name: "multiple files, no description",