- Execute
bash
code block from a markdown file → ```bash [...] ```
- add this to your .bashrc or .zshrc or .what-ever.rc
# markdown bash execute
function mbe() {
if [ -f "$1" ]; then
cat $1 | # print the file
sed -n '/```bash/,/```/p' | # get the bash code blocks
sed 's/```bash//g' | # remove the ```bash
sed 's/```//g' | # remove the trailing ```
sed '/^$/d' | # remove empty lines
/usr/bin/env sh ; # execute the command
else
echo "${1} is not valid" ;
fi
}
-
call with
mbe file.md
-
Enjoy !
Following the idea this one will print out text in between (+respecting indentation):
Example output: