@@ -2307,6 +2307,30 @@ alias_source_file() {
23072307 echo " $PROJECT_DIR /scripts/core/alias.sh"
23082308}
23092309
2310+ completion_dir () {
2311+ if [ " $INSTALL_SCOPE " = " system" ]; then
2312+ echo " /etc/profile.d"
2313+ else
2314+ echo " $HOME /.config/clash-for-linux"
2315+ fi
2316+ }
2317+
2318+ bash_completion_entry_file () {
2319+ if [ " $INSTALL_SCOPE " = " system" ]; then
2320+ echo " $( completion_dir) /clash-for-linux-completion.bash"
2321+ else
2322+ echo " $( completion_dir) /completion.bash"
2323+ fi
2324+ }
2325+
2326+ zsh_completion_entry_file () {
2327+ if [ " $INSTALL_SCOPE " = " system" ]; then
2328+ echo " $( completion_dir) /clash-for-linux-completion.zsh"
2329+ else
2330+ echo " $( completion_dir) /completion.zsh"
2331+ fi
2332+ }
2333+
23102334clashctl_entry_target () {
23112335 echo " $( command_install_dir) /clashctl"
23122336}
@@ -2411,12 +2435,14 @@ cleanup_legacy_shell_entries() {
24112435}
24122436
24132437install_shell_alias_entry () {
2414- local profile_file alias_file shell_rc
2438+ local profile_file alias_file shell_rc bash_completion_file zsh_completion_file
24152439
24162440 cleanup_legacy_shell_entries
24172441
24182442 profile_file=" $( profile_entry_file) "
24192443 alias_file=" $( alias_source_file) "
2444+ bash_completion_file=" $( bash_completion_entry_file) "
2445+ zsh_completion_file=" $( zsh_completion_entry_file) "
24202446
24212447 mkdir -p " $( dirname " $profile_file " ) "
24222448 [ -f " $alias_file " ] || die " 未找到 alias 脚本:$alias_file "
@@ -2430,6 +2456,18 @@ if [ -n "\${BASH_VERSION:-}" ] && [ -z "\${CLASH_FOR_LINUX_SHELL_LOADED:-}" ]; t
24302456 export CLASH_FOR_LINUX_SHELL_LOADED="1"
24312457 source "$alias_file "
24322458fi
2459+
2460+ case "\$ -" in
2461+ *i*)
2462+ if [ -n "\$ {BASH_VERSION:-}" ] && [ -z "\$ {CLASH_FOR_LINUX_BASH_COMPLETION_LOADED:-}" ] && [ -f "$bash_completion_file " ]; then
2463+ export CLASH_FOR_LINUX_BASH_COMPLETION_LOADED="1"
2464+ source "$bash_completion_file "
2465+ elif [ -n "\$ {ZSH_VERSION:-}" ] && [ -z "\$ {CLASH_FOR_LINUX_ZSH_COMPLETION_LOADED:-}" ] && [ -f "$zsh_completion_file " ]; then
2466+ export CLASH_FOR_LINUX_ZSH_COMPLETION_LOADED="1"
2467+ source "$zsh_completion_file "
2468+ fi
2469+ ;;
2470+ esac
24332471EOF
24342472 chmod +x " $profile_file "
24352473
@@ -2440,6 +2478,21 @@ EOF
24402478 install_alias_command_wrappers
24412479}
24422480
2481+ install_clashctl_completion () {
2482+ local bash_target zsh_target
2483+
2484+ bash_target=" $( bash_completion_entry_file) "
2485+ zsh_target=" $( zsh_completion_entry_file) "
2486+
2487+ mkdir -p " $( dirname " $bash_target " ) "
2488+ mkdir -p " $( dirname " $zsh_target " ) "
2489+
2490+ bash " $PROJECT_DIR /scripts/core/clashctl.sh" completion bash > " $bash_target "
2491+ bash " $PROJECT_DIR /scripts/core/clashctl.sh" completion zsh > " $zsh_target "
2492+
2493+ chmod +x " $bash_target " " $zsh_target " 2> /dev/null || true
2494+ }
2495+
24432496remove_clashctl_entry () {
24442497 rm -f " $( clashctl_entry_target) " " $( clashctl_bin_entry_target) " 2> /dev/null || true
24452498 remove_alias_command_wrappers
@@ -2461,6 +2514,10 @@ remove_shell_alias_entry() {
24612514 fi
24622515}
24632516
2517+ remove_clashctl_completion () {
2518+ rm -f " $( bash_completion_entry_file) " " $( zsh_completion_entry_file) " 2> /dev/null || true
2519+ }
2520+
24642521install_has_subscription () {
24652522 [ -n " $( subscription_url 2> /dev/null || true) " ]
24662523}
0 commit comments