
    k7i                         S r SSKrSSKJr  SSKJr  SSKJrJr  SSK	J
r
  S\S   S	\S
\4S jrS\S	\S\S   S
\4S jrS\S\4   S\4S jrg)zShell completion installation utilities.

This module handles the installation of completion scripts to shell-specific
locations and the updating of shell RC files to load completions.
    N)Callable)Path)	AnnotatedLiteral)	Parametershellzshbashfish	prog_namereturnc                 4   [         R                  " 5       nU S:X  a   US-  S-  nUR                  SSS9  USU 3-  $ U S:X  a"  US-  S	-  S
-  S-  nUR                  SSS9  XA-  $ U S:X  a"  US-  S-  S-  nUR                  SSS9  XQ S3-  $ [        SU  35      e)aC  Get the default completion script path for a given shell.

Parameters
----------
shell : Literal["zsh", "bash", "fish"]
    Shell type.
prog_name : str
    Program name for the completion script.

Returns
-------
Path
    Default installation path for the shell.

Raises
------
ValueError
    If shell type is unsupported.
r
   z.zshcompletionsT)parentsexist_ok_r   z.localsharezbash-completionr   z.configz.fishzUnsupported shell: )r   homemkdir
ValueError)r   r   r   zsh_completionsbash_completionsfish_completionss         U/home/james-whalen/.local/lib/python3.13/site-packages/cyclopts/completion/install.pyget_default_completion_pathr      s    ( 99;D~--7dT:1YK00	&(?W47HH=Xtd;++	&)+f4}Dtd;Ku"555.ug677    script_path)r   r
   c                     US:X  a"  [         R                  " 5       S-  nSU  SU  S3nO.US:X  a"  [         R                  " 5       S-  nSU  SU  S3nO[        eUR                  5       nUR	                  5       (       a6  UR                  5       nXE;   a  gU=(       a    UR                  S	5      (       + nOSnUR                  S
5       nU(       a  UR                  S	5        UR                  SU SU S	35        SSS5        g! , (       d  f       g= f)a]  Add source line to shell RC file to ensure completion is loaded.

Parameters
----------
script_path : Path
    Path to the completion script.
prog_name : str
    Program name for display in comments.
shell : Literal["bash", "zsh"]
    Shell type.

Returns
-------
bool
    True if the source line was added, False if it already existed or on error.
r   .bashrcz[ -f "z
" ] && . ""r
   .zshrcF
az# Load z completion
NT)	r   r   NotImplementedErrorresolveexists	read_textendswithopenwrite)r   r   r   rc_filesource_linecontentneeds_newlinefs           r   add_to_rc_filer1   4   s    " ))+	){m:k]!D	%))+({m:k]!D!!ooG~~##%!>(8(8(>$>	c	aGGDM	')M+bAB 

  
	
 s   1C??
Dinstall_completion_fn.add_to_startupc           
         ^ ^ SSS.S[         [        S   S-  [        5       4   S[         [        S-  [        SS/S94   4UU 4S	 jjjnU$ )
a  Create a command function for installing shell completion.

Parameters
----------
install_completion_fn : Callable
    Function that performs the actual installation (typically App.install_completion).
    Should accept (shell, output, add_to_startup) and return the installation path.
add_to_startup : bool
    Whether to add source line to shell RC file.

Returns
-------
Callable
    Command function that can be registered with App.command().
N)r   outputr   r	   r5   z-oz--output)namec                 V  > SSK JnJn  U c   U" 5       n T	" XTS9n[        SU 35        U S	:X  a  T(       a2  [        R                  " 5       S
-  n[        SU 35        [        S5        gUR                  n[        SU S35        [        S5        [        SU S35        [        S5        [        S5        gU S:X  a  T(       a2  [        R                  " 5       S-  n[        SU 35        [        S5        g[        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        [        S5        gU S:X  a  [        S 5        [        S!5        g[        e! U a2    [        S[        R
                  S9  [        R                  " S5         GNf = f)"a  Install shell completion for this application.

This command generates and installs the completion script to the appropriate
location for your shell. After installation, you may need to restart your
shell or source your shell configuration file.

Parameters
----------
shell : Literal["zsh", "bash", "fish"] | None
    Shell type for completion. If not specified, attempts to auto-detect current shell.
output : Path | None
    Output path for the completion script. If not specified, uses shell-specific default.
r   )ShellDetectionErrordetect_shellNz?Could not auto-detect shell. Please specify --shell explicitly.)file   )r   r5   r3   u#   ✓ Completion script installed to r
   r"   u   ✓ Added completion loader to z+
Restart your shell or run: source ~/.zshrcz
To enable completions, ensure z is in your $fpath.z@Add this to your ~/.zshrc or ~/.zprofile if not already present:z    fpath=(z $fpath)z%    autoload -Uz compinit && compinitz)
Then restart your shell or run: exec zshr   r    z,
Restart your shell or run: source ~/.bashrcz=
Completions will be automatically loaded by bash-completion.zIf completions don't work:z0  1. Ensure bash-completion is installed (v2.8+)z)  2. Restart your shell or run: exec bashz2
Note: bash-completion is typically installed via:z)  - macOS: brew install bash-completion@2z.  - Debian/Ubuntu: apt install bash-completionz,  - Fedora/RHEL: dnf install bash-completionr   z.
Completions are automatically loaded in fish.z<Restart your shell or run: source ~/.config/fish/config.fish)cyclopts.completion.detectr8   r9   printsysstderrexitr   r   parentr%   )
r   r5   r8   r9   install_pathzshrccompletion_dirbashrcr3   r2   s
           r   _install_completion_commandFcreate_install_completion_command.<locals>._install_completion_commandt   s   $ 	Q=$ -5Xfg3L>BCE>		h.7w?@DE!-!4!488HH[\]XYN#38<==>BCf_y07x@AEFVW23HIABKLABFGDEf_CDPQ%%S ' U s   E0 04F('F()r   r   r   r   )r2   r3   rF   s   `` r   !create_install_completion_commandrH   `   se    , PTMQ@&!67$>	KL@& $+ytZ6H'IIJ@& @&D '&r   )__doc__r>   collections.abcr   pathlibr   typingr   r   cyclopts.parameterr   strr   boolr1   rH    r   r   <module>rQ      s     $  % ("8w/D'E "8RU "8Z^ "8J) ) )W]=S )X\ )XV'#CI.V'V'r   