Skip to content

Commit

Permalink
Add -x flag, which invokes xdg-open on the decrypted file
Browse files Browse the repository at this point in the history
  • Loading branch information
nadiamoe committed Sep 17, 2019
1 parent 480c90e commit c42b950
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import (
"github.com/pkg/errors"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"roob.re/omemo-wget/aesgcm"
"strings"
)

func main() {
outfile := flag.String("o", "", "out file. Use '-' for stdout. Defaults to guess from input uri/path")
xdgopen := flag.Bool("x", false, "Open resulting file with xdg-open")
flag.Parse()

if flag.NArg() < 1 {
Expand Down Expand Up @@ -58,6 +61,7 @@ func main() {
switch *outfile {
case "-":
out = os.Stdout
*xdgopen = false
case "":
// Generate a suitable name
basename := filepath.Base(path)
Expand All @@ -83,6 +87,16 @@ func main() {
return
}
_ = out.Close()

if *xdgopen {
cmd := exec.Command("xdg-open", *outfile)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
err := cmd.Run()
if err != nil {
log.Println(err)
}
}
}

func open(uri string) (io.ReadCloser, error) {
Expand Down

0 comments on commit c42b950

Please sign in to comment.