Show More
@@ -10,10 +10,11 b' Authors:' | |||
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | 12 | #----------------------------------------------------------------------------- |
|
13 |
# Copyright (C) 2008-200 |
|
|
13 | # Copyright (C) 2008-2010 The IPython Development Team | |
|
14 | 14 | # |
|
15 |
# Distributed under the terms of the BSD License. |
|
|
16 | # the file COPYING, distributed as part of this software. | |
|
15 | # Distributed under the terms of the BSD License. | |
|
16 | # | |
|
17 | # The full license is in the file COPYING.txt, distributed with this software. | |
|
17 | 18 | #----------------------------------------------------------------------------- |
|
18 | 19 | |
|
19 | 20 | #----------------------------------------------------------------------------- |
@@ -41,50 +42,61 b' from IPython.utils.warn import warn, error' | |||
|
41 | 42 | shell_line_split = re.compile(r'^(\s*)(\S*\s*)(.*$)') |
|
42 | 43 | |
|
43 | 44 | def default_aliases(): |
|
44 | # Make some aliases automatically | |
|
45 | # Prepare list of shell aliases to auto-define | |
|
45 | """Return list of shell aliases to auto-define. | |
|
46 | """ | |
|
47 | # Note: the aliases defined here should be safe to use on a kernel | |
|
48 | # regardless of what frontend it is attached to. Frontends that use a | |
|
49 | # kernel in-process can define additional aliases that will only work in | |
|
50 | # their case. For example, things like 'less' or 'clear' that manipulate | |
|
51 | # the terminal should NOT be declared here, as they will only work if the | |
|
52 | # kernel is running inside a true terminal, and not over the network. | |
|
53 | ||
|
46 | 54 | if os.name == 'posix': |
|
47 |
default_aliases = ('mkdir |
|
|
48 |
'mv |
|
|
49 |
'cat |
|
|
50 |
|
|
|
51 | 'ls ls -F', | |
|
52 | # long ls | |
|
53 | 'll ls -lF') | |
|
54 | # Extra ls aliases with color, which need special treatment on BSD | |
|
55 | # variants | |
|
56 | ls_extra = ( # color ls | |
|
57 |
'l |
|
|
58 | # ls normal files only | |
|
59 | 'lf ls -F -o --color %l | grep ^-', | |
|
60 | # ls symbolic links | |
|
61 | 'lk ls -F -o --color %l | grep ^l', | |
|
62 | # directories or links to directories, | |
|
63 | 'ldir ls -F -o --color %l | grep /$', | |
|
64 | # things which are executable | |
|
65 | 'lx ls -F -o --color %l | grep ^-..x', | |
|
66 |
|
|
|
67 | # The BSDs don't ship GNU ls, so they don't understand the | |
|
68 | # --color switch out of the box | |
|
69 | if 'bsd' in sys.platform: | |
|
70 | ls_extra = ( # ls normal files only | |
|
71 |
'l |
|
|
72 |
|
|
|
73 |
'l |
|
|
74 |
|
|
|
75 |
'l |
|
|
76 |
|
|
|
77 |
'l |
|
|
78 |
|
|
|
79 | default_aliases = default_aliases + ls_extra | |
|
80 | elif os.name in ['nt','dos']: | |
|
81 |
default_aliases = |
|
|
82 | 'ddir dir /ad /on', 'ldir dir /ad /on', | |
|
83 | 'mkdir mkdir','rmdir rmdir','echo echo', | |
|
84 | 'ren ren','cls cls','copy copy') | |
|
55 | default_aliases = [('mkdir', 'mkdir'), ('rmdir', 'rmdir'), | |
|
56 | ('mv', 'mv -i'), ('rm', 'rm -i'), ('cp', 'cp -i'), | |
|
57 | ('cat', 'cat'), | |
|
58 | ] | |
|
59 | # Useful set of ls aliases. The GNU and BSD options are a little | |
|
60 | # different, so we make aliases that provide as similar as possible | |
|
61 | # behavior in ipython, by passing the right flags for each platform | |
|
62 | if sys.platform.startswith('linux'): | |
|
63 | ls_aliases = [('ls', 'ls -F --color'), | |
|
64 | # long ls | |
|
65 | ('ll', 'ls -F -o --color'), | |
|
66 | # ls normal files only | |
|
67 | ('lf', 'ls -F -o --color %l | grep ^-'), | |
|
68 | # ls symbolic links | |
|
69 | ('lk', 'ls -F -o --color %l | grep ^l'), | |
|
70 | # directories or links to directories, | |
|
71 | ('ldir', 'ls -F -o --color %l | grep /$'), | |
|
72 | # things which are executable | |
|
73 | ('lx', 'ls -F -o --color %l | grep ^-..x'), | |
|
74 | ] | |
|
75 | else: | |
|
76 | # BSD, OSX, etc. | |
|
77 | ls_aliases = [('ls', 'ls -F'), | |
|
78 | # long ls | |
|
79 | ('ll', 'ls -F -l'), | |
|
80 | # ls normal files only | |
|
81 | ('lf', 'ls -F -l %l | grep ^-'), | |
|
82 | # ls symbolic links | |
|
83 | ('lk', 'ls -F -l %l | grep ^l'), | |
|
84 | # directories or links to directories, | |
|
85 | ('ldir', 'ls -F -l %l | grep /$'), | |
|
86 | # things which are executable | |
|
87 | ('lx', 'ls -F -l %l | grep ^-..x'), | |
|
88 | ] | |
|
89 | default_aliases = default_aliases + ls_aliases | |
|
90 | elif os.name in ['nt', 'dos']: | |
|
91 | default_aliases = [('ls', 'dir /on'), | |
|
92 | ('ddir', 'dir /ad /on'), ('ldir', 'dir /ad /on'), | |
|
93 | ('mkdir', 'mkdir'), ('rmdir', 'rmdir'), | |
|
94 | ('echo', 'echo'), ('ren', 'ren'), ('copy', 'copy'), | |
|
95 | ] | |
|
85 | 96 | else: |
|
86 |
default_aliases = |
|
|
87 | return [s.split(None,1) for s in default_aliases] | |
|
97 | default_aliases = [] | |
|
98 | ||
|
99 | return default_aliases | |
|
88 | 100 | |
|
89 | 101 | |
|
90 | 102 | class AliasError(Exception): |
@@ -94,12 +106,10 b' class AliasError(Exception):' | |||
|
94 | 106 | class InvalidAliasError(AliasError): |
|
95 | 107 | pass |
|
96 | 108 | |
|
97 | ||
|
98 | 109 | #----------------------------------------------------------------------------- |
|
99 | 110 | # Main AliasManager class |
|
100 | 111 | #----------------------------------------------------------------------------- |
|
101 | 112 | |
|
102 | ||
|
103 | 113 | class AliasManager(Configurable): |
|
104 | 114 | |
|
105 | 115 | default_aliases = List(default_aliases(), config=True) |
@@ -113,10 +123,7 b' class AliasManager(Configurable):' | |||
|
113 | 123 | self.init_aliases() |
|
114 | 124 | |
|
115 | 125 | def __contains__(self, name): |
|
116 |
|
|
|
117 | return True | |
|
118 | else: | |
|
119 | return False | |
|
126 | return name in self.alias_table | |
|
120 | 127 | |
|
121 | 128 | @property |
|
122 | 129 | def aliases(self): |
@@ -231,7 +238,6 b' class AliasManager(Configurable):' | |||
|
231 | 238 | then: |
|
232 | 239 | |
|
233 | 240 | baz huhhahhei -> bar /tmp huhhahhei |
|
234 | ||
|
235 | 241 | """ |
|
236 | 242 | line = fn + " " + rest |
|
237 | 243 |
@@ -115,6 +115,28 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
115 | 115 | toggle_set_term_title(False) |
|
116 | 116 | |
|
117 | 117 | #------------------------------------------------------------------------- |
|
118 | # Things related to aliases | |
|
119 | #------------------------------------------------------------------------- | |
|
120 | ||
|
121 | def init_alias(self): | |
|
122 | # The parent class defines aliases that can be safely used with any | |
|
123 | # frontend. | |
|
124 | super(TerminalInteractiveShell, self).init_alias() | |
|
125 | ||
|
126 | # Now define aliases that only make sense on the terminal, because they | |
|
127 | # need direct access to the console in a way that we can't emulate in | |
|
128 | # GUI or web frontend | |
|
129 | if os.name == 'posix': | |
|
130 | aliases = [('clear', 'clear'), ('more', 'more'), ('less', 'less'), | |
|
131 | ('man', 'man')] | |
|
132 | elif os.name == 'nt': | |
|
133 | aliases = [('cls', 'cls')] | |
|
134 | ||
|
135 | ||
|
136 | for name, cmd in aliases: | |
|
137 | self.alias_manager.define_alias(name, cmd) | |
|
138 | ||
|
139 | #------------------------------------------------------------------------- | |
|
118 | 140 | # Things related to the banner and usage |
|
119 | 141 | #------------------------------------------------------------------------- |
|
120 | 142 |
General Comments 0
You need to be logged in to leave comments.
Login now