
    l:i5                         d dl 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	 ddl
mZ ddlmZ  edd	      Z G d
 de      Zy)    N)
namedtuple   )warn)memoize)settings)PathShellConfigurationcontentpathreloadcan_configure_automaticallyc                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zed
        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)GenericzGeneric Shellc                     i S N selfs    M/var/www/html/bot/venv/lib/python3.12/site-packages/thefuck/shells/generic.pyget_aliaseszGeneric.get_aliases   s    	    c                     | j                         }|j                  d      d   }||v r|j                  |||   d      S |S )N r      )r   splitreplace)r   command_scriptaliasesbinarys       r   _expand_aliaseszGeneric._expand_aliases   sL    ""$%%c*1-W!))&'&/1EE!!r   c                 $    | j                  |      S )z'Prepares command before running in app.)r!   r   r   s     r   
from_shellzGeneric.from_shell   s    ##N33r   c                     |S )z&Prepares command for running in shell.r   r#   s     r   to_shellzGeneric.to_shell"   s    r   c                 $    dj                  |      S )NzPalias {0}='eval "$(TF_ALIAS={0} PYTHONIOENCODING=utf-8 thefuck "$(fc -ln -1)")"')formatr   
alias_names     r   	app_aliaszGeneric.app_alias&   s    //5vj/A	Br   c                 :    t        d       | j                  |      S )Nz(Instant mode not supported by your shell)r   r+   r)   s     r   instant_mode_aliaszGeneric.instant_mode_alias*   s    78~~j))r   c                      yN r   r   s    r   _get_history_file_namezGeneric._get_history_file_name.       r   c                      yr/   r   r#   s     r   _get_history_linezGeneric._get_history_line1   r2   r   c                 4    t        | j                               S r   )list_get_history_linesr   s    r   get_historyzGeneric.get_history4   s    D++-..r   c              #     K   | j                         }t        j                  j                  |      rt	        j
                  |ddd      5 }|j                         }t        j                  r|t        j                   d }|D ](  }| j                  |      j                         }|s%| * 	 ddd       yy# 1 sw Y   yxY ww)z Returns list of history entries.rzutf-8ignore)encodingerrorsN)r1   osr   isfileioopen	readlinesr   history_limit_script_from_historystrip)r   history_file_namehistory_filelineslineprepareds         r   r7   zGeneric._get_history_lines8   s      77977>>+,*C")(< '?K$..0))!8#9#9"9":;E! 'D#88> &	'' ' -' 's%   A	CAB8'B8.
C8C=Cc                 $    dj                  |      S )Nz && joinr   commandss     r   and_zGeneric.and_I       ||H%%r   c                 $    dj                  |      S )Nz || rL   rN   s     r   or_zGeneric.or_L   rQ   r   c                      y r   r   r   s    r   how_to_configurezGeneric.how_to_configureO   s    r   c                    | j                  |      }	 t        j                  |j                  dd            D cg c]  }|j                  dd       }}| j                  |      S c c}w # t        $ r |j                  d      }Y 2w xY w)z*Split the command using shell-like syntax.z\ z??r   )encode_utf8shlexr   r   
ValueErrordecode_utf8)r   commandencodedssplitteds        r   split_commandzGeneric.split_commandR   s    ""7+	*8=GOOTY[_D`8ab1		$.bHb ))	 c 	*}}S)H	*s"   'A+ A&A+ &A+ +BBc                 H    t         j                  r|j                  d      S |S Nutf8)sixPY2encoder   r[   s     r   rW   zGeneric.encode_utf8]   s    77>>&))r   c                 n    t         j                  r|D cg c]  }|j                  d       c}S |S c c}w ra   )rc   rd   decode)r   command_partsr]   s      r   rZ   zGeneric.decode_utf8b   s.    77.;<AHHV$<< =s   2c                 L    t         j                  rddlm} nddlm}  ||      S )z/Return a shell-escaped version of the string s.r   )quote)rc   rd   pipesrk   rX   )r   r]   rk   s      r   rk   zGeneric.quoteg   s     77##Qxr   c                     |S r   r   )r   rI   s     r   rD   zGeneric._script_from_historyq   s    r   c                      y)zAdds fixed command to shell history.

        In most of shells we change history on shell-level, but not
        all shells support it (Fish).

        Nr   rf   s     r   put_to_historyzGeneric.put_to_historyt   s    r   c                 
    g dS )z Returns shells builtin commands.)8aliasbgbindbreakbuiltincasecdr[   compgencompletecontinuedeclaredirsdisownechoenableevalexecexitexportfcfggetoptshashhelphistoryifjobskillletlocallogoutpopdprintfpushdpwdreadreadonlyreturnsetshiftshoptsourcesuspendtesttimestraptypetypesetulimitumaskunaliasunsetuntilwaitwhiler   r   s    r   get_builtin_commandszGeneric.get_builtin_commands|   s    * 	*r   c                      y)z(Returns the version of the current shellr0   r   r   s    r   _get_versionzGeneric._get_version   s    r   c                     	 | j                         }dj                  | j                  |      j                         S # t        $ r&}t        dj                  |             d}Y d}~Td}~ww xY w)z1Returns the name and version of the current shellz%Could not determine shell version: {}r0   Nz{} {})r   	Exceptionr   r(   friendly_namerstrip)r   versiones      r   infozGeneric.info   sb    	'')G t117;BBDD  	9@@CDG	s   < 	A+A&&A+c                 j    t        |||t        |      j                         j                               S )Nr
   )r	   r   
expanduserexists)r   r   r   r   s       r   _create_shell_configurationz#Generic._create_shell_configuration   s3    !(,T
(=(=(?(F(F(H	J 	Jr   N)__name__
__module____qualname__r   r   r!   r$   r&   r+   r-   r1   r4   r   r8   r7   rP   rS   rU   r_   rW   rZ   rk   rD   ro   r   r   r   r   r   r   r   r   r      s    #M"4B* / /'"&&	*


*EJr   r   )r@   r>   rX   rc   collectionsr   logsr   utilsr   confr   systemr   r	   objectr   r   r   r   <module>r      sG    	 	  
 "       4 7@ A JJf JJr   