mirror of
https://github.com/makew0rld/amfora.git
synced 2024-12-04 14:46:29 -05:00
Allow opening local files by relative path (#257)
This commit is contained in:
parent
eb314f2a4d
commit
9c217df9a8
20
amfora.go
20
amfora.go
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/makeworld-the-better-one/amfora/bookmarks"
|
"github.com/makeworld-the-better-one/amfora/bookmarks"
|
||||||
@ -74,8 +75,25 @@ func main() {
|
|||||||
// Initialize Amfora's settings
|
// Initialize Amfora's settings
|
||||||
display.Init(version, commit, builtBy)
|
display.Init(version, commit, builtBy)
|
||||||
display.NewTab()
|
display.NewTab()
|
||||||
|
|
||||||
|
// Load a URL, file, or render from stdin
|
||||||
if len(os.Args[1:]) > 0 {
|
if len(os.Args[1:]) > 0 {
|
||||||
display.URL(os.Args[1])
|
url := os.Args[1]
|
||||||
|
if !strings.Contains(url, "://") || strings.HasPrefix(url, "../") || strings.HasPrefix(url, "./") {
|
||||||
|
fileName := url
|
||||||
|
if _, err := os.Stat(fileName); err == nil {
|
||||||
|
if !strings.HasPrefix(fileName, "/") {
|
||||||
|
cwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "error getting working directory path: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fileName = filepath.Join(cwd, fileName)
|
||||||
|
}
|
||||||
|
url = "file://" + fileName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display.URL(url)
|
||||||
} else if !isStdinEmpty() {
|
} else if !isStdinEmpty() {
|
||||||
renderFromStdin()
|
renderFromStdin()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user