2021-10-22 16:24:02 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
new_tmp_dir() {
|
|
|
|
local dirname
|
|
|
|
dirname=$(mktemp -d)
|
|
|
|
mkdir -p "$dirname"
|
|
|
|
cd "$dirname"
|
|
|
|
trap "rm -rf '$dirname'" EXIT
|
|
|
|
}
|
|
|
|
|
2022-10-21 05:13:09 +00:00
|
|
|
run_command() {
|
|
|
|
echo "\$ $@"
|
2023-08-29 03:57:26 +00:00
|
|
|
# `bash` often resets $COLUMNS, so we also
|
|
|
|
# allow $RUN_COMMAND_COLUMNS
|
|
|
|
COLUMNS=${RUN_COMMAND_COLUMNS-${COLUMNS-80}} eval "$@"
|
2021-10-23 16:34:58 +00:00
|
|
|
}
|
2021-10-23 16:22:45 +00:00
|
|
|
|
2023-09-10 04:17:47 +00:00
|
|
|
run_command_output_redacted() {
|
|
|
|
echo "\$ $@"
|
|
|
|
# `bash` often resets $COLUMNS, so we also
|
|
|
|
# allow $RUN_COMMAND_COLUMNS
|
|
|
|
eval "$@" > /dev/null
|
|
|
|
echo -e "\033[0;90m... (output redacted) ...\033[0m"
|
|
|
|
}
|
|
|
|
|
2023-08-29 05:59:58 +00:00
|
|
|
run_command_allow_broken_pipe() {
|
|
|
|
run_command "$@" || {
|
|
|
|
EXITCODE="$?"
|
|
|
|
case $EXITCODE in
|
|
|
|
3)
|
|
|
|
# `jj` exits with error coded 3 on broken pipe,
|
|
|
|
# which can happen simply because of running
|
|
|
|
# `jj|head`.
|
|
|
|
return 0;;
|
|
|
|
*)
|
|
|
|
return $EXITCODE;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-21 05:13:09 +00:00
|
|
|
blank() {
|
|
|
|
echo ""
|
|
|
|
}
|
2021-10-22 16:24:02 +00:00
|
|
|
|
2022-10-21 05:13:09 +00:00
|
|
|
comment() {
|
|
|
|
indented="$(echo "$@"| sed 's/^/# /g')"
|
|
|
|
blank
|
|
|
|
echo -e "\033[0;32m${indented}\033[0m"
|
|
|
|
blank
|
2021-10-22 16:24:02 +00:00
|
|
|
}
|