butiran

npprel problem

· 1 min read

intro

  • Content of setup/npprel/npprel.py is as follow.
    import os, sys, subprocess, urllib.parse
    
    # --- Notepad++ path per machine ---
    NOTEPADPP = r"C:\Program Files\Notepad++\notepad++.exe"
    
    # This script is in <repo>\setup\npprel\npprel.py
    script_dir = os.path.dirname(os.path.abspath(__file__))
    
    # repo root is two levels up
    repo_root = os.path.abspath(os.path.join(script_dir, os.pardir, os.pardir))
    
    if len(sys.argv) < 2:
        sys.exit("Usage: npprel.py <url>")
    
    url = sys.argv[1]  # e.g. npprel://content/post/my-post.md
    parsed = urllib.parse.urlparse(url)
    rel_path = urllib.parse.unquote(parsed.path).lstrip("/")
    
    folder_path = "content/posts/"
    
    if rel_path == '.md':
        rel_path = '_index.md'
        folder_path = 'content/'
    
    full_path = os.path.normpath(os.path.join(repo_root, folder_path, rel_path))
    print(full_path)
    
    if not os.path.exists(full_path):
        subprocess.run([NOTEPADPP])  # just open N++ if missing
    else:
        subprocess.run([NOTEPADPP, full_path])
  • Problem:
    • Link clicked does not open the Notepad++ with file nor only it when the file not exist.
    • Commnd line does work, e.g. py npprel.py 25/h/62-categ-notes.md.
  • Solution:
    • Find Computer\HKEY_CURRENT_USER\Software\Classes\npprel\shell\open\command
    • Edit
      "C:\Users\Sparisoma Viridi\AppData\Local\Programs\Python\Python312\python.exe" "M:\butiran\setup\npprel\npprel.py" "%1"
    • Revision
      "C:\Users\Sparisoma Viridi\AppData\Local\Programs\Python\Python312\python.exe" "M:\butiran-src\setup\npprel\npprel.py" "%1"
    • Close Registry Editor.
  • Test
    • It works.