Support multi line
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 execandpet search
- [x]
- [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.
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 = []
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?
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
$EDITORfor editing multi line commands?
Good idea. I'll try it.
Thank you!
Any update on it?
This will be helpful!
I like this! Will look into it soon after all the high prio bugs. @ofey404 Thanks for the great idea!