From 071b4f95a19446cd2c2914739a7cf48f53333866 Mon Sep 17 00:00:00 2001 From: Yancy Lin Date: Wed, 5 Jun 2024 16:45:27 +0800 Subject: [PATCH] fix: Can not enable proxy for non-root user (#21) The plugin tries to enable apt proxy, but it is not support to use apt for non-root users, so as the proxy for apt. I only determine if the current user has sudo privileges. If the user does not have sudo privileges, the proxy will not be set for apt. --- zsh-proxy.plugin.zsh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/zsh-proxy.plugin.zsh b/zsh-proxy.plugin.zsh index 0d7de89..ac15115 100755 --- a/zsh-proxy.plugin.zsh +++ b/zsh-proxy.plugin.zsh @@ -244,7 +244,9 @@ __enable_proxy() { __disable_proxy_all __disable_proxy_git __disable_proxy_npm - __disable_proxy_apt + if sudo -n true 2>/dev/null; then + __disable_proxy_apt + fi echo "Done!" echo "----------------------------------------" echo "Enable proxy for:" @@ -255,7 +257,10 @@ __enable_proxy() { # npm & yarn & pnpm" __enable_proxy_npm # apt" - __enable_proxy_apt + if sudo -n true 2>/dev/null; then + echo "- apt" + __enable_proxy_apt + fi echo "Done!" fi } @@ -264,7 +269,9 @@ __disable_proxy() { __disable_proxy_all __disable_proxy_git __disable_proxy_npm - __disable_proxy_apt + if sudo -n true 2>/dev/null; then + __disable_proxy_apt + fi } __auto_proxy() {