Exemplo n.º 1
0
func updateCmd(args cli.Args, conf *config.Config) {
	dir, err := os.Getwd()
	if len(args) == 0 && err != nil {
		cli.Exitf(1, "err: %s\n", err)
	} else {
		if dir, err = filepath.Abs(args.CommandName()); err != nil {
			cli.Exitf(1, "err: %s\n", err)
		}
	}

	entries, err := conf.ReadEntries()
	if err != nil {
		cli.Exitf(1, "err: %s\n", err)
	}

	if entry, found := entries.Find(dir); found {
		entry.UpdateScore()
	} else {
		entries = append(entries, *scoring.NewEntry(dir))
	}

	if err := conf.WriteEntries(entries); err != nil {
		cli.Exitf(1, "err: %s\n", err)
	}
}
Exemplo n.º 2
0
func main() {
	args := cli.ParseArgs(os.Args)

	config, err := config.SetupDefault(os.Getenv("JUMP_HOME"))
	if err != nil {
		cli.Exitf(1, "bug: %s", err.Error())
	}

	command, err := cli.DispatchCommand(args, "--help")
	if err != nil {
		cli.Exitf(1, "bug: %s", err.Error())
	}

	command.Action(args.Rest(), config)
}
Exemplo n.º 3
0
Arquivo: hint.go Projeto: NJichev/jump
func hintCmd(args cli.Args, conf *config.Config) {
	var hints scoring.Entries

	term := args.CommandName()
	smart := args.Has("--smart")

	entries, err := conf.ReadEntries()
	if err != nil {
		cli.Exitf(1, "%s\n", err)
	}

	if len(term) == 0 {
		// We usually keep them reversely sort to optimize the fuzzy search.
		sort.Sort(sort.Reverse(entries))

		hints = hintSmartSelect(entries, term, smart)
	} else {
		fuzzyEntries := scoring.NewFuzzyEntries(entries, term)

		hints = hintSmartSelect(&fuzzyEntries.Entries, term, smart)
	}

	for _, entry := range hints {
		cli.Outf("%s\n", entry.Path)
	}
}
Exemplo n.º 4
0
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.Exitf(0, "%s\n", term)
	}

	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
	}

	for {
		fuzzyEntries := scoring.NewFuzzyEntries(entries, term)

		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)

				continue
			}

			cli.Outf("%s\n", entry.Path)
			conf.WriteSearch(term, index)
		}

		break
	}
}
Exemplo n.º 5
0
func topCmd(args cli.Args, conf *config.Config) {
	entries, err := conf.ReadEntries()
	if err != nil {
		cli.Exitf(1, "%s\n", err)
	}

	// We usually keep them reversely sort to optimize the fuzzy search.
	sort.Sort(sort.Reverse(entries))

	for _, entry := range entries {
		cli.Outf("%s\n", entry.Path)
	}
}