]> glassweightruler.freedombox.rocks Git - xdg-ninja.git/blobdiff - programs/python.json
Fix missing filename extension
[xdg-ninja.git] / programs / python.json
index 2841df996646c32a728e5ed462afa43e817efc6d..3aa547e7a0deeafb340a1b5b98d52899279830cc 100644 (file)
@@ -3,8 +3,8 @@
         {
             "path": "$HOME/.python_history",
             "movable": true,
         {
             "path": "$HOME/.python_history",
             "movable": true,
-            "help": "Export the following environment variables:\n\n```bash\nexport PYTHONSTARTUP=\"${XDG_CONFIG_HOME}/python/pythonrc\"\n```\n\nNow create the file _pythonrc_, and put the following code into it:\n\n```python\nimport os\nimport atexit\nimport readline\n\nhistory = os.path.join(os.environ['XDG_CACHE_HOME'], 'python_history')\ntry:\n    readline.read_history_file(history)\nexcept OSError:\n    pass\n\ndef write_history():\n    try:\n        readline.write_history_file(history)\n    except OSError:\n        pass\n\natexit.register(write_history)\n```\n\n_Note: This won't work if python is invoked with -i flag._\n\n_Credit:_ https://unix.stackexchange.com/a/675631/417527\n"
+            "help": "Export the following environment variables:\n\n```bash\nexport PYTHONSTARTUP=\"$HOME\"/python/pythonrc\n```\n\nNow create the file _~/python/pythonrc_, and put the following code into it:\n\n```python\ndef is_vanilla() -> bool:\n    import sys\n    return not hasattr(__builtins__, '__IPYTHON__') and 'bpython' not in sys.argv[0]\n\n\ndef setup_history():\n    import os\n    import atexit\n    import readline\n    from pathlib import Path\n\n    if state_home := os.environ.get('XDG_STATE_HOME'):\n        state_home = Path(state_home)\n    else:\n        state_home = Path.home() / '.local' / 'state'\n\n    history: Path = state_home / 'python_history'\n\n    readline.read_history_file(str(history))\n    atexit.register(readline.write_history_file, str(history))\n\n\nif is_vanilla():\n    setup_history()\n```\n\nFinally, create an empty file at _$XDG_STATE_HOME/python_history_\n\n_Note: This won't work if python is invoked with -i flag._\n\n_Credit:_ https://github.com/b3nj5m1n/xdg-ninja/issues/289#issuecomment-1666024202"
         }
     ],
     "name": "python"
         }
     ],
     "name": "python"
-}
\ No newline at end of file
+}