Skip to content

Instantly share code, notes, and snippets.

@cyrex562
Created August 22, 2020 20:02
Show Gist options
  • Save cyrex562/310153239be426a727db8854356c37e6 to your computer and use it in GitHub Desktop.
Save cyrex562/310153239be426a727db8854356c37e6 to your computer and use it in GitHub Desktop.
Install powerline status on Linux
import sys
import subprocess
from subprocess import CompletedProcess
import logging
from typing import List
from pathlib import Path
import os
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
def run_cmd(cmd: List[str]) -> str:
result: CompletedProcess = subprocess.run(cmd, capture_output=True)
logging.debug("result: %s", result)
logging.debug("stdout: %s", result.stdout)
if result.returncode != 0:
logging.error("call failed, stderr: %s", result.stderr)
raise RuntimeError("")
return result.stdout.decode()
def run() -> int:
# install python package
run_cmd(["sudo", "pip3", "install", "powerline-status"])
# find package
find_result = run_cmd(["find", "/usr/local", "-name", "powerline.sh"])
lines = find_result.splitlines()
bash_line = ""
for line in lines:
if "bash" in line:
bash_line = line.strip()
logging.debug("found bash shell script for powerline")
break
if bash_line == "":
raise RuntimeError("didnt fine an instance of powerline.sh for bash")
bashrc_lines = f"""
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
source {bash_line}
"""
# edit bashrc
bashrc_edited = False
bashrc_path = str(Path.home())
bashrc_path = os.path.join(bashrc_path, ".bashrc")
with open(bashrc_path, "r") as fd:
lines = fd.readlines()
for line in lines:
if "powerline-daemon -q" in line:
bashrc_edited = True
break
if bashrc_edited is False:
with open(bashrc_path, "a") as fd:
fd.write(bashrc_lines)
logging.debug("updated bashrc file")
else:
logging.warning("powerline stuff already in bashrc")
return 0
if __name__ == "__main__":
sys.exit(run())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment