~sircmpwn/mrsh

966f4ca6fafc0e950ad2d01c8591344a6b11c9d4 — Simon Ser 6 months ago bd7a77e
shell/task: add pipeline bang
4 files changed, 11 insertions(+), 5 deletions(-)

M shell/task/pipeline.c
M shell/task/simple_command.c
M shell/task/task.c
M test/pipeline.sh
M shell/task/pipeline.c => shell/task/pipeline.c +3 -0
@@ 88,5 88,8 @@ int run_pipeline(struct context *ctx, struct mrsh_pipeline *pl) {
		}
	}
	mrsh_array_finish(&procs);
	if (pl->bang && ret >= 0) {
		ret = !ret;
	}
	return ret;
}

M shell/task/simple_command.c => shell/task/simple_command.c +0 -4
@@ 348,10 348,6 @@ int run_simple_command(struct context *ctx, struct mrsh_simple_command *sc) {
		ret = run_process(ctx, sc, argv);
	}

	if (ret >= 0) {
		ctx->state->last_status = ret;
	}

	mrsh_command_destroy(&sc->command);
	for (size_t i = 0; i < args.len; ++i) {
		free(args.data[i]);

M shell/task/task.c => shell/task/task.c +3 -0
@@ 317,6 317,9 @@ int run_command_list_array(struct context *ctx, struct mrsh_array *array) {
				return ret;
			}
		}
		if (ret >= 0) {
			ctx->state->last_status = ret;
		}
	}
	return ret;
}

M test/pipeline.sh => test/pipeline.sh +5 -1
@@ 9,12 9,16 @@ echo "a b c d" | sed s/b/B/
echo >&2 "Pipeline with 3 commands"
echo "a b c d" | sed s/b/B/ | sed s/c/C/

#echo >&2 "Pipeline with bang"
#! false
#echo $?

# https://github.com/emersion/mrsh/issues/100
#echo >&2 "Pipeline with subshell"
#(echo "a b"; echo "c d") | sed s/c/C/

# https://github.com/emersion/mrsh/issues/96
#echo >&2 "Pipeline with brace group"
echo >&2 "Pipeline with brace group"
#{ echo "a b"; echo "c d"; } | sed s/c/C/

# https://github.com/emersion/mrsh/issues/95