o
    Ďi(                     @   s   d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZ ddlZedZd	ej	ejeef  fd
dZG dd deZG dd deZG dd deZG dd deZdS )zE
System command aliases.

Authors:

* Fernando Perez
* Brian Granger
    N)Configurable   )
UsageError)ListInstance)errorz^(\s*)()(\S+)(.*$)returnc                  C   s|   t jdkr/g d} tjdrg d}ntjds tjdr%g d}ng d}| | } | S t jd	v r:g d
} | S g } | S )z1Return list of shell aliases to auto-define.
    posix)mkdirr   rmdirr   )mvr   )rmr   )cpr   )catr   linux))lszls -F --color)llzls -F -o --color)lfzls -F -o --color %l | grep ^-)lkzls -F -o --color %l | grep ^l)ldirzls -F -o --color %l | grep /$)lxz ls -F -o --color %l | grep ^-..xopenbsdnetbsd))r   zls -F)r   zls -F -l)r   zls -F -l %l | grep ^-)r   zls -F -l %l | grep ^l)r   zls -F -l %l | grep /$)r   zls -F -l %l | grep ^-..x))r   zls -F -G)r   zls -F -l -G)r   zls -F -l -G %l | grep ^-)r   zls -F -l -G %l | grep ^l)r   zls -F -G -l %l | grep /$)r   zls -F -l -G %l | grep ^-..x)ntdos))r   zdir /on)ddirdir /ad /on)r   r   r
   r   )echor   )renr    )copyr!   )osnamesysplatform
startswith)default_aliases
ls_aliases r)   N/home/jeff/fluffinator/venv/lib/python3.10/site-packages/IPython/core/alias.pyr'   +   s   





r'   c                   @      e Zd ZdS )
AliasErrorN__name__
__module____qualname__r)   r)   r)   r*   r,   t       r,   c                   @   r+   )InvalidAliasErrorNr-   r)   r)   r)   r*   r2   x   r1   r2   c                   @   s:   e Zd ZdZh dZdd Zdd Zdd Zdd
dZdS )AliaszCallable object storing the details of one alias.

    Instances are registered as magic functions to allow use of aliases.
    >   cdpopdaliasdhistpushdunaliasc                 C   s,   || _ || _|| _d|| _|  | _d S )NzAlias for `!{}`)shellr#   cmdformat__doc__validatenargs)selfr:   r#   r;   r)   r)   r*   __init__   s
   zAlias.__init__c                 C   s   | j | jv rtd| j  z| jjjd | j  }W n	 ty"   Y nw t|ts/td| j  t| j	t
s<td| j	 | j	d| j	d }|dkrX| j	ddkrXtd	|S )
z7Validate the alias, and return the number of arguments.z@The name %s can't be aliased because it is a keyword or builtin.linezAThe name %s can't be aliased because it is another magic command.z*An alias command must be a string, got: %r%s%%sr   %lzEThe %s and %l specifiers are mutually exclusive in alias definitions.)r#   	blacklistr2   r:   magics_managermagicsKeyError
isinstancer3   r;   strcountfind)r@   callerr?   r)   r)   r*   r>      s*   
zAlias.validatec                 C   s   d | j| jS )Nz<alias {} for {!r}>)r<   r#   r;   r@   r)   r)   r*   __repr__   s   zAlias.__repr__ c                 C   s   | j }| j}|ddkr|d|}d}|dkr-|ddkr&|dd}d||f }n-|d |}t||k rEtd| j|t|f d|t|d |  d		||d  f }| j
| d S )
NrE   r   rQ   rD   r   rC   z%s %sz+Alias <%s> requires %s arguments, %s given. )r;   r?   rM   replacesplitlenr   r#   tuplejoinr:   system)r@   restr;   r?   argsr)   r)   r*   __call__   s    *zAlias.__call__N)rQ   )	r.   r/   r0   r=   rF   rA   r>   rP   r[   r)   r)   r)   r*   r3   {   s    r3   c                       s   e Zd ZU ee jddZeed< eg djddZeed< edddZ	d fd	d
	Z
dd Zedd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Z  ZS )AliasManagerT)configr'   )default_valueuser_aliasesz1IPython.core.interactiveshell.InteractiveShellABC)
allow_noneNc                    sD   t t| jdd|i| | jd ur | jjjd | _|   d S d S )Nr:   rB   r)   )superr\   rA   r:   rG   rH   
linemagicsinit_aliases)r@   r:   kwargs	__class__r)   r*   rA      s
   
zAliasManager.__init__c                 C   sR   | j | j D ] \}}|dr | jd ur | jjdkr |dd}| || qd S )Nzls NoColorz --colorrQ   )r'   r_   r&   r:   colorsrS   soft_define_alias)r@   r#   r;   r)   r)   r*   rc      s   
zAliasManager.init_aliasesc                 C   s   dd | j  D S )Nc                 S   s$   g | ]\}}t |tr||jfqS r)   )rJ   r3   r;   ).0nfuncr)   r)   r*   
<listcomp>   s    z(AliasManager.aliases.<locals>.<listcomp>)rb   itemsrO   r)   r)   r*   aliases   s   zAliasManager.aliasesc              
   C   sF   z	|  || W dS  ty" } ztd|  W Y d}~dS d}~ww )z2Define an alias, but don't raise on an AliasError.zInvalid alias: %sN)define_aliasr,   r   )r@   r#   r;   er)   r)   r*   ri      s   zAliasManager.soft_define_aliasc                 C   s(   t | j||d}| jjj|d|d dS )zDefine a new alias after validating it.

        This will raise an :exc:`AliasError` if there are validation
        problems.
        )r:   r#   r;   rB   )
magic_kind
magic_nameN)r3   r:   rG   register_function)r@   r#   r;   rN   r)   r)   r*   rp      s   
zAliasManager.define_aliasc                 C   s    | j |d}t|tr|S dS )z9Return an alias, or None if no alias by that name exists.N)rb   getrJ   r3   )r@   r#   anamer)   r)   r*   	get_alias   s   zAliasManager.get_aliasc                 C   s   |  |duS )z?Return whether or not a given name has been defined as an aliasN)rw   r@   r#   r)   r)   r*   is_alias   s   zAliasManager.is_aliasc                 C   s"   |  |r| j|= d S td| )N%s is not an alias)ry   rb   
ValueErrorrx   r)   r)   r*   undefine_alias   s   
zAliasManager.undefine_aliasc                 C   s   | j D ]	\}}| | qd S N)ro   r|   )r@   r#   _r)   r)   r*   clear_aliases  s   zAliasManager.clear_aliasesc                 C   s    |  |}|r
|jS td| )z/Retrieve the command to which an alias expands.rz   )rw   r;   r{   )r@   r#   rN   r)   r)   r*   retrieve_alias  s   
zAliasManager.retrieve_aliasr}   )r.   r/   r0   r   r'   tag__annotations__r_   r   r:   rA   rc   propertyro   ri   rp   rw   ry   r|   r   r   __classcell__r)   r)   re   r*   r\      s"   
 

r\   )r=   r"   rer$   traitlets.config.configurabler   r   r   	traitletsr   r   loggingtypingtcompileshell_line_splitTuplerK   r'   	Exceptionr,   r2   objectr3   r\   r)   r)   r)   r*   <module>   s   
IH