]> glassweightruler.freedombox.rocks Git - xdg-ninja.git/commitdiff
Add config for .python_history
authorb3nj4m1n <b3nj4m1n@gmx.net>
Wed, 18 May 2022 09:35:59 +0000 (11:35 +0200)
committerb3nj4m1n <b3nj4m1n@gmx.net>
Wed, 18 May 2022 09:35:59 +0000 (11:35 +0200)
programs/python.json [new file with mode: 0644]

diff --git a/programs/python.json b/programs/python.json
new file mode 100644 (file)
index 0000000..c4e02a3
--- /dev/null
@@ -0,0 +1,10 @@
+{
+    "files": [
+        {
+            "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_Credit:_ https://unix.stackexchange.com/a/675631/417527\n"
+        }
+    ],
+    "name": "python"
+}