clashctl.fish 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. set fn_arr \
  2. clashui \
  3. clashstatus \
  4. clashsecret \
  5. clashtun \
  6. clashmixin \
  7. clashupdate \
  8. clashhelp
  9. set -gx fish_version $FISH_VERSION
  10. for fn in $fn_arr
  11. eval "
  12. function $fn
  13. bash -i -c '$fn \"\$@\"' -- \$argv
  14. end
  15. "
  16. end
  17. function clashctl
  18. if test -z "$argv"
  19. clashhelp
  20. return
  21. end
  22. set suffix $argv[1]
  23. set argv $argv[2..-1]
  24. switch $suffix
  25. case on
  26. clashon $argv
  27. case off
  28. clashoff $argv
  29. case '*'
  30. clash"$suffix" $argv
  31. end
  32. end
  33. function clashon
  34. bash -i -c 'clashon; sudo tee /var/proxy >/dev/null <<EOF
  35. export http_proxy=$http_proxy
  36. export https_proxy=$http_proxy
  37. export HTTP_PROXY=$http_proxy
  38. export HTTPS_PROXY=$http_proxy
  39. export all_proxy=$all_proxy
  40. export ALL_PROXY=$all_proxy
  41. export no_proxy=$no_proxy
  42. export NO_PROXY=$no_proxy
  43. EOF'
  44. source /var/proxy
  45. end
  46. function clashoff
  47. bash -i -c 'clashoff'
  48. set -e \
  49. http_proxy \
  50. https_proxy \
  51. HTTP_PROXY \
  52. HTTPS_PROXY \
  53. all_proxy \
  54. ALL_PROXY \
  55. no_proxy \
  56. NO_PROXY
  57. end