Files
Copies/start-gui.sh
T
2026-09-08 16:41:04 +02:00

48 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Applications opened from a file manager do not inherit variables exported by
# an interactive shell (for example GEMINI_API_KEY from ~/.zshrc). Re-enter
# through the user's shell once so its startup file can provide those values.
if [[ -z "${GEMINI_API_KEY:-}" && -z "${COPIENATOR_GUI_SHELL_LOADED:-}" && -x "${SHELL:-}" ]]; then
export COPIENATOR_GUI_SHELL_LOADED=1
exec "$SHELL" -ic 'exec "$@"' copienator-gui-shell "$0" "$@"
fi
# With no arguments, choose the newest visible immediate subfolder by mtime.
if [[ $# -eq 0 ]]; then
newest=""
for candidate in "$PWD"/*/; do
[[ -d "$candidate" ]] || continue
folder="${candidate%/}"
folder="${folder##*/}"
case "$folder" in
copienator|copienator_gui|tests|OLD|__pycache__|build|dist|*.egg-info|venv|env|node_modules)
continue
;;
esac
if [[ -z "$newest" || "$candidate" -nt "$newest" ]]; then
newest="$candidate"
fi
done
if [[ -n "$newest" ]]; then
set -- "${newest%/}"
fi
fi
# Resolve the evaluation before changing to the project directory.
if [[ $# -gt 0 && "$1" != -* && "$1" != /* ]]; then
evaluation="$PWD/$1"
shift
set -- "$evaluation" "$@"
fi
repository="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
cd -- "$repository"
if [[ -x "$repository/.venv/bin/python" ]]; then
python_command="$repository/.venv/bin/python"
else
python_command="python3"
fi
exec "$python_command" -m copienator_gui "$@"