File sing-box.fish of Package network-sing-box-master-git

complete -c sing-box -f

# --- 辅助函数 ---
function __fish_sing_box_needs_command; set cmd (commandline -opc); if [ (count $cmd) -eq 1 ]; return 0; end; return 1; end
function __fish_sing_box_using_command; set cmd (commandline -opc); set subcommand $argv[1]; if [ (count $cmd) -gt 1 ]; if [ $cmd[2] = $subcommand ]; return 0; end; end; return 1; end
function __fish_sing_box_needs_mode_arg; set cmd (commandline -opc); if [ (count $cmd) -le 2 ]; return 0; end; return 1; end

# 动态获取节点
function __fish_sing_box_get_nodes; if systemctl is-active --quiet sing-box; curl -s --max-time 0.2 "http://127.0.0.1:9090/proxies/proxy" | jq -r '.all[]' 2>/dev/null; end; end

# 动态获取订阅名
function __fish_sing_box_get_subs; if test -f /etc/sing-box/subscriptions.json; jq -r '.[].name' /etc/sing-box/subscriptions.json 2>/dev/null; end; end

# --- 主命令 ---
complete -c sing-box -n "__fish_sing_box_needs_command" -a "on" -d "启动服务"
complete -c sing-box -n "__fish_sing_box_needs_command" -a "off" -d "停止服务"
complete -c sing-box -n "__fish_sing_box_needs_command" -a "restart" -d "重启服务"
complete -c sing-box -n "__fish_sing_box_needs_command" -a "status" -d "查看状态"
complete -c sing-box -n "__fish_sing_box_needs_command" -a "logs" -d "查看日志"
complete -c sing-box -n "__fish_sing_box_needs_command" -a "mode" -d "切换模式"
complete -c sing-box -n "__fish_sing_box_needs_command" -a "add" -d "添加订阅"
complete -c sing-box -n "__fish_sing_box_needs_command" -a "sub" -d "订阅管理"
complete -c sing-box -n "__fish_sing_box_needs_command" -a "update" -d "更新节点"
complete -c sing-box -n "__fish_sing_box_needs_command" -a "upgrade" -d "软件升级"
complete -c sing-box -n "__fish_sing_box_needs_command" -a "s" -d "选择节点"

# --- 子命令参数 ---
complete -c sing-box -n "__fish_sing_box_using_command s" -a "(__fish_sing_box_get_nodes)" -d "节点"
complete -c sing-box -n "__fish_sing_box_using_command mode; and __fish_sing_box_needs_mode_arg" -a "tun" -d "TUN 模式"
complete -c sing-box -n "__fish_sing_box_using_command mode; and __fish_sing_box_needs_mode_arg" -a "proxy" -d "Proxy 模式"
complete -c sing-box -n "__fish_sing_box_using_command on; and __fish_sing_box_needs_mode_arg" -a "tun" -d "TUN 启动"
complete -c sing-box -n "__fish_sing_box_using_command on; and __fish_sing_box_needs_mode_arg" -a "proxy" -d "Proxy 启动"
complete -c sing-box -n "__fish_sing_box_using_command add" -s l -l link -d "URL"
complete -c sing-box -n "__fish_sing_box_using_command add" -s f -l file -r -F -d "文件"

# --- sub 命令补全 ---
complete -c sing-box -n "__fish_sing_box_using_command sub" -a "(__fish_sing_box_get_subs)" -d "订阅名"
complete -c sing-box -n "__fish_sing_box_using_command sub" -a "update" -d "更新"
complete -c sing-box -n "__fish_sing_box_using_command sub" -a "delete" -d "删除"
complete -c sing-box -n "__fish_sing_box_using_command sub" -a "rename" -d "重命名"
complete -c sing-box -n "__fish_sing_box_using_command sub" -a "url" -d "修改URL"
complete -c sing-box -n "__fish_sing_box_using_command sub" -a "auto" -d "自动更新开关"
openSUSE Build Service is sponsored by