##// END OF EJS Templates
Add --term-title-format flag to customize terminal title format
Tory Haavik -
Show More
@@ -0,0 +1,2 b''
1 An additional flag `--term-title-format` is introduced to allow the user to control the format of the terminal
2 title. It is specified as a python format string, and currently the only variable it will format is `{cwd}`.
@@ -352,7 +352,7 b' class OSMagics(Magics):'
352 try:
352 try:
353 os.chdir(os.path.expanduser(ps))
353 os.chdir(os.path.expanduser(ps))
354 if hasattr(self.shell, 'term_title') and self.shell.term_title:
354 if hasattr(self.shell, 'term_title') and self.shell.term_title:
355 set_term_title('IPython: ' + abbrev_cwd())
355 set_term_title(self.shell.term_title_format.format(cwd=abbrev_cwd()))
356 except OSError:
356 except OSError:
357 print(sys.exc_info()[1])
357 print(sys.exc_info()[1])
358 else:
358 else:
@@ -365,7 +365,7 b' class OSMagics(Magics):'
365 else:
365 else:
366 os.chdir(self.shell.home_dir)
366 os.chdir(self.shell.home_dir)
367 if hasattr(self.shell, 'term_title') and self.shell.term_title:
367 if hasattr(self.shell, 'term_title') and self.shell.term_title:
368 set_term_title('IPython: ' + '~')
368 set_term_title(self.shell.term_title_format.format(cwd="~"))
369 cwd = os.getcwd()
369 cwd = os.getcwd()
370 dhist = self.shell.user_ns['_dh']
370 dhist = self.shell.user_ns['_dh']
371
371
@@ -179,6 +179,11 b' class TerminalInteractiveShell(InteractiveShell):'
179 help="Automatically set the terminal title"
179 help="Automatically set the terminal title"
180 ).tag(config=True)
180 ).tag(config=True)
181
181
182 term_title_format = Unicode("IPython: {cwd}",
183 help="Customize the terminal title format. This is a python format string. " +
184 "Available substitutions are: {cwd}."
185 ).tag(config=True)
186
182 display_completions = Enum(('column', 'multicolumn','readlinelike'),
187 display_completions = Enum(('column', 'multicolumn','readlinelike'),
183 help= ( "Options for displaying tab completions, 'column', 'multicolumn', and "
188 help= ( "Options for displaying tab completions, 'column', 'multicolumn', and "
184 "'readlinelike'. These options are for `prompt_toolkit`, see "
189 "'readlinelike'. These options are for `prompt_toolkit`, see "
@@ -206,7 +211,7 b' class TerminalInteractiveShell(InteractiveShell):'
206 # Enable or disable the terminal title.
211 # Enable or disable the terminal title.
207 if self.term_title:
212 if self.term_title:
208 toggle_set_term_title(True)
213 toggle_set_term_title(True)
209 set_term_title('IPython: ' + abbrev_cwd())
214 set_term_title(self.term_title_format.format(cwd=abbrev_cwd()))
210 else:
215 else:
211 toggle_set_term_title(False)
216 toggle_set_term_title(False)
212
217
General Comments 0
You need to be logged in to leave comments. Login now