Add pyenv support
This commit is contained in:
parent
655eb827e1
commit
d65948ca41
@ -633,9 +633,13 @@ For example, a revert. If there is no current operation, return nil."
|
||||
|
||||
(defun eshell-starship--current-venv ()
|
||||
"Return the name of the prompt string for the current venv.
|
||||
This requires pyvenv.el to work. Without it, return nil."
|
||||
(and (bound-and-true-p pyvenv-virtual-env-name)
|
||||
(format " (%s)" pyvenv-virtual-env-name)))
|
||||
This requires pyvenv.el or pyenv-mode to work."
|
||||
(concat
|
||||
(and (bound-and-true-p pyvenv-virtual-env-name)
|
||||
(format " (%s)" pyvenv-virtual-env-name))
|
||||
(and (fboundp 'pyenv-mode-version)
|
||||
(when-let ((ver (pyenv-mode-version)))
|
||||
(format " (%s)" ver)))))
|
||||
|
||||
(defun eshell-starship--python-status ()
|
||||
"Return the prompt string for the python module."
|
||||
@ -649,18 +653,32 @@ This requires pyvenv.el to work. Without it, return nil."
|
||||
"The previous `pyvenv-virtual-env' value.
|
||||
This does not mean anything if pyvenv.el is not installed.")
|
||||
|
||||
(defvar-local eshell-starship--python-last-pyenv nil
|
||||
"The return value of the last `pyenv-mode-version'.
|
||||
This does not mean anything if pyenv-mode is not installed.")
|
||||
|
||||
(defun eshell-starship--python-postcmd-action ()
|
||||
"The postcmd action for the python module."
|
||||
(when (and (boundp 'pyvenv-virtual-env)
|
||||
(not (equal eshell-starship--python-last-pyvenv
|
||||
pyvenv-virtual-env)))
|
||||
(setq eshell-starship--python-last-pyvenv pyvenv-virtual-env)
|
||||
(eshell-starship-clear-cache-for 'python)))
|
||||
(let ((need-clear nil))
|
||||
(when (and (boundp 'pyvenv-virtual-env)
|
||||
(not (equal eshell-starship--python-last-pyvenv
|
||||
pyvenv-virtual-env)))
|
||||
(setq eshell-starship--python-last-pyvenv pyvenv-virtual-env
|
||||
need-clear t))
|
||||
(when (fboundp 'pyenv-mode-version)
|
||||
(let ((cur-ver (pyenv-mode-version)))
|
||||
(when (not (equal eshell-starship--python-last-pyenv cur-ver))
|
||||
(setq eshell-starship--python-last-pyenv cur-ver
|
||||
need-clear t))))
|
||||
(when need-clear
|
||||
(eshell-starship-clear-cache-for 'python))))
|
||||
|
||||
(eshell-starship-defmodule python
|
||||
:extensions '("py" "ipynb")
|
||||
:predicate (lambda ()
|
||||
(bound-and-true-p pyvenv-virtual-env))
|
||||
(or (bound-and-true-p pyvenv-virtual-env)
|
||||
(and (fboundp 'pyenv-mode-version)
|
||||
(pyenv-mode-version))))
|
||||
:files '(".python-version" "Pipfile" "__init__.py" "pyproject.toml"
|
||||
"requirements.txt" "setup.py" "tox.ini" "pixi.toml")
|
||||
:prefix "via "
|
||||
|
Loading…
x
Reference in New Issue
Block a user