hsh ::
command ::
Prog ::
Class Prog
|
|
Class Prog
object --+
|
Token --+
|
AggregateToken --+
|
ArgOrProg --+
|
Prog
Prog specifies what to run. It must be the first token of a
command.
Prog objects behave differently depending on if they are specifying a
program, builtin or alias. It would be desirable to use subclasses for
the three, but isn't straightforward because as text is entered the type
would change, resulting in a lot reparsing, and risk of infinite
loops.
The rules for choosing what to run are:
-
Supported syntax elements are expanded: single and double quoted
tokens, environment variables, named directories, job references.
Glob expansion is not permitted in Progs.
-
If the resultant text starts with '+' then a builtin is being
explicitly chosen, and if there's no such builtin, then nothing is
run.
-
If the resultant text starts with '/', './' or '../' then an external
program is specified. The program will be found absolutely or
relative to the current directory, and the PATH will not be
consulted.
-
Alias list is searched, and if the text matches, that alias is
expanded. The alias text is expanded as a full command, except that
the first token will not do alias expansion.
-
Builtin list is searched, and if the text matches, that builtin is
used.
-
Finally, the text will be searched for relative to all entries on the
PATH.
These rules depart from those of other shells (bash, zsh, ksh, tcsh)
in the case of a command name with a '/' in it. hsh will search for such
commands in subdirectories of path entries, while other shells will run
programs relative to the current directory. With a well-structured path
this does not represent a weakening of security, and in fact tightens
security in same cases. The traditional usage is still available by
prepending "./". Finally this allows namespacing of groups of
commands, for instance, all of the ImageMagick programs could be moved to
a subdirectory, so that their generic names would not be so confusing, or
the foomatic programs could have simplified names and go in their own
subdirectory.
As per shell tradition, external programs are searched only from the
path unless they start with './', '../', '/'. This is so that the user
isn't tricked into running something in the local directory by
mistake.
Glob expansion is not supported in Prog because multiple expansions
just opens risk of error, has non-obvious interaction with path search,
and does not seem particularly useful anyway. Other syntax which may
result in multiple expansion may also be precluded. This differs from
other shells which will look in the current directory when glob syntax is
used.
|
__init__(self,
do_aliases)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature |
|
|
|
_parexp(self)
Return the result of the parent expanding the subtokens. |
|
|
|
expand(self)
The command is expanded, with any glob characters causing an
exception. |
|
|
|
|
|
completions(self,
cloc)
Completions are filename or built-in completions, and are searched
for across the entire path. |
|
|
Inherited from ArgOrProg :
create_token
Inherited from AggregateToken :
__len__ ,
__str__ ,
dump ,
modify
Inherited from Token :
commences ,
terminated ,
terminates
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__subclasshook__
|
Inherited from object :
__class__
|
__init__(self,
do_aliases)
(Constructor)
|
|
x.__init__(...) initializes x; see x.__class__.__doc__ for
signature
- Overrides:
object.__init__
- (inherited documentation)
|
Return the result of the parent expanding the subtokens. Remove
escapes because Prog does not do glob expansion. Raise an exception if
the parent expands it to multiple tokens.
|
The command is expanded, with any glob characters causing an
exception. \ escapes are removed. If the command doesn't exist an empty
string is returned.
- Overrides:
Token.expand
|
Completions are filename or built-in completions, and are searched for
across the entire path.
- Overrides:
Token.completions
|