Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions IPython/core/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2456,19 +2456,15 @@ def magic_alias(self, parameter_s = ''):
alias can not be executed until 'del foo' removes the Python variable.

You can use the %l specifier in an alias definition to represent the
whole line when the alias is called. For example:

In [2]: alias bracket echo "Input in brackets: <%l>"
In [3]: bracket hello world
Input in brackets: <hello world>
whole line when the alias is called.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this example been removed? It's a helpful addition to the bit above it.

You can also define aliases with parameters using %s specifiers (one
per parameter):

In [1]: alias parts echo first %s second %s
In [2]: %parts A B
In [2]: parts A B
first A second B
In [3]: %parts A
In [3]: parts A
Incorrect number of arguments: 2 expected.
parts is an alias to: 'echo first %s second %s'

Expand All @@ -2488,6 +2484,44 @@ def magic_alias(self, parameter_s = ''):
A Python string
In [9]: show $$PATH
/usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:...
example:
-------
explanation::

here in this example we are aliasing the command ls with lst
so that if we want to list the directories we can use the command lst.


In [1]: alias lst ls
In [2]: lst
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the best example - you can already use ls directly in IPython.

COPYING.txt ipython.egg-info/ README.txt setupbase.pyc setup.py*
docs/ ipython.py* scripts/ setupegg.py* tools/
IPython/ MANIFEST.in setupbase.py setupext/

In [1]: alias manual mkdir
In [2]: manual
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you try running this, it doesn't actually do this.

MKDIR(1) User Commands MKDIR(1)

NAME
mkdir - make directories

SYNOPSIS
mkdir [OPTION]... DIRECTORY...

DESCRIPTION
Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options
too.

-m, --mode=MODE
set file mode (as in chmod), not a=rwx - umask

-p, --parents
no error if existing, make parent directories as needed

-v, --verbose
print a message for each created directory

You can use the alias facility to acess all of $PATH. See the %rehash
and %rehashx functions, which automatically create aliases for the
Expand Down