pet icon indicating copy to clipboard operation
pet copied to clipboard

Support multi line

Open ofey404 opened this issue 5 years ago • 6 comments

Issue #116

Description of changes:

Add a --multiline flag in pet new subcommand.

$ pet new --multiline
Command> for i in 1 2 3;
.......> do
.......>     echo "$i"
.......> done
.......> 
.......> 
Description> test multi line new 3
  • Double enter to finish command entering.
  • Don't trim space surround commands.

Entry below will generated:

[[snippets]]
  description = "test multi line new 3"
  command = "for i in 1 2 3;\ndo\n\techo \"$i\"\ndone"  # I want to support triple quote raw string, but github.com/BurntSushi/toml don't support this feature, and it's unmaintained.
  output = ""

Tested pet search, exec, it works well on my test toml:

[[snippets]]
  description = "test run multiline"
  command = "for i in 1 2 3;\ndo\n\techo \"$i\"\ndone"
  output = ""

[[snippets]]
  description = "test run multiline 2"
  command = """for i in 1 2 3;
do
	echo \"$i\"
done
"""
  output = ""

Test result:

$ pet search --query multi1
for i in 1 2 3;
do
        echo "$i"
done

$ pet search --query multi2
for i in 1 2 3;
do
        echo "$i"
done

$ pet exec --query multi1
1
2
3

$ pet exec --query multi2
1
2
3

roadmap

  • [x] Basic multiline support.
    • [x] pet new
    • [x] pet exec and pet search
  • [x] generate triple quote raw string while pet new -m.
    • [x] Replace unmaintained dependency BurntSushi/toml

I also want to:

  • Enhance tag support of pet, make something like list all tag or filter by tag.
  • Enhance pet edit, so we can fuzzy find an entry and jump to it right we enter the editor.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

ofey404 avatar Mar 17 '21 10:03 ofey404

All commands become multiline quoted string.

Test command:

$ ./pet new
Command> echo "hello"
Description> Test single lined new

$ ./pet new -m
Command> for i in 1 2 3;
.......> do
.......>     echo "$i"
.......> done
.......> 
.......> 
Description> Test multi lined new

Generate result:

[[snippets]]
  command = """
echo "hello\""""
  description = "Test single lined new"
  output = ""
  tag = []

[[snippets]]
  command = """
for i in 1 2 3;
do
	echo "$i"
done"""
  description = "Test multi lined new"
  output = ""
  tag = []

ofey404 avatar Mar 17 '21 14:03 ofey404

I checked out your code and tried it. While I like the idea, the makeshift multiline editor is not easy to use. Why not calling $EDITOR for editing multi line commands?

snipem avatar May 13 '21 07:05 snipem

I checked out your code and tried it. While I like the idea, the makeshift multiline editor is not easy to use. Why not calling $EDITOR for editing multi line commands?

Good idea. I'll try it.

Thank you!

ofey404 avatar May 28 '21 05:05 ofey404

Any update on it?

omriperi avatar Dec 05 '21 14:12 omriperi

This will be helpful!

keidarcy avatar Feb 27 '22 02:02 keidarcy

I like this! Will look into it soon after all the high prio bugs. @ofey404 Thanks for the great idea!

RamiAwar avatar Jan 30 '24 18:01 RamiAwar