This commit is contained in:
2025-08-25 07:06:50 +02:00
parent e8d09164ff
commit 581fb0c0f0
15 changed files with 287 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
# Common error handling setup
# set -euo pipefail
SCRIPT="${BASH_SOURCE[-1]}" # last sourced = the actual script file
ERROR_FILE="$SCRIPT.error"
DONE_FILE="$SCRIPT.done"
# Reset markers
rm -f "$ERROR_FILE" "$DONE_FILE"
error_handler() {
local exit_code=$?
local line_no=$1
local cmd="$2"
{
echo "EXIT_CODE=$exit_code"
echo "LINE=$line_no"
echo "COMMAND=$cmd"
} > "$ERROR_FILE"
# If we are inside a sourced script, don't kill the shell
if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
return $exit_code
else
exit $exit_code
fi
}
trap 'error_handler ${LINENO} "$BASH_COMMAND"' ERR
mark_done() {
touch "$DONE_FILE"
}

View File

@@ -0,0 +1,12 @@
hpy() {
if [ ! -f ".venv/bin/activate" ]; then
echo "Error: .venv not found in current directory" >&2
return 1
fi
# Activate venv in a subshell so it doesnt pollute caller
(
source .venv/bin/activate
python "$@"
)
}

View File

@@ -0,0 +1,19 @@
get_session() {
local sessions
sessions=$(tmux ls 2>/dev/null | cut -d: -f1)
local count
count=$(echo "$sessions" | wc -l)
if [ "$count" -eq 0 ]; then
echo "Error: no tmux sessions found." >&2
return 1
elif [ "$count" -gt 1 ]; then
echo "Error: more than one tmux session found:" >&2
echo "$sessions" >&2
return 1
fi
export SESSIONNAME="$sessions"
echo "$SESSIONNAME"
}