| 207 | } |
| 208 | |
| 209 | func completeWithTilde(prefix string) []flags.Completion { |
| 210 | var homeDir string |
| 211 | if strings.HasPrefix(prefix, fmt.Sprintf("~%c", os.PathSeparator)) { |
| 212 | // when $HOME is empty this will complete on /, however this is not tested |
| 213 | homeDir = os.Getenv("HOME") |
| 214 | prefix = fmt.Sprintf("%s%s", homeDir, prefix[1:]) |
| 215 | } |
| 216 | |
| 217 | return findMatches( |
| 218 | fmt.Sprintf("%s*", prefix), |
| 219 | func(path string) string { |
| 220 | if homeDir != "" { |
| 221 | newPath, err := filepath.Rel(homeDir, path) |
| 222 | if err == nil { |
| 223 | path = filepath.Join("~", newPath) |
| 224 | } |
| 225 | } |
| 226 | return path |
| 227 | }) |
| 228 | } |
| 229 | |
| 230 | func checkIfFileExists(path string) (os.FileInfo, error) { |
| 231 | fileInfo, err := os.Stat(path) |