From f88f4a003d1f1b62cf503922d4e2ac6da7cb6c25 Mon Sep 17 00:00:00 2001 From: TheK4n Date: Mon, 30 May 2022 14:07:50 +0300 Subject: [PATCH] add ipython --- Makefile | 5 +++ sub/ipython/ipython_config.py | 57 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 sub/ipython/ipython_config.py diff --git a/Makefile b/Makefile index 4b37212..a7bdb0c 100644 --- a/Makefile +++ b/Makefile @@ -80,6 +80,11 @@ bat: mkdir -p ~/.config/bat ln -s $(PWD)/sub/bat/config ~/.config/bat/config +ipython: + test -d ~/.ipython || \ + mkdir -p ~/.ipython/profile_default + ln -s $(PWD)/sub/ipython/ipython_config.py ~/.ipython/profile_default/ipython_config.py + font: mkdir -p ~/.local/share/fonts cd ~/.local/share/fonts diff --git a/sub/ipython/ipython_config.py b/sub/ipython/ipython_config.py new file mode 100644 index 0000000..69f6ebf --- /dev/null +++ b/sub/ipython/ipython_config.py @@ -0,0 +1,57 @@ +from IPython.terminal.prompts import Prompts, Token +import subprocess +from pathlib import Path +import os +from platform import python_version + + +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 CustomPrompt(Prompts): + + def in_prompt_tokens(self, cli=None): + return [ + (Token, "\n┌──("), + (Token.Name.Class, os.getlogin()), + (Token.Prompt, "@"), + (Token.Name.Class, "ipython v" + python_version()), + (Token, ")-["), + (Token.OutPrompt, os.getcwd()), + (Token, "]"), + (Token.Generic.Subheading, get_branch()), + (Token, " "), + (Token, "\n└─"), + ( + Token.Prompt + if self.shell.last_execution_succeeded + else Token.Generic.Error, + "λ ", + ), + ] + + def out_prompt_tokens(self, cli=None): + return [(Token.Prompt, ''), ] + + def continuation_prompt_tokens(self, cli=None, width=None): + return [(Token.Prompt, ''), ] + + +c = get_config() + +c.TerminalInteractiveShell.prompts_class = CustomPrompt +c.TerminalInteractiveShell.separate_in = '' +c.TerminalInteractiveShell.confirm_exit = False +c.TerminalIPythonApp.display_banner = False + +q = exit