diff options
| author | Eyal Posener <[email protected]> | 2017-05-13 00:17:48 +0300 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2017-05-13 00:17:59 +0300 |
| commit | f580110640e0213502e4fe1138a06f57b532ff7a (patch) | |
| tree | 7a0692e1baa4da0d252f5aa1b2bc7c4e2c1cbaef /args.go | |
| parent | 66402080675c250edabe50839555942d1b1aa189 (diff) | |
gocomplete: complete by packages
Diffstat (limited to 'args.go')
| -rw-r--r-- | args.go | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -1,5 +1,10 @@ package complete +import ( + "os" + "path/filepath" +) + // Args describes command line arguments type Args struct { // All lists of all arguments in command line (not including the command itself) @@ -18,6 +23,21 @@ type Args struct { LastCompleted string } +// Directory gives the directory of the current written +// last argument if it represents a file name being written. +// in case that it is not, we fall back to the current directory. +func (a Args) Directory() string { + if info, err := os.Stat(a.Last); err == nil && info.IsDir() { + return a.Last + } + dir := filepath.Dir(a.Last) + _, err := os.Stat(dir) + if err != nil { + return "./" + } + return dir +} + func newArgs(line []string) Args { completed := removeLast(line) return Args{ |
