Skip to content

Commit

Permalink
removed DEBUG trap
Browse files Browse the repository at this point in the history
  • Loading branch information
dmalan committed Aug 12, 2024
1 parent 84d7819 commit 21148f6
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions etc/profile.d/help50.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,34 @@ function _help50() {
HISTFILE=$histfile history -a
local argv=$(HISTFILE=$histfile history 1 | cut -c 8-) # Could technically contain multiple commands, separated by ; or &&
rm --force $histfile
local argv0=$(echo "$argv" | awk '{print $1}') # Assume for simplicity it's just a single command

# Remove any of these aliases
for name in n no y yes; do
unalias $name 2> /dev/null
done

# If last command was ./*
# touch foo.c && make foo && touch foo.c && ./foo
if [[ "$argv" =~ ^\./(.*)$ ]]; then
local src="${BASH_REMATCH[1]}.c"
local dst="${BASH_REMATCH[1]}"
if [[ -f "$src" && $(file --brief --mime-type "$src") == "text/x-c" ]]; then
if [[ -x "$dst" && $(file --brief --mime-type "$dst") == "application/x-pie-executable" ]]; then
if [[ "$src" -nt "$dst" ]]; then
_helpful "It looks like \`$src\` has changed. Did you mean to run \`make $dst\` again?"
fi
fi
fi
fi

# If last command erred (and is not ctl-c or ctl-z)
# https://tldp.org/LDP/abs/html/exitcodes.html
if [[ $status -ne 0 && $status -ne 130 && $status -ne 148 ]]; then

# Ignore ./* if executable file
local argv0=$(echo "$argv" | awk '{print $1}') # Assume for simplicity it's just a single command
if [[ "$argv0" =~ ^\./ && -f "$argv0" && -x "$argv0" ]]; then
echo XXX
return
fi

Expand Down Expand Up @@ -72,6 +87,7 @@ function _help50() {
# Try to get help
for helper in $HELPERS/*; do
if [[ -f $helper && -x $helper ]]; then
echo "[$helper]"
local help=$($helper $argv <<< "$typescript")
if [[ -n "$help" ]]; then
break
Expand Down Expand Up @@ -112,22 +128,3 @@ if ! type _helpless >/dev/null 2>&1; then
fi

export PROMPT_COMMAND=_help50

function _trap() {

# touch foo.c && make foo && touch foo.c && ./foo
if [[ "$BASH_COMMAND" =~ ^\./(.*)$ ]]; then
local src="${BASH_REMATCH[1]}.c"
local dst="${BASH_REMATCH[1]}"
if [[ -f "$src" && $(file --brief --mime-type "$src") == "text/x-c" ]]; then
if [[ -x "$dst" && $(file --brief --mime-type "$dst") == "application/x-pie-executable" ]]; then
_helpful "It looks like \`$src\` has changed. Did you mean to run \`make $dst\` again?"
fi
fi
fi
}

# If the command run by the DEBUG trap returns a non-zero value, the next command is skipped and not executed
shopt -s extdebug

trap _trap DEBUG

0 comments on commit 21148f6

Please sign in to comment.