#! ls -la
Last active
August 13, 2016 00:29
-
-
Save progrium/d353426624e99a1b3352a1bfe2f5a28b to your computer and use it in GitHub Desktop.
execute and insert commands found in markdown inside ``` starting with #!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"os" | |
"strings" | |
"github.com/lunixbochs/vtclean" | |
"github.com/progrium/go-shell" | |
) | |
func main() { | |
d, _ := ioutil.ReadAll(os.Stdin) | |
doc := string(d) | |
preparts := strings.SplitN(doc, "```\n#!", 2) | |
postparts := strings.SplitN(preparts[1], "```", 2) | |
cmdparts := strings.SplitN(postparts[0], "\n", 2) | |
cmdline := strings.Trim(cmdparts[0], " ") | |
output, _ := shell.Cmd(cmdline).OutputFn()() | |
fmt.Println( | |
strings.Join([]string{ | |
preparts[0], | |
"```\n#! " + cmdline + "\n", | |
vtclean.Clean(output, false), | |
"\n```", | |
postparts[1], | |
}, "")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment