hsh :: command :: Prog :: Class Prog
[hide private]
[frames] | no frames]

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:

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.

Instance Methods [hide private]
 
__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.
 
expand_directives(self)
Only aliases can include directives.
 
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__

Class Variables [hide private]
  expl_cmd_re = re.compile(r'\.?\.?/')

Inherited from Token: commencer_ch, dquotable

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, do_aliases)
(Constructor)

 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

_parexp(self)

 

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.

expand(self)

 

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

expand_directives(self)

 

Only aliases can include directives.

Overrides: Token.expand_directives

completions(self, cloc)

 

Completions are filename or built-in completions, and are searched for across the entire path.

Overrides: Token.completions