diff --git a/README.md b/README.md index 4feef5d2d..e8f62bc81 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,7 @@ This application still in experiment, any change could happen, but it doesn't af ### v0.3.* -- Command `search` add flag `-a` to show results of sub-packages, not just search by project name. - Command `install` and `remove` give number to let user choose operate one package. -- Command `search` add flags `-n` and `-o` for number of list items and offset. - Command `check` add feature to update or generate gopack.json. - Command `install` generates dependencies configuration file. - Command `install` save tarball add support for packages in code.google.com, bitbucket.org, launchpad.net, git.oschina.net, gitcafe.com, *.codeplex.com. @@ -48,7 +46,6 @@ This application still in experiment, any change could happen, but it doesn't af ### Future -- Command `search` show installed prompt. - Command `home` and `doc`. - Command `remove` add flag `-d` for removing dependencies at the same time. - Command `remove` add feature check for dependencies, make sure other packages don't import this one, and give choose for users. diff --git a/search.go b/search.go index 5001a9152..ed06c5ba7 100644 --- a/search.go +++ b/search.go @@ -52,19 +52,46 @@ func runSearch(cmd *Command, args []string) { resultStr := string(results) - if runtime.GOOS != "windows" { + isWindws := runtime.GOOS == "windows" + if !isWindws { // Set color highlight. - resultStr = strings.Replace(resultStr, args[0], fmt.Sprintf(utils.PureStartColor, utils.Yellow)+args[0]+utils.EndColor, -1) + resultStr = strings.Replace(resultStr, args[0], + fmt.Sprintf(utils.PureStartColor, utils.Yellow)+args[0]+utils.EndColor, -1) } + pkgsCache := make(map[string]string) + paths := utils.GetGOPATH() pkgs := strings.Split(resultStr, "|||") for _, p := range pkgs { i := strings.Index(p, "$") if i > -1 { - fmt.Println("-> " + p[:i]) // Package import path. - if len(p) > (i + 1) { - fmt.Println(" " + p[i+1:]) // Synopsis。 + // Do not display standard library. + if !utils.IsGoRepoPath(p[:i]) { + pkgsCache[utils.GetProjectPath(p[:i])] = p[i+1:] } } } + + for k, v := range pkgsCache { + fmt.Print("-> " + k) // Package import path. + // Check if has been installed. + for _, path := range paths { + if checkIsExistWithVCS(path + "/src/" + k + "/") { + installStr := " [Installed]" + if !isWindws { + installStr = strings.Replace(installStr, "[", + fmt.Sprintf("[\033[%dm", utils.Green), 1) + installStr = strings.Replace(installStr, "]", + utils.EndColor+"]", 1) + } + fmt.Print(installStr) + break + } + } + fmt.Print("\n") + + if len(v) > 0 { + fmt.Println(" " + v) // Synopsis。 + } + } }