Lines 1-6
Link Here
|
1 |
#!/bin/sh |
1 |
#!/bin/sh |
2 |
|
2 |
|
3 |
# Copyright (c) 2013 Yanhui Shen, shen.elf@gmail.c0m |
3 |
# version 0.3 |
|
|
4 |
|
5 |
# Copyright (c) 2014 Yanhui Shen, shen.elf@gmail.c0m |
4 |
# All rights reserved. |
6 |
# All rights reserved. |
5 |
# |
7 |
# |
6 |
# Redistribution and use in source and binary forms, with or without |
8 |
# Redistribution and use in source and binary forms, with or without |
Lines 24-51
Link Here
|
24 |
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 |
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
# SUCH DAMAGE. |
27 |
# SUCH DAMAGE. |
26 |
|
28 |
|
27 |
#Twiddle="echo '|/-\\' | cut -c" |
29 |
cols=$((`stty size | cut -w -f2` - 6)) |
28 |
PkgQuery="pkg query -e \"%#r=0\" \"%o#%c\" | sort" |
30 |
rows=$((`stty size | cut -w -f1` - 4)) |
|
|
31 |
height=$(($rows - 7)) |
32 |
sep="#" |
33 |
PkgQuery="pkg query -e \"%#r=0\" \"%o$sep%c\" | sort" |
29 |
PkgDelete="pkg delete -y" |
34 |
PkgDelete="pkg delete -y" |
30 |
DialogList="dialog --stdout --checklist \"leaf packages (%s)\" 30 90 30" |
35 |
FmtDialog="dialog --checklist \"Leaf Packages: %s\" $rows $cols $height %s" |
31 |
|
36 |
|
32 |
KeptLeaves="" |
37 |
KeptLeaves="" |
33 |
while true; do |
38 |
while true; do |
34 |
#==== refresh leaves ==== |
39 |
#==== refresh leaves ==== |
35 |
echo "Calculating..." |
40 |
echo "Querying..." |
36 |
AllLeaves=`eval $PkgQuery` |
41 |
AllLeaves=`eval $PkgQuery` |
37 |
NewLeaves="" |
42 |
NewLeaves="" |
38 |
nNewLeaves="0" |
43 |
nNewLeaves="0" |
39 |
#n="0" |
44 |
|
40 |
IFS=$'\n' |
45 |
#IFS=$'\n' |
|
|
46 |
# see http://svnweb.freebsd.org/base?view=revision&revision=221513 |
47 |
# for compatibility, use the following trick instead |
48 |
IFS=" |
49 |
" |
41 |
for line in $AllLeaves; do |
50 |
for line in $AllLeaves; do |
42 |
# print twiddle will be a little slower |
51 |
case $line in |
43 |
#n=$(($n % 4 + 1)) |
52 |
(*"$sep"*) |
44 |
#ch=`eval "$Twiddle $n"` |
53 |
port=${line%%"$sep"*} |
45 |
#printf "Calculating...%s\r" "$ch" |
54 |
desc=${line#*"$sep"} |
|
|
55 |
;; |
56 |
(*) |
57 |
echo "Bad line: " $line |
58 |
exit |
59 |
;; |
60 |
esac |
46 |
|
61 |
|
47 |
port=`echo "$line" | cut -d'#' -f1` |
|
|
48 |
desc=`echo "$line" | cut -d'#' -f2 | sed -e 's/\"/\\\"/g'` |
49 |
ret=`echo "$KeptLeaves" | grep "$port"` |
62 |
ret=`echo "$KeptLeaves" | grep "$port"` |
50 |
if [ -z "$ret" ]; then |
63 |
if [ -z "$ret" ]; then |
51 |
NewLeaves="$NewLeaves $port \"$desc\" off" |
64 |
NewLeaves="$NewLeaves $port \"$desc\" off" |
Lines 58-65
Link Here
|
58 |
echo "Nothing to do!" |
71 |
echo "Nothing to do!" |
59 |
exit |
72 |
exit |
60 |
fi |
73 |
fi |
61 |
cmd=`printf $DialogList "$nNewLeaves"` |
74 |
cmd=`printf $FmtDialog "$nNewLeaves" "$NewLeaves"` |
62 |
selections=`eval "$cmd $NewLeaves"` |
75 |
selections=`eval "$cmd 3>&2 2>&1 1>&3"` |
63 |
if [ $? -ne 0 ]; then |
76 |
if [ $? -ne 0 ]; then |
64 |
echo "Canceled." |
77 |
echo "Canceled." |
65 |
exit |
78 |
exit |