summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-04-02 12:42:09 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-04-02 12:42:09 -0400
commit91a861dc35367a48d8a4cc33ac133f49bc185538 (patch)
treef74e37bbee7c1694857988449a05b7aff1fa1488 /cmd2.py
parent760785317ec1ffb7a5b1e0f01723f5faf94e3c7a (diff)
downloadcmd2-git-91a861dc35367a48d8a4cc33ac133f49bc185538.tar.gz
Added ability to query individual alias
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/cmd2.py b/cmd2.py
index 9ddd5fc1..0e2e9c36 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -2745,15 +2745,20 @@ class Cmd(cmd.Cmd):
def do_alias(self, arglist):
"""Define or display aliases
-Usage: Usage: alias [<name> <value>]
+Usage: Usage: alias [name] | [<name> <value>]
Where:
- name - name of the alias being added or edited
- value - what the alias will be resolved to
+ name - name of the alias being looked up, added, or edited
+ value - what the alias will be resolved to (if adding or editing)
this can contain spaces and does not need to be quoted
Without arguments, 'alias' prints a list of all aliases in a reusable form which
can be outputted to a startup_script to preserve aliases across sessions.
+ With one argument, 'alias' shows the value of the specified alias.
+ Example: alias ls (Prints the value of the alias called 'ls' if it exists)
+
+ With two or more arguments, 'alias' creates or replaces an alias.
+
Example: alias ls !ls -lF
If you want to use redirection or pipes in the alias, then either quote the tokens with these
@@ -2769,8 +2774,16 @@ Usage: Usage: alias [<name> <value>]
for cur_alias in self.aliases:
self.poutput("alias {} {}".format(cur_alias, self.aliases[cur_alias]))
+ # The user is looking up an alias
+ elif len(arglist) == 1:
+ name = arglist[0]
+ if name in self.aliases:
+ self.poutput("alias {} {}".format(name, self.aliases[name]))
+ else:
+ self.perror("Alias '{}' not found".format(name), traceback_war=False)
+
# The user is creating an alias
- elif len(arglist) >= 2:
+ else:
name = arglist[0]
value = ' '.join(arglist[1:])
@@ -2785,9 +2798,6 @@ Usage: Usage: alias [<name> <value>]
self.aliases[name] = value
self.poutput("Alias created")
- else:
- self.do_help('alias')
-
def complete_alias(self, text, line, begidx, endidx):
""" Tab completion for alias """
index_dict = \