From 5567e00e33d8834ef2811472e9d30af2fea4791b 2017-05-11 21:01:03 From: Tory Haavik Date: 2017-05-11 21:01:03 Subject: [PATCH] Add --term-title-format flag to customize terminal title format --- diff --git a/IPython/core/magics/osm.py b/IPython/core/magics/osm.py index 9832127..72f264e 100644 --- a/IPython/core/magics/osm.py +++ b/IPython/core/magics/osm.py @@ -352,7 +352,7 @@ class OSMagics(Magics): try: os.chdir(os.path.expanduser(ps)) if hasattr(self.shell, 'term_title') and self.shell.term_title: - set_term_title('IPython: ' + abbrev_cwd()) + set_term_title(self.shell.term_title_format.format(cwd=abbrev_cwd())) except OSError: print(sys.exc_info()[1]) else: @@ -365,7 +365,7 @@ class OSMagics(Magics): else: os.chdir(self.shell.home_dir) if hasattr(self.shell, 'term_title') and self.shell.term_title: - set_term_title('IPython: ' + '~') + set_term_title(self.shell.term_title_format.format(cwd="~")) cwd = os.getcwd() dhist = self.shell.user_ns['_dh'] diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index cce643e..315d1f1 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -179,6 +179,11 @@ class TerminalInteractiveShell(InteractiveShell): help="Automatically set the terminal title" ).tag(config=True) + term_title_format = Unicode("IPython: {cwd}", + help="Customize the terminal title format. This is a python format string. " + + "Available substitutions are: {cwd}." + ).tag(config=True) + display_completions = Enum(('column', 'multicolumn','readlinelike'), help= ( "Options for displaying tab completions, 'column', 'multicolumn', and " "'readlinelike'. These options are for `prompt_toolkit`, see " @@ -206,7 +211,7 @@ class TerminalInteractiveShell(InteractiveShell): # Enable or disable the terminal title. if self.term_title: toggle_set_term_title(True) - set_term_title('IPython: ' + abbrev_cwd()) + set_term_title(self.term_title_format.format(cwd=abbrev_cwd())) else: toggle_set_term_title(False) diff --git a/docs/source/whatsnew/pr/term-title-format-feature.rst b/docs/source/whatsnew/pr/term-title-format-feature.rst new file mode 100644 index 0000000..68de11c --- /dev/null +++ b/docs/source/whatsnew/pr/term-title-format-feature.rst @@ -0,0 +1,2 @@ +An additional flag `--term-title-format` is introduced to allow the user to control the format of the terminal +title. It is specified as a python format string, and currently the only variable it will format is `{cwd}`.