Files
tui/install.sh
2026-10-12 22:00:15 +02:00

64 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PREFIX="${HOME}/.local"
LIBDIR="${PREFIX}/lib/tui"
BINDIR="${PREFIX}/bin"
BASHRC="${HOME}/.bashrc"
MARKER="# >>> tui shell integration >>>"
ENDMARKER="# <<< tui shell integration <<<"
if ! command -v python3 >/dev/null 2>&1; then
echo "install.sh: python3 is required" >&2
exit 1
fi
if ! python3 - <<'PY'
try:
import yaml
except ImportError:
raise SystemExit(1)
PY
then
echo "install.sh: PyYAML is required." >&2
echo "Install it with: sudo apt install python3-yaml" >&2
exit 1
fi
mkdir -p "$LIBDIR" "$BINDIR"
cp "$SCRIPT_DIR/tui/tui.py" "$LIBDIR/tui.py"
chmod 755 "$LIBDIR/tui.py"
cp "$SCRIPT_DIR/tui/tui-shell.bash" "$LIBDIR/tui-shell.bash"
chmod 644 "$LIBDIR/tui-shell.bash"
# Optional standalone entry point. The normal command is the Bash function
# loaded from tui-shell.bash; this wrapper is useful for diagnostics.
cat > "$BINDIR/tui.py" <<EOF2
#!/usr/bin/env bash
exec python3 "$LIBDIR/tui.py" "\$@"
EOF2
chmod 755 "$BINDIR/tui.py"
# Load the Bash integration for every interactive Bash session. On Debian,
# the normal login startup path loads ~/.bashrc for interactive Bash shells.
touch "$BASHRC"
if ! grep -Fqx "$MARKER" "$BASHRC"; then
{
printf '\n%s\n' "$MARKER"
printf 'source "%s"\n' "$LIBDIR/tui-shell.bash"
printf '%s\n' "$ENDMARKER"
} >> "$BASHRC"
fi
# Install an example configuration only if the user does not already have
# one in the current directory. .tui files are deliberately project-local.
if [[ ! -e "$HOME/.tui" && -f "$SCRIPT_DIR/tui/example.tui" ]]; then
cp "$SCRIPT_DIR/tui/example.tui" "$HOME/.tui"
echo "Installed example configuration: ~/.tui"
fi
printf '\nTUI installed to %s\n' "$LIBDIR"
printf 'Bash integration installed in %s\n' "$BASHRC"
printf '\nStart a new login/terminal session, or run:\n source ~/.bashrc\n\nThen:\n tui\n'