Created
February 26, 2021 18:46
-
-
Save WaylonWalker/cb93b85e7ddcc802bed24f856d3a9587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.terminal.prompts import Prompts, Token | |
from pathlib import Path | |
import os | |
from platform import python_version | |
import subprocess | |
def get_branch(): | |
try: | |
return ( | |
subprocess.check_output( | |
"git branch --show-current", shell=True, stderr=subprocess.DEVNULL | |
) | |
.decode("utf-8") | |
.replace("\n", "") | |
) | |
except BaseException: | |
return "" | |
class MyPrompt(Prompts): | |
def in_prompt_tokens(self, cli=None): | |
return [ | |
(Token, ""), | |
(Token.OutPrompt, Path().absolute().stem), | |
(Token, " "), | |
(Token.Generic.Subheading, "↪"), | |
(Token.Generic.Subheading, get_branch()), | |
(Token, " "), | |
(Token.Prompt, "©"), | |
(Token.Prompt, os.environ["CONDA_DEFAULT_ENV"]), | |
(Token, " "), | |
(Token.Name.Class, "v" + python_version()), | |
(Token, " "), | |
(Token.Name.Entity, "ipython"), | |
(Token, "\n"), | |
( | |
Token.Prompt | |
if self.shell.last_execution_succeeded | |
else Token.Generic.Error, | |
"❯ ", | |
), | |
] | |
def out_prompt_tokens(self, cli=None): | |
return [] | |
ip = get_ipython() | |
ip.prompts = MyPrompt(ip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment