+
Skip to content

atgumx/esht

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

esht - Embeddable SHell Tags

Description

This is still way under development and verification, but the main idea here is to be able to write a plain text document with shell code enclosed between $[ and ]. And then be able to compile it into a working shell script that prints everything verbatim using printf and the code between the tags gets executed in the same subshell.

There are similar examples that but not quite the same like bash-tbl, spp, sempl, and another snippet I can't find right now.

Usage & example

esht requires one or more filenames as arguments, the first will be considered the source file. If a second filename is provided it will be considered as the output file and will be created, or overwritted if it already exists. If no output file specified, esht will print to the standard output.

Given a file source.html.esht with the following content:

$[ # define a user function
   table_element() {
       echo "<td bgcolor=\"$1\">$1</td>"
    }
   ]
<html>
	<body>
<table border=1><tr>
$[ for a in Red Blue Yellow Cyan; do ]
        $[ table_element $a ]
        $[ done ]
</tr></table>
</body>
</html>

Running ./esht source.html.esht output.sh will generate the file output.sh with the following code:

# define a user function
   table_element() {
       echo "<td bgcolor=\"$1\">$1</td>"
    }

printf '\n<html>\n\t<body>\n<table border=1><tr>\n'
for a in Red Blue Yellow Cyan; do
printf '\n        '
table_element $a
printf '\n        '
done
printf '\n</tr></table>\n</body>\n</html>\n'

Which in turn can be sourced by running . output.sh to get the html output:

<html>
	<body>
<table border=1><tr>

        <td bgcolor="Red">Red</td>

        
        <td bgcolor="Blue">Blue</td>

        
        <td bgcolor="Yellow">Yellow</td>

        
        <td bgcolor="Cyan">Cyan</td>

        
</tr></table>
</body>
</html>

The same result from above can can also be produced by using -x option.

TODO

  • Detect and remove unnecessary leading and trailing white spaces
  • Refactor and organize the existing code
  • Use trap to indicate incomplete output
  • Add -x option to automatically execute the generated script
  • Add -u option to automatically update esht
  • Add -e option to include environmental variables
  • Define some default variables for template name, dirname, parsing date,..
  • Write more test inputs to detect edge cases
  • Write proper documentation

Credits

License

This project is licensed under The Unlicense

About

Embeddable SHell Tags parser thingie

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载