Git Product home page Git Product logo

cobra-shell's People

Contributors

brianstrauch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

yannickpferr

cobra-shell's Issues

Fuzzy Suggestions for Autocomplete

Hey!

I implemented a directory walker that outputs e.g. ps1 files recursively in nested folders.

Is it possible to do fuzzy searching on this parameter?
I saw fuzzy suggestions are implemented in go-prompt (https://github.com/c-bata/go-prompt/blob/82a912274504477990ecf7c852eebb7c85291772/CHANGELOG.md and c-bata/go-prompt#92).

However, I'm unsure where to set this option and if it is configurable also in cobra-shell.
You showed already a nice way to add keybindings. So I thought there may be an easy solution for this as well. ๐Ÿ˜„

Persistent History

Hey!

I'm trying to get a persistent history working. However, the struggle is real :D
Maybe you have an idea and better understanding of cobra.

The command has the following additional argument

...
PreRun:            WriteHistory,

The following function does write the history line and append it to the file:

func WriteHistory(cmd *cobra.Command, args []string) {
	enabledFlags = nil

	// Open history file
	f, err := os.OpenFile(".fry_history",
		os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
	if err != nil {
		log.Println(err)
	}
	defer f.Close()

	// Parse flags
	cmd.Flags().SortFlags = false
	cmd.Flags().Visit(checkFlags)
	log.Print()
	// Join flags and arguments
	cmdLine := cmd.Parent().Use + " " + cmd.Use + " " + strings.Join(enabledFlags, " ") + " " + strings.Join(args, " ")
	if _, err := f.WriteString(cmdLine + "\n"); err != nil {
		log.Println(err)
	}
}

Reading the history does happen at the start of the program execution:

func init...
hist := prompt.OptionHistory(readHistory())
	myShell := shell.New(rootCmd, keyBinds, codeBinds, number, hist)
func readHistory() []string {
	data, err := os.ReadFile(".fry_history")
	if err != nil {
		log.Println("No history yet. Nothing to parse")
	}
	history := strings.Split(string(data), "\n")
	return history
}

Build the flag strings (this is super weird and I look for a better solution).

func checkFlags(f *pflag.Flag) {
	if f.Value.Type() == "bool" {
		//fmt.Println(f.Value.String())
		enabledFlags = append(enabledFlags, "--"+f.Name)
	} else {
		enabledFlags = append(enabledFlags, "--"+f.Name+" \""+f.Value.String()+"\"")
	}
	fmt.Printf("Flags: %v\n", enabledFlags)
}

This approach works fine for the first execution of a command.
However, the flags do not reset after each command execution. Thus the flags add up when running multiple times in one shell.

image

By any chance. Do you have experience how to parse the flags correctly in order to write them to a file?

[Bug] Flags are permanently removed from the autocompletion

Bug

When I have e.g. two flags like the following:
image

I can use them one time. Afterwards they will be removed. This is expected and good.
image

However, when I now press up or rewrite the commands the used completion flags are gone.
image

Fix

The flags should be re-enabled after each execution.

Edit: I saw you already tried to fix this issue in db07c08.
However, I'm on 0.2.4 so maybe the fix is not complete.

Autocomplete Flag Parsing Order

Currently flags do show up like this:
image

However, it might be a good idea to display all --flags first and after them the -f(lags).
Another solution would be to show only the long version or both in one line as the description has to be the same and on autocomplete insert the long one as this is the most descriptive. This might need some conditional logic I guess if there are cases with short but no long flags or the other way round.

Alt + Backspace to delete complete words

Hey Brian,

Can't believe I'm the first person creating an issue here. This project is such a great idea! I missed this automation in other projects like ishell or promptui.

Bug / Feature Request

I just noticed that alt + backspace behaves strangely. It will insert question marks instead of deleting complete words as I would expect it in an interactive shell.

As it messes with the cli-ui it might be a bug to address but also a nice feature implementation that I'd love to see!

Edit: Also ctrl+right and ctrl+left would be a great idea in order to skip through longer commands as I just noticed :D

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.