#!/bin/bash TEX_DOSYASI="${1:-test.tex}" PDF_DOSYASI="${TEX_DOSYASI%.tex}.pdf" export DISPLAY=:0 shopt -s nullglob # *.py/*.ipynb hiç yoksa git add'e "bulunamadı" hatası vermesin # 1. OTOMATİK GÖNDERME (PUSH) FONKSİYONU cleanup_and_push() { echo -e '\n🛑 İzleme durduruldu.' # Eğer bir Git deposunun içindeysek (örneğin nonmarkov klasörü), otomatik push yap if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then echo "☁️ Değişiklikler Forgejo'ya gönderiliyor..." # Kodu (tex/py/ipynb) ve PDF'i ekle ki arkadaşların site üzerinden okuyabilsin git add *.tex *.py *.ipynb 2>/dev/null [ -f "$PDF_DOSYASI" ] && git add "$PDF_DOSYASI" 2>/dev/null # O anki tarih ve saat ile otomatik commit mesajı oluştur if git commit -m "Oto-Kayıt: $(date '+%Y-%m-%d %H:%M:%S')"; then echo "📦 Bu commit'e giren dosyalar:" git show --stat HEAD fi if timeout 10 git push origin main; then echo "✅ Kodlar ve PDF sunucuya başarıyla işlendi!" else echo "⚠️ Push başarısız — internet yok ya da firewall engelliyor." echo " Değişiklikler yerelde commit edildi, bağlantı düzelince 'git push origin main' ile gönderebilirsin." fi fi echo 'X11 arka planda sessizce bekliyor. Görüşmek üzere!' exit 0 } # Ctrl+C'ye basıldığında doğrudan çıkmak yerine yukarıdaki fonksiyonu çalıştır trap cleanup_and_push SIGINT # 2. OTOMATİK ÇEKME (PULL) - Sen yokken web'den veya arkadaştan gelenleri al if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then echo "🔄 Sunucudaki son değişiklikler kontrol ediliyor (Auto-pull)..." if ! timeout 10 git pull origin main; then echo "⚠️ Sunucuya ulaşılamadı (internet/firewall sorunu olabilir). Yerel dosyalarla devam ediliyor..." fi fi # 3. Eski evince pencerelerini temizle pkill -f evince 2>/dev/null # 4. X11 CHECK if ! pgrep -f "termux-x11" > /dev/null; then echo "🖥️ Starting X11..." pkill -f fluxbox 2>/dev/null termux-x11 :0 > /dev/null 2>&1 & sleep 3 if ! pgrep -f "termux-x11" > /dev/null; then echo "❌ ERROR: X11 failed to start." exit 1 fi echo "✅ X11 started." else echo "🔄 X11 is already active." fi # 5. FLUXBOX CHECK if ! pgrep -f "fluxbox" > /dev/null; then echo "🪟 Starting window manager..." fluxbox > /dev/null 2>&1 & sleep 1 fi # 6. TEMPLATE CREATOR if [ ! -f "$TEX_DOSYASI" ]; then echo "📄 '$TEX_DOSYASI' not found. Creating template..." # Dosya adından başlık üret: yolu ve .tex uzantısını at, alt çizgiyi boşluğa çevir BASLIK="${TEX_DOSYASI##*/}" BASLIK="${BASLIK%.tex}" BASLIK="${BASLIK//_/ }" # NOT: Bu heredoc tırnaksız ($BASLIK genişlesin diye). İçine $, ` ya da \\ eklemeyin. cat << TEMPLATE > "$TEX_DOSYASI" \documentclass{article} \usepackage{amsmath} \usepackage{amssymb} \usepackage{physics} \usepackage{geometry} \usepackage{hyperref} \geometry{margin=0.1in} \title{$BASLIK paper side notes} \author{Demircan Demirbağ} \date{\today} \begin{document} \maketitle \tableofcontents \newpage \end{document} TEMPLATE fi # 7. INITIAL COMPILE echo "⚙️ Compiling..." pdflatex -interaction=nonstopmode "$TEX_DOSYASI" > compile_log.txt 2>&1 if [ ! -f "$PDF_DOSYASI" ]; then echo "❌ ERROR: LaTeX compilation crashed!" grep -A 3 "^!" compile_log.txt exit 1 fi # 8. OPEN PDF (FULLSCREEN, GENİŞLİĞE SIĞDIR) # Evince tam ekranı kendisi istesin: wmctrl/xdotool kurulu olmasına ya da zamanlamaya bağlı değil. # (Çıkmak için Esc veya F11) # Varsayılan zoom modunu %100 yerine "genişliğe sığdır" yap. dconf/dbus olmayan Termux'ta # ayar kaybolmasın diye keyfile backend kullanılıyor (~/.config/glib-2.0/settings/keyfile). # NOT: Evince, daha önce açılmış bir PDF için kendi kaydettiği zoom'u kullanır (o dosyada bir kez # yukarıdaki zoom menüsünden "Fit Width" seç, hatırlar). GSETTINGS_BACKEND=keyfile gsettings set org.gnome.Evince.Default sizing-mode 'fit-width' 2>/dev/null GSETTINGS_BACKEND=keyfile evince --fullscreen "$PWD/$PDF_DOSYASI" > /dev/null 2>&1 & # 9. TRIGGER ACODE # Evince penceresi açılsın, sonra Acode öne gelsin (yoksa X11 Acode'un üstüne çıkabiliyor). # Yine Acode'un arkasında kalıyorsa süreyi artır. sleep 2 termux-open --content-type "text/x-tex" "$TEX_DOSYASI" echo "==============================================" echo "👀 Watching: '$TEX_DOSYASI'" echo "📂 Working Directory: $PWD" echo "==============================================" # 10. WATCH LOOP (Aynı bıraktık) HEDEF_YOL="$(realpath -m "$TEX_DOSYASI")" while DEGISEN=$(inotifywait -q -e close_write --format '%w%f' --include '.*\.tex$' -r .); do # Sadece izlenen dosya kaydedildiyse derle, diğer .tex dosyalarını yoksay [ "$(realpath -m "$DEGISEN")" = "$HEDEF_YOL" ] || continue echo "⏳ Saved. Compiling..." pdflatex -interaction=nonstopmode "$TEX_DOSYASI" > compile_log.txt 2>&1 if grep -q "^!" compile_log.txt; then echo "⚠️ ERRORS IN CODE! (Evince is showing the last working PDF)" python3 - << 'EOF' import re with open("compile_log.txt") as f: lines = f.readlines() i = 0 while i < len(lines): if lines[i].startswith("!"): error = lines[i].strip() lineno = "?" for j in range(i+1, min(i+10, len(lines))): m = re.match(r'^l\.(\d+)', lines[j]) if m: lineno = m.group(1) break print(f" Line {lineno:<6} {error}") i += 1 EOF else echo "✅ Updated." fi done