diff --git a/README.md b/README.md index 960a5e8..af6dc38 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,11 @@ I applied some magic to summon the ingestion of `chapter markers` to the video t 1. Download and install zsh zim framework: `curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh` 2. Remove `compinit` from your .zshrc if needed -3. Install asciinema `apt install asciinema python3-docopt` +3. Install asciinema and Python dependencies: + ```bash + apt install asciinema + pip install -r requirements.txt # installs docopt + prompt_toolkit + ``` 4. Edit .zimrc and add `zmodule cmprmsd/cinelog` 5. Run `zimfw install` to download the plugin from GitHub 6. Start a new terminal diff --git a/cinelog.plugin.zsh b/cinelog.plugin.zsh index 7ef69ca..e5169fc 100644 --- a/cinelog.plugin.zsh +++ b/cinelog.plugin.zsh @@ -5,6 +5,9 @@ # Author: Sebastian Haas - https://h8.to #################################################### +# Resolve plugin directory dynamically — works with zim, oh-my-zsh, antigen, manual installs, etc. +CINELOG_DIR="${${0:A:h}}" + # Color definitions using 24-bit true color (RGB) RESET='\e[0m' # Resets all attributes BOLD='\e[1m' @@ -13,7 +16,7 @@ BOLD='\e[1m' BASIC_RED='\e[31m' BASIC_GREEN='\e[32m' BASIC_BLUE='\e[34m' -BAISC_MAGENTA='\e[35m' +BASIC_MAGENTA='\e[35m' BASIC_CYAN='\e[36m' # Pastel Colors PASTEL_RED='\e[38;2;255;105;97m' @@ -69,8 +72,8 @@ here() { alias cs="clear; load_motd" # Interactive history search with graphical Asciinema UI -alias hist="$HOME/.zim/modules/cinelog/hist" -alias histo="$HOME/.zim/modules/cinelog/histo" +alias hist="$CINELOG_DIR/hist" +alias histo="$CINELOG_DIR/histo" # MOTD functionality load_motd() { @@ -151,7 +154,7 @@ else # Check for webserver and spawn if not running if ! ss -tln | grep -q ":${CINELOG_VIEWER_PORT}"; then { - nohup python3 "$HOME/.zim/modules/cinelog/http_server.py" & #>/dev/null 2>&1 & + nohup python3 "$CINELOG_DIR/http_server.py" & #>/dev/null 2>&1 & } &>/dev/null fi export LOGFILE="$LOGDIR/terminal_$(date +%F_%T:%3N).cast" diff --git a/http_server.py b/http_server.py index fc5da3a..ea284c1 100644 --- a/http_server.py +++ b/http_server.py @@ -35,7 +35,14 @@ def do_GET(self): def run_server(port, directory, auth_token): handler = partial(AuthHandler, auth_token=auth_token, directory=directory) - ip = subprocess.check_output("ip route get 1 | awk '{print $7}'", shell=True).decode().strip() + try: + ip = subprocess.check_output("ip route get 1 | awk '{print $7}'", shell=True).decode().strip() + except Exception: + import socket + # Fallback for non-Linux systems (macOS, BSD) + with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: + s.connect(("8.8.8.8", 80)) + ip = s.getsockname()[0] with socketserver.TCPServer((ip, port), handler) as httpd: print(f"Serving at port {port} with authentication") httpd.serve_forever() @@ -43,7 +50,11 @@ def run_server(port, directory, auth_token): if __name__ == "__main__": port = int(os.environ.get('CINELOG_VIEWER_PORT', 10000)) auth_token = os.environ.get('CINELOG_AUTH_UUID') - directory = os.path.expanduser("~/.zim/modules/cinelog/asciinema-player") + # Use CINELOG_DIR env var if set (exported by the zsh plugin), otherwise fall back to + # a path relative to this script's location — works regardless of plugin manager. + script_dir = os.path.dirname(os.path.realpath(__file__)) + directory = os.environ.get('CINELOG_DIR', script_dir) + directory = os.path.join(directory, 'asciinema-player') if not auth_token: print("Error: CINELOG_AUTH_UUID environment variable not set") diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2001fe8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +docopt==0.6.2 +prompt_toolkit>=3.0.0