feat(bash): support bash time syntax

This commit is contained in:
mateoferon 2022-12-09 16:57:20 +01:00
parent 6453b44b00
commit f74c97fc7f
3 changed files with 21 additions and 6 deletions

View file

@ -287,12 +287,13 @@ public:
class pipeline_t : public _obj
{
public:
pipeline_t(block_t* bl=nullptr) { type=_obj::pipeline; if(bl!=nullptr) cmds.push_back(bl); negated=false; }
pipeline_t(block_t* bl=nullptr) { type=_obj::pipeline; if(bl!=nullptr) cmds.push_back(bl); negated=false; bash_time=false; }
~pipeline_t() { for(auto it: cmds) delete it; }
inline void add(block_t* bl) { this->cmds.push_back(bl); }
std::vector<block_t*> cmds;
bool negated; // negated return value (! at start)
bool bash_time; // has bash time command
std::string generate(int ind, generate_context* ctx);
std::string generate(int ind) { return this->generate(ind, nullptr); };

View file

@ -56,6 +56,10 @@ std::string pipeline_t::generate(int ind, generate_context* ctx)
if(negated)
ret += "! ";
if(bash_time)
ret += "time ";
ret += cmds[0]->generate(ind, ctx);
for(uint32_t i=1 ; i<cmds.size() ; i++)
{

View file

@ -931,12 +931,22 @@ std::pair<pipeline_t*, parse_context> parse_pipeline(parse_context ctx)
{
pipeline_t* ret = new pipeline_t;
if(ctx[ctx.i] == '!' && ctx.i+1<ctx.size && is_in(ctx[ctx.i+1], SPACES))
{
ret->negated = true;
ctx.i++;
ctx.i=skip_chars(ctx, SPACES);
while(true) {
auto wp = get_word(ctx, ARG_END);
if(ctx[ctx.i] == '!' && ctx.i+1<ctx.size && is_in(ctx[ctx.i+1], SPACES))
{
ret->negated = ret->negated ? false : true;
ctx.i++;
ctx.i=skip_chars(ctx, SPACES);
} else if(ctx.bash && wp.first == "time" ) {
ret->bash_time = true;
ctx.i+=4;
ctx.i=skip_chars(ctx, SPACES);
} else {
break;
}
}
while(ctx.i<ctx.size)
{
auto pp=parse_block(ctx);