{"id":20592383,"url":"https://github.com/valodim/zsh-python-mode","last_synced_at":"2025-07-19T08:33:58.754Z","repository":{"id":17342017,"uuid":"20113357","full_name":"Valodim/zsh-python-mode","owner":"Valodim","description":"ui frontend for interactive use of zyx's zpython zsh module","archived":false,"fork":false,"pushed_at":"2014-05-23T23:17:50.000Z","size":216,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-06T13:48:13.326Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Valodim.png","metadata":{"files":{"readme":"readme.mkd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-23T20:40:27.000Z","updated_at":"2015-08-03T13:07:30.000Z","dependencies_parsed_at":"2022-09-25T08:22:59.104Z","dependency_job_id":null,"html_url":"https://github.com/Valodim/zsh-python-mode","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Valodim/zsh-python-mode","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Valodim%2Fzsh-python-mode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Valodim%2Fzsh-python-mode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Valodim%2Fzsh-python-mode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Valodim%2Fzsh-python-mode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Valodim","download_url":"https://codeload.github.com/Valodim/zsh-python-mode/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Valodim%2Fzsh-python-mode/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265905116,"owners_count":23846696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T07:43:40.897Z","updated_at":"2025-07-19T08:33:58.733Z","avatar_url":"https://github.com/Valodim.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zsh-python-mode\n\nDisclaimer: This entire thing is a heap of half-baked, unfinished, not well\ndocumented code.  Don't judge me bro.\n\nThis bit of zsh configuration aims to provide a ui frontend for seamless use of\npython in an interactive zsh session, making use of zyx's excellent\n[zsh/zpython] module. That module is (at the time of this writing) not part of\nthe regular zsh distribution, so you will likely have to compile it yourself.\nIt should work with the unmodified source from zyx's [repository].\n\nThis was kind of a weekend project for me when I needed a break from other\nstuff. I'm not sure if this feature ever finds its way into my workflow, it\nmight just as well turn out to be fruitless endeavour.\n\nAnyways I still find the idea rather interesting, so I decided to take a couple\nscreenshots and upload it. If you have some ideas on what could be done\ndifferently or nicer (especially with the variable integration parts), hit me\nup in #zsh on freenode :)\n\n\n## The gist of it\n\nThe entire thing is pretty much just one widget, `zpy-enable`. Installation\nboils down to copying the zpy-enable file into your fpath (or adding the\nrepository dir to $fpath), then autoloading and binding the widget. See\n`example.config.zsh` for more on this.\n\nCalling this widget will enter a mode that interprets commands as python rather\nthan zsh.  It moves a few things around, but will generally try to change as\nlittle in actual editing behavior as possible. The mode will stay enabled until\n^D is pressed on an empty line, the zpy-enable widget is called again, or the\nline is aborted (^C).\n\nSyntax highlighting requires the zsh-syntax-highlighting loaded and [pygments]\ninstalled to work. To get completion support, [jedi] needs to be installed.\n\n![completion screenshot](screenshots/zpy_completion.png)\n\n\n## Variable interpolation\n\nThere are two syntax extensions added to interactively executed python code,\nfor a more seamless integration. Firstly, expressions of the form `$var`\nanywhere in the code are replaced by `zsh.getvalue(\"var\")`. While this is a\nfairly hackish way to go about it, this results in fairly natural variable\ninterpolation, allowing well-typed use in more complex expressions with proper\nscoping.\n\n![interpolation screenshot](screenshots/zpy_interpolation.png)\n\nSecondly, the same type of expression at the beginning of a line followed by an\nassignment operator as in `$var = expr` will be replaced by\n`zsh.setvariable(\"word\", expr)`. This is even more hackish, doesn't work\nanywhere in expressions or anything, but provides a convenient way to assign\nzsh variables. For a more robust method, zpython can bind python variables to\nzsh special variables.\n\n![assignandspecial screenshot](screenshots/zpy_assignandspecial.png)\n\n## Hints and caveats\n\n* the python session is bound to the zsh process. To reset it, run `exec zsh`\n\n* variable interpolation also replaces $word inside strings, leading to a\n  to a parse error or even undefined behavior. I plan to fix this and have\n  a couple of ways to go about it in mind but none yet that really feels\n  right. leaving this as a todo for now.\n* getting ^C, ^D, and ^M to behave involved a number of rather ugly hacks. I'm\n  happy with the resulting behavior, but there might be corner cases I didn't\n  take into consideration.\n* multiline commands work weirdly and output will often be obscured by the\n  prompt. this is a consequence of the zle recursive-edit technique used,\n  unfortunately I couldn't get this to behave properly. :(\n\n\n[zsh/zpython]:  http://www.zsh.org/mla/workers/2013/msg00055.html\n[repository]: https://bitbucket.org/ZyX_I/zsh/src\n[pygments]: http://pygments.org/\n[jedi]: http://jedi.jedidjah.ch/en/latest/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalodim%2Fzsh-python-mode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalodim%2Fzsh-python-mode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalodim%2Fzsh-python-mode/lists"}