本文整理匯總了Golang中github.com/gsamokovarov/jump/config.Config.WriteSearch方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.WriteSearch方法的具體用法?Golang Config.WriteSearch怎麽用?Golang Config.WriteSearch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gsamokovarov/jump/config.Config
的用法示例。
在下文中一共展示了Config.WriteSearch方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: cdCmd
func cdCmd(args cli.Args, conf *config.Config) {
term := args.CommandName()
entries, err := conf.ReadEntries()
if err != nil {
cli.Exitf(1, "%s\n", err)
}
// If an auto-completion triggered a full path, just go there.
if filepath.IsAbs(term) {
cli.Outf("%s\n", term)
return
}
index, search := 0, conf.ReadSearch()
// If we happen to match the last term, e.g. j is called with no
// arguments then jump to the previous search.
if len(term) == 0 {
term, index = search.Term, search.Index+1
}
fuzzyEntries := scoring.NewFuzzyEntries(entries, term)
for {
if entry, empty := fuzzyEntries.Select(index); !empty {
// Remove the entries that no longer exists.
if _, err := os.Stat(entry.Path); os.IsNotExist(err) {
entries.Remove(entry.Path)
conf.WriteEntries(entries)
index++
continue
}
// Jump to the next entry, if the jump is going to land on the
// current directory.
if cwd, err := os.Getwd(); err == nil && entry.Path == cwd {
index++
continue
}
cli.Outf("%s\n", entry.Path)
conf.WriteSearch(term, index)
}
break
}
}