Skip to content

Conversation

@Enprogames
Copy link

Sorry about the messy commit.

This allows for a python virtual environment to be displayed at the beginning of the powerline. This is basically achieved by calling the $VIRTUAL_ENV variable and seeing if it has a value. If it does, the venv_info variable is set to 'venv'. It then looks for a venv/pyvenv.cfg file, which is how the python-venv package stores its configuration. If this file has a prompt variable, it uses this as the prompt at the beginning of the powerline. This can be seen in the image below:

venv_powerbar

This is done with the following code on line 87:

function __powerline_python_virtual_env_prompt {
  local venv_path="$VIRTUAL_ENV"
  local color=${VIRTUAL_ENV_PROMPT_COLOR}
  local venv_info=""
  if [[ "$venv_path" != "" ]]; then

    if [[ -f "venv/pyvenv.cfg" ]]; then 
      shopt -s extglob
      configfile="venv/pyvenv.cfg" # set the actual path name of your (DOS or Unix) config file
      while IFS=' =' read -r lhs rhs
      do
          if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then
              rhs="${rhs%%\#*}"    # Del in line right comments
              rhs="${rhs%%*( )}"   # Del trailing spaces
              rhs="${rhs%\"*}"     # Del opening string quotes 
              rhs="${rhs#\"*}"     # Del closing string quotes 
              if [[ ! $lhs == *-* ]]; then
                declare $lhs="$rhs"
              fi
          fi
      done < $configfile
      eval prompt=$prompt
      venv_info="$prompt"
    else
      venv_info=$(basename ${venv_path})
    fi
  fi
  [[ -n "${venv_info}" ]] && echo "${venv_info}|${color}"
}

PeterShaws and others added 4 commits October 25, 2020 19:24
- Show NPM package name@version segment, if package.json is detected
- Add optional multiline capability (linebreak before and after prompt)
- Add optional short CWD display capability
- Add optional padding character sequence
- Change text color to black, for legibility across more terminal themes
- Incorporate change from PR#3 to speed up last_status
@Enprogames Enprogames force-pushed the feature/virtual-environment branch from 92d3b5f to 78fcab8 Compare August 30, 2021 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants