##// END OF EJS Templates
Add option to force silence %cd
Reuben Morais -
Show More
@@ -0,0 +1,15 b''
1 OSMagics.cd_force_quiet configuration option
2 ============================================
3
4 You can set this option to force the %cd magic to behave as if ``-q`` was passed:
5 ::
6
7 In [1]: cd /
8 /
9
10 In [2]: %config OSMagics.cd_force_quiet = True
11
12 In [3]: cd /tmp
13
14 In [4]:
15
@@ -24,6 +24,7 b' from IPython.testing.skipdoctest import skip_doctest'
24 from IPython.utils.openpy import source_to_unicode
24 from IPython.utils.openpy import source_to_unicode
25 from IPython.utils.process import abbrev_cwd
25 from IPython.utils.process import abbrev_cwd
26 from IPython.utils.terminal import set_term_title
26 from IPython.utils.terminal import set_term_title
27 from traitlets import Bool
27
28
28
29
29 @magics_class
30 @magics_class
@@ -31,6 +32,10 b' class OSMagics(Magics):'
31 """Magics to interact with the underlying OS (shell-type functionality).
32 """Magics to interact with the underlying OS (shell-type functionality).
32 """
33 """
33
34
35 cd_force_quiet = Bool(False,
36 help="Force %cd magic to be quiet even if -q is not passed."
37 ).tag(config=True)
38
34 def __init__(self, shell=None, **kwargs):
39 def __init__(self, shell=None, **kwargs):
35
40
36 # Now define isexec in a cross platform manner.
41 # Now define isexec in a cross platform manner.
@@ -414,7 +419,7 b' class OSMagics(Magics):'
414 if oldcwd != cwd:
419 if oldcwd != cwd:
415 dhist.append(cwd)
420 dhist.append(cwd)
416 self.shell.db['dhist'] = compress_dhist(dhist)[-100:]
421 self.shell.db['dhist'] = compress_dhist(dhist)[-100:]
417 if not 'q' in opts and self.shell.user_ns['_dh']:
422 if not 'q' in opts and not self.cd_force_quiet and self.shell.user_ns['_dh']:
418 print(self.shell.user_ns['_dh'][-1])
423 print(self.shell.user_ns['_dh'][-1])
419
424
420 @line_magic
425 @line_magic
@@ -23,7 +23,7 b' from IPython.core.error import UsageError'
23 from IPython.core.magic import (Magics, magics_class, line_magic,
23 from IPython.core.magic import (Magics, magics_class, line_magic,
24 cell_magic,
24 cell_magic,
25 register_line_magic, register_cell_magic)
25 register_line_magic, register_cell_magic)
26 from IPython.core.magics import execution, script, code, logging
26 from IPython.core.magics import execution, script, code, logging, osm
27 from IPython.testing import decorators as dec
27 from IPython.testing import decorators as dec
28 from IPython.testing import tools as tt
28 from IPython.testing import tools as tt
29 from IPython.utils.io import capture_output
29 from IPython.utils.io import capture_output
@@ -433,7 +433,7 b' def test_parse_options():'
433 nt.assert_equal(m.parse_options('foo', '')[1], 'foo')
433 nt.assert_equal(m.parse_options('foo', '')[1], 'foo')
434 nt.assert_equal(m.parse_options(u'foo', '')[1], u'foo')
434 nt.assert_equal(m.parse_options(u'foo', '')[1], u'foo')
435
435
436
436
437 def test_dirops():
437 def test_dirops():
438 """Test various directory handling operations."""
438 """Test various directory handling operations."""
439 # curpath = lambda :os.path.splitdrive(os.getcwd())[1].replace('\\','/')
439 # curpath = lambda :os.path.splitdrive(os.getcwd())[1].replace('\\','/')
@@ -453,6 +453,23 b' def test_dirops():'
453 os.chdir(startdir)
453 os.chdir(startdir)
454
454
455
455
456 def test_cd_force_quiet():
457 """Test OSMagics.cd_force_quiet option"""
458 _ip.config.OSMagics.cd_force_quiet = True
459 osmagics = osm.OSMagics(shell=_ip)
460
461 startdir = os.getcwd()
462 ipdir = os.path.realpath(_ip.ipython_dir)
463
464 try:
465 with tt.AssertNotPrints(ipdir):
466 osmagics.cd('"%s"' % ipdir)
467 with tt.AssertNotPrints(startdir):
468 osmagics.cd('-')
469 finally:
470 os.chdir(startdir)
471
472
456 def test_xmode():
473 def test_xmode():
457 # Calling xmode three times should be a no-op
474 # Calling xmode three times should be a no-op
458 xmode = _ip.InteractiveTB.mode
475 xmode = _ip.InteractiveTB.mode
General Comments 0
You need to be logged in to leave comments. Login now