MCPcopy Create free account
hub / github.com/ipython/ipython / alias

Method alias

IPython/core/magics/osm.py:98–182  ·  view source on GitHub ↗

Define an alias for a system command. '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd' Then, typing 'alias_name params' will execute the system command 'cmd params' (from your underlying operating system). Aliases have lower precedence than magic

(self, parameter_s='')

Source from the content-addressed store, hash-verified

96 @skip_doctest
97 @line_magic
98 def alias(self, parameter_s=''):
99 """Define an alias for a system command.
100
101 '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
102
103 Then, typing 'alias_name params' will execute the system command 'cmd
104 params' (from your underlying operating system).
105
106 Aliases have lower precedence than magic functions and Python normal
107 variables, so if 'foo' is both a Python variable and an alias, the
108 alias can not be executed until 'del foo' removes the Python variable.
109
110 You can use the %l specifier in an alias definition to represent the
111 whole line when the alias is called. For example::
112
113 In [2]: alias bracket echo "Input in brackets: <%l>"
114 In [3]: bracket hello world
115 Input in brackets: <hello world>
116
117 You can also define aliases with parameters using %s specifiers (one
118 per parameter)::
119
120 In [1]: alias parts echo first %s second %s
121 In [2]: %parts A B
122 first A second B
123 In [3]: %parts A
124 Incorrect number of arguments: 2 expected.
125 parts is an alias to: 'echo first %s second %s'
126
127 Note that %l and %s are mutually exclusive. You can only use one or
128 the other in your aliases.
129
130 Aliases expand Python variables just like system calls using ! or !!
131 do: all expressions prefixed with '$' get expanded. For details of
132 the semantic rules, see PEP-215:
133 http://www.python.org/peps/pep-0215.html. This is the library used by
134 IPython for variable expansion. If you want to access a true shell
135 variable, an extra $ is necessary to prevent its expansion by
136 IPython::
137
138 In [6]: alias show echo
139 In [7]: PATH='A Python string'
140 In [8]: show $PATH
141 A Python string
142 In [9]: show $$PATH
143 /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
144
145 You can use the alias facility to access all of $PATH. See the %rehashx
146 function, which automatically creates aliases for the contents of your
147 $PATH.
148
149 If called with no parameters, %alias prints the current alias table
150 for your system. For posix systems, the default aliases are 'cat',
151 'cp', 'mv', 'rm', 'rmdir', and 'mkdir', and other platform-specific
152 aliases are added. For windows-based systems, the default aliases are
153 'copy', 'ddir', 'echo', 'ls', 'ldir', 'mkdir', 'ren', and 'rmdir'.
154
155 You can see the definition of alias by adding a question mark in the

Callers

nothing calls this directly

Calls 3

define_aliasMethod · 0.80
flushMethod · 0.45
getdocMethod · 0.45

Tested by

no test coverage detected