aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/posener/complete/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/posener/complete/utils.go')
-rw-r--r--vendor/github.com/posener/complete/utils.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/github.com/posener/complete/utils.go b/vendor/github.com/posener/complete/utils.go
new file mode 100644
index 0000000..58b8b79
--- /dev/null
+++ b/vendor/github.com/posener/complete/utils.go
@@ -0,0 +1,46 @@
1package complete
2
3import (
4 "os"
5 "path/filepath"
6 "strings"
7)
8
9// fixPathForm changes a file name to a relative name
10func fixPathForm(last string, file string) string {
11 // get wording directory for relative name
12 workDir, err := os.Getwd()
13 if err != nil {
14 return file
15 }
16
17 abs, err := filepath.Abs(file)
18 if err != nil {
19 return file
20 }
21
22 // if last is absolute, return path as absolute
23 if filepath.IsAbs(last) {
24 return fixDirPath(abs)
25 }
26
27 rel, err := filepath.Rel(workDir, abs)
28 if err != nil {
29 return file
30 }
31
32 // fix ./ prefix of path
33 if rel != "." && strings.HasPrefix(last, ".") {
34 rel = "./" + rel
35 }
36
37 return fixDirPath(rel)
38}
39
40func fixDirPath(path string) string {
41 info, err := os.Stat(path)
42 if err == nil && info.IsDir() && !strings.HasSuffix(path, "/") {
43 path += "/"
44 }
45 return path
46}