import{n as e}from"./chunk-DR8-3Aex.js";import{$ as t,In as n,Ln as r,t as i,v as a}from"./src-Di342QoJ.js";import{G as o,U as s,l as c,p as l}from"./debug-otxXY3j-.js";import{o as u,s as d}from"./log-DSV4Ht5l.js";import{r as f,t as p}from"./execFileNoThrow-azCkYhmF.js";import{homedir as m}from"os";import{dirname as h,join as g}from"path";import{mkdir as _,readFile as v,writeFile as y}from"fs/promises";import{pathToFileURL as b}from"url";function x(){let e=process.env.SHELL||``,t=m(),n=g(t,`.claude`);if(e.endsWith(`/zsh`)||e.endsWith(`/zsh.exe`)){let e=g(n,`completion.zsh`);return{name:`zsh`,rcFile:g(t,`.zshrc`),cacheFile:e,completionLine:`[[ -f "${e}" ]] && source "${e}"`,shellFlag:`zsh`}}if(e.endsWith(`/bash`)||e.endsWith(`/bash.exe`)){let e=g(n,`completion.bash`);return{name:`bash`,rcFile:g(t,`.bashrc`),cacheFile:e,completionLine:`[ -f "${e}" ] && source "${e}"`,shellFlag:`bash`}}if(e.endsWith(`/fish`)||e.endsWith(`/fish.exe`)){let e=process.env.XDG_CONFIG_HOME||g(t,`.config`),r=g(n,`completion.fish`);return{name:`fish`,rcFile:g(e,`fish`,`config.fish`),cacheFile:r,completionLine:`[ -f "${r}" ] && source "${r}"`,shellFlag:`fish`}}return null}function S(e){return t()?`\x1b]8;;${b(e).href}\x07${e}\x1b]8;;\x07`:e}async function C(e){let t=x();if(!t)return``;try{await _(h(t.cacheFile),{recursive:!0})}catch(r){return d(r),`${T}${a(`warning`,e)(`Could not write ${t.name} completion cache`)}${T}${n.dim(`Run manually: claude completion ${t.shellFlag} > ${t.cacheFile}`)}${T}`}if((await p(process.argv[1]||`claude`,[`completion`,t.shellFlag,`--output`,t.cacheFile])).code!==0)return`${T}${a(`warning`,e)(`Could not generate ${t.name} shell completions`)}${T}${n.dim(`Run manually: claude completion ${t.shellFlag} > ${t.cacheFile}`)}${T}`;let r=``;try{if(r=await v(t.rcFile,{encoding:`utf-8`}),r.includes(`claude completion`)||r.includes(t.cacheFile))return`${T}${a(`success`,e)(`Shell completions updated for ${t.name}`)}${T}${n.dim(`See ${S(t.rcFile)}`)}${T}`}catch(r){if(!o(r))return d(r),`${T}${a(`warning`,e)(`Could not install ${t.name} shell completions`)}${T}${n.dim(`Add this to ${S(t.rcFile)}:`)}${T}${n.dim(t.completionLine)}${T}`}try{await _(h(t.rcFile),{recursive:!0});let i=r&&!r.endsWith(`
`)?`
`:``,o=`${r}${i}\n# Claude Code shell completions\n${t.completionLine}\n`;return await y(t.rcFile,o,{encoding:`utf-8`}),`${T}${a(`success`,e)(`Installed ${t.name} shell completions`)}${T}${n.dim(`Added to ${S(t.rcFile)}`)}${T}${n.dim(`Run: source ${t.rcFile}`)}${T}`}catch(r){return d(r),`${T}${a(`warning`,e)(`Could not install ${t.name} shell completions`)}${T}${n.dim(`Add this to ${S(t.rcFile)}:`)}${T}${n.dim(t.completionLine)}${T}`}}async function w(){let e=x();if(e){if(l(`update: Regenerating ${e.name} completion cache`),(await p(process.argv[1]||`claude`,[`completion`,e.shellFlag,`--output`,e.cacheFile])).code!==0){l(`update: Failed to regenerate ${e.name} completion cache`);return}l(`update: Regenerated ${e.name} completion cache at ${e.cacheFile}`)}}var T,E=e((()=>{r(),i(),c(),s(),f(),u(),T=`
`}));export{w as n,C as r,E as t};