【问题标题】:How can I start powerline (within a global pyenv) on bash by referencing the powerline package path?如何通过引用 powerline 包路径在 bash 上启动 powerline(在全局 pyenv 中)?
【发布时间】:2020-04-29 04:30:22
【问题描述】:

我最近更新了我的全局 pyenv 以使用更新版本的 python 并启用其他一些功能。问题是这破坏了我的powerline(我在 bash 上使用的状态行插件)设置。以前我关注了他们的instructions,他们提到使用repository-root 来自pip show powerline-status。

问题在于,除了路径本身之外,命令还提供了许多其他信息。有没有办法让我的 .bash_profile 引用站点包路径,而不仅仅是硬编码的绝对路径?

【问题讨论】:

    标签: bash powerline


    【解决方案1】:

    一种方法是使用像python -c "import powerline as _; print(_.__path__[0])" 这样的命令的输出,它将打印出包目录。使用它作为基本路径,然后您可以调用 powerline.sh。这是我的 .bash_profile 中的内容:

    #Powerline shell invoke
    ## Note: if you've upgrade pyenv and have with old powerline installed, 
    ##       make sure you 'pyenv shell' to the older release and 
    ##       uninstall powerline first. Otherwise you'll get 'command not found' errors.
    ## 1. start daemon - done in 'quiet' mode for speed optimization
    powerline-daemon -q
    ## 2. start powerline shell
    export POWERLINE_SITE_PACKAGE_PATH=`python -c "import powerline as _; print(_.__path__[0])"`
    . $POWERLINE_SITE_PACKAGE_PATH/bindings/bash/powerline.sh
    

    警告:如果您经常使用 pyenv 本地环境,您可能需要比这更复杂的东西。

    注意:你能缓存这个值,这样我就不必每次都调用 python 了吗?理论上是的,但是在检查何时发生更改方面会变得复杂。您也可以只粘贴绝对路径。您需要将路径保存到文件并清除它。暂时保持简单。仅测试变量(通过执行类似if [ -z ${POWERLINE_SITE_PACKAGE_PATH+x} ] ; then .....; fi 的操作不会在 bash 会话中持续存在。

    受How do I find the location of my Python site-packages directory?启发的答案

    【讨论】:

      猜你喜欢
      • 2012-10-21
      • 2020-11-18
      • 2020-05-10
      • 2016-11-15
      • 1970-01-01
      • 2018-01-05
      • 1970-01-01
      • 2022-11-16
      • 2020-02-17
      相关资源
      最近更新 更多