nuno 修订了这个 Gist 1 month ago. 转到此修订
1 file changed, 21 insertions
gistfile1.txt(文件已创建)
| @@ -0,0 +1,21 @@ | |||
| 1 | + | function cmd::list::_iter_confs() { | |
| 2 | + | # Usage: cmd::list::_iter_confs <filter_type> <callback> | |
| 3 | + | local filter_type="$1" | |
| 4 | + | local callback="$2" | |
| 5 | + | local dir | |
| 6 | + | dir="$(ctx::clients)" | |
| 7 | + | ||
| 8 | + | for conf in "${dir}"/*.conf; do | |
| 9 | + | [[ -f "$conf" ]] || continue | |
| 10 | + | local client_name | |
| 11 | + | client_name=$(basename "$conf" .conf) | |
| 12 | + | local ip="${p_ips[$client_name]:-}" | |
| 13 | + | if [[ -z "$ip" ]]; then | |
| 14 | + | ip=$(grep "^Address" "$conf" | awk '{print $3}' | cut -d'/' -f1) | |
| 15 | + | fi | |
| 16 | + | local type | |
| 17 | + | type=$(peers::get_type_from_ip "$ip") | |
| 18 | + | [[ -n "$filter_type" && "$type" != "$filter_type" ]] && continue | |
| 19 | + | "$callback" "$client_name" "$ip" "$type" | |
| 20 | + | done | |
| 21 | + | } | |
上一页
下一页