-
Notifications
You must be signed in to change notification settings - Fork 0
/
nuget-clean.sh
37 lines (32 loc) · 1.01 KB
/
nuget-clean.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# ###################################
# Author : gaoyang
# Url : https://github.com/gaoyang/tool-shells
# Description : 清理多余的本地 nuget 包,规则:只保留最近一次下载的包
# ###################################
output=$(dotnet nuget locals global-packages -l)
packages_folder=${output#"global-packages: "}
folders=()
for package_folder in $packages_folder*; do
count=$(ls -l $package_folder | grep "^d" | wc -l)
if [ $count -gt 1 ]; then
package_name=${package_folder##*/}
echo ${package_name}
for version_name in $(ls -1tr $package_folder | tail -n +2); do
echo "\t$version_name"
version_folder=${package_folder}/${version_name}
folders+=($version_folder)
done
echo ""
fi
done
if [ ${#folders[*]} = 0 ]; then
echo "未找到多余的 nuget 包版本。"
exit
fi
read -r -p "确认删除列表中的 nuget 包?(Y/n)" response
if [[ "$response" =~ ^([yY])$ ]]; then
for folder in ${folders[*]}; do
rm -r ${folder}
done
fi