From d9ae70a0583c54ccd0fc281a2f1d7d77215c850d Mon Sep 17 00:00:00 2001 From: theofficialgman <28281419+theofficialgman@users.noreply.github.com> Date: Sat, 29 Jul 2023 10:51:21 -0400 Subject: [PATCH] Powerline-Shell: use pipx, install globally, and bookworm compat work towards https://github.com/Botspot/pi-apps/issues/2401 --- apps/Powerline-Shell/install | 23 ++++++++++++++++++----- apps/Powerline-Shell/uninstall | 6 +++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/apps/Powerline-Shell/install b/apps/Powerline-Shell/install index d1548d3913..a15ff22e52 100755 --- a/apps/Powerline-Shell/install +++ b/apps/Powerline-Shell/install @@ -2,11 +2,24 @@ install_packages python3 python3-pip python3-dev fonts-powerline fonts-fantasque-sans || exit 1 -sudo pip3 install powerline-shell || error "Failed to install powerline shell with pip3" +if package_available pipx ;then + install_packages pipx python3-venv || exit 1 +elif package_available python3.8 ;then + install_packages python3.8 python3.8-venv || exit 1 + sudo -H python3.8 -m pip install pipx || exit 1 +else + error "pipx is not available so cannot install powerline-shell to python venv" +fi -#Remove new powerline ~/.bashrc function if already there -sed -i '/powerline-shell/d' ~/.bashrc +sudo PIPX_HOME=/usr/local/pipx PIPX_BIN_DIR=/usr/local/bin pipx install powerline-shell || error "Failed to install powerline shell with pipx" -#Add powerline to ~/.bashrc -echo 'if [ $TERM != linux ] && [[ ! $PROMPT_COMMAND =~ "powerline-shell" ]]; then PROMPT_COMMAND="PS1="\"""\$"(powerline-shell)"\""; $PROMPT_COMMAND" ; fi' >> ~/.bashrc +#Remove powerline-shell function from ~/.bashrc if already there +sed -i '/powerline-shell/d' ~/.bashrc +# Remove powerline-shell function from /etc/bash.bashrc if already there +sudo sed -i '/powerline-shell/d' /etc/bash.bashrc +#Add powerline to /etc/bash.bashrc +echo 'if [ $TERM != linux ] && [[ ! $PROMPT_COMMAND =~ "powerline-shell" ]]; then PROMPT_COMMAND="PS1="\"""\$"(powerline-shell)"\""; $PROMPT_COMMAND" ; fi' | sudo tee -a /etc/bash.bashrc > /dev/null || error "Could not modify /etc/bash.bashrc" +#Also add to users ~/.bashrc . Some terminals (eg: gnome-terminal) overwrite the PROMPT_COMMAND with their own contents after /etc/bash.bashrc so is necessary for them +#The following will only affect the current users install +echo 'if [ $TERM != linux ] && [[ ! $PROMPT_COMMAND =~ "powerline-shell" ]]; then PROMPT_COMMAND="PS1="\"""\$"(powerline-shell)"\""; $PROMPT_COMMAND" ; fi' | tee -a ~/.bashrc > /dev/null || error "Could not modify ~/.bashrc" diff --git a/apps/Powerline-Shell/uninstall b/apps/Powerline-Shell/uninstall index 217aa739f4..8eb6068a2f 100755 --- a/apps/Powerline-Shell/uninstall +++ b/apps/Powerline-Shell/uninstall @@ -1,6 +1,10 @@ #!/bin/bash +# note: do not check exit code from pipx since exit code is set to 1 if not already installed +sudo PIPX_HOME=/usr/local/pipx PIPX_BIN_DIR=/usr/local/bin pipx uninstall powerline-shell purge_packages || exit 1 -sudo pip3 uninstall -y powerline-shell +#Remove powerline-shell function from ~/.bashrc if already there sed -i '/powerline-shell/d' ~/.bashrc +# Remove powerline-shell function from /etc/bash.bashrc if already there +sudo sed -i '/powerline-shell/d' /etc/bash.bashrc