# SPDX-License-Identifier: AGPL-3.0-or-later
# this gets sourced. shebang is just for file mode detection
+
# Use source ~/.bashrc instead of doing bash -l when running a script
# so this can set extdebug and avoid the bash debugger.
if [[ -s /a/bin/errhandle/err ]]; then
history -a # save history
fi
+ if [[ $jr_pid ]]; then
+ if [[ -e /proc/$jr_pid ]]; then
+ kill $jr_pid
+ fi
+ unset jr_pid
+ fi
+
case $return in
0) ps_color="$term_purple"
ps_char='\$'
# shellcheck disable=SC1090
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
+# I had this idea to start a bash shell which would run an initial
+# command passed through this env variable, then continue on
+# interactively. But the use case I had in mind went away.
+#
+# if [[ $MY_INIT_CMD ]]; then
+# "${MY_INIT_CMD[@]}"
+# unset MY_INIT_CMD
+# fi
# ensure no bad programs appending to this file will have an affect
return 0
fi
}
-_jrun() { # journal run. run args, log to journal, tail and grep the journal.
- # Redirect all commands which might have stderr to stdout because of
- # wrapping.
- local pid pattern jr_pid sedscript cmd_name ended
+
+jrun() { # journal run. run args, log to journal, tail and grep the journal.
+ # Note, an alternative without systemd would be something like ts.
+ # Note: I tried doing cmd | pee "sudo systemd-cat" cat, but that
+ # had some problems like ctrl-c didnt work or something.
+ local pid pattern sedscript cmd_name ended
ret=0
case $1 in
-p)
;;
esac
cmd_name=${1##*/}
- systemd-cat -t "$cmd_name" "$@" 2>&1 &
- pid=$!
- old_int_trap="$(trap -p INT)"
- # Note, just passing along INT wont actually stop it.
- # Oddly, the log says ERROR: /script.sh returned 130
- # but it continues on.
- trap "inttrap $pid" INT
- sedscript="/$pattern$cmd_name/p;/^.{16}[^ ]+ $cmd_name\[$pid]: ([^ ]*\/)?$cmd_name: exiting with status [0-9]+\$/q"
- # debug:
- #echo "sedscript: sed -nr '$sedscript'"
- journalctl -S "4 seconds ago" -f |& sed -nr "$sedscript" 2>&1 &
+ sedscript="/$pattern$cmd_name/p;/^.{16}[^ ]+ $cmd_name\[[0-9]+]: ([^ ]*\/)?$cmd_name: exiting with status [0-9]+\$/q"
+ # We use >() so that $! is the pid of journalctl, otherwise its the sed pid and then
+ # if we kill that, it takes journalctl about 10 seconds to catch up, and we get
+ # an annoying message about job finishing then.
+ journalctl -qn2 -f &> >(sed -nr "$sedscript") &
+ # We kill this in prompt-command for the case that we ctrl-c the
+ # systemd-cat. i dont know any way to trap ctrl-c and still run the
+ # normal action for it. There might be a way, unsure.
jr_pid=$!
- wait $pid 2>&1 || ret=$?
+ systemd-cat -t "$cmd_name" "$@" || ret=$?
if (( $ret )); then
- echo "$0: ERROR: $* returned $ret"
- fi
- ended=false
- # give it 4 seconds to find the end of the log
- for (( i=0; i<80; i++ )); do
- if [[ -e /proc/$jr_pid ]]; then
- sleep .05 2>&1
- else
- ended=true
- break
- fi
- done
- if ! $ended; then
- kill $jr_pid 2>&1
+ echo "jrun: ERROR: $* returned $ret"
fi
- if [[ $old_int_trap ]]; then
- $old_int_trap
- else
- trap INT
- fi
- return 0
-}
-jrun() {
- # ditching stderr avoids the jobs status change output.
- _jrun "$@" 2>/dev/null
+ # This justs lets the journal output its last line
+ # before the prompt comes up.
+ sleep .5
+ kill $jr_pid &>/dev/null ||:
+ unset jr_pid
+ fg &>/dev/null ||:
}
sm() {