~kris/dots

srice

ref: ff7367cb2ef828502c3f7fde003f45d5daa33206 srice/.local/bin/rofi-courses.py -rw-r--r-- 1.3 KiB
ff7367cb — Kris Yotam add ram memory visualization script 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
"""
===============================================================
 Script: rofi-courses.py
 Author: Kris Yotam (aka. khr1st)
 Date:   2025-09-29
 License: MIT License
 Description:
   Rofi interface to select and activate a course.
   Highlights the current course, and updates the symlink +
   watch file if a new course is chosen.

 Inspiration:
   Adapted and extended from Gilles Castel's lecture note workflow.
===============================================================
"""

from rofi import rofi
from courses import Courses


def select_course(courses: Courses):
    """
    Show course list in rofi, return selected index or -1 if cancelled.
    """
    try:
        current_index = courses.index(courses.current)
        args = ["-a", current_index]  # Highlight current course
    except ValueError:
        args = []

    code, index, _ = rofi(
        "Select course",
        [c.info["title"] for c in courses],
        ["-auto-select", "-no-custom", "-lines", str(len(courses))] + args,
    )
    return index


def main():
    courses = Courses()
    index = select_course(courses)

    if index >= 0:
        courses.current = courses[index]
        print(f"[ok] Switched to {courses[index].info['title']}")


if __name__ == "__main__":
    main()