...
This commit is contained in:
		
							
								
								
									
										32
									
								
								examples/tmuxrunnerexamples/functions/base.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								examples/tmuxrunnerexamples/functions/base.sh
									
									
									
									
									
										Normal 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"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										12
									
								
								examples/tmuxrunnerexamples/functions/hpy.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								examples/tmuxrunnerexamples/functions/hpy.sh
									
									
									
									
									
										Normal 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 doesn’t pollute caller
 | 
			
		||||
    (
 | 
			
		||||
        source .venv/bin/activate
 | 
			
		||||
        python "$@"
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								examples/tmuxrunnerexamples/functions/tmuxlib.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								examples/tmuxrunnerexamples/functions/tmuxlib.sh
									
									
									
									
									
										Normal 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"
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user