m: allow showing summary of directories in list
Add a PATH-like variable M_LIST_PATH. If no arguments are given and this new variable isn't empty, show a summary of those directories, without showing stats for each subdirectory. This permits a more compact output that comes handy when your directory tree is growing out of control.
This commit is contained in:
parent
2231ee3e8d
commit
54f5477b0f
43
mblaze/m.sh
43
mblaze/m.sh
@ -22,6 +22,36 @@ Usage:
|
||||
exit 1
|
||||
}
|
||||
|
||||
_mlist_i_rec_ln()
|
||||
{
|
||||
if [ $# -eq 4 ]; then
|
||||
printf "%6d unseen %3d flagged %6d msg %s\n" "$@"
|
||||
else
|
||||
printf "%6d unseen %3d flagged %6d msg\n" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
_mlist_i_rec()
|
||||
{
|
||||
tuc=0
|
||||
tfc=0
|
||||
tmc=0
|
||||
entries=0
|
||||
while IFS= read -r dir; do
|
||||
mdirs "$dir" | mlist -i | tail -n 1 | {
|
||||
IFS=" " read -r uc ut fc ft mc mt dummy
|
||||
_mlist_i_rec_ln "$uc" "$fc" "$mc" "$dir"
|
||||
tuc=$((tuc + uc))
|
||||
tfc=$((tfc + fc))
|
||||
tmc=$((tmc + mc))
|
||||
entries=$((entries + 1))
|
||||
}
|
||||
done
|
||||
if [ $entries -gt 1 ]; then
|
||||
_mlist_i_rec_ln "$tuc" "$tfc" "$tmc"
|
||||
fi
|
||||
}
|
||||
|
||||
m_fetch_usage()
|
||||
{
|
||||
printf "Usage: %s f|fetch\n" "${0##*/}" >&2
|
||||
@ -53,7 +83,18 @@ m_list()
|
||||
{
|
||||
pwd=$(pwd)
|
||||
# cut(1) lists are 1-based, and +1 for leading slash
|
||||
mdirs "${@:-.}" | sort -t / | cut -c $((${#pwd} + 2))- | mlist -i
|
||||
pwd_offset=$((${#pwd} + 2))
|
||||
if [ $# -eq 0 ] && [ -n "$M_LIST_PATH" ]; then
|
||||
oldIFS=$IFS
|
||||
IFS=:
|
||||
set -- $M_LIST_PATH
|
||||
IFS=$oldIFS
|
||||
|
||||
printf "%s\n" "$@" | sort -t / | cut -c $pwd_offset- |
|
||||
_mlist_i_rec
|
||||
else
|
||||
mdirs "${@:-.}" | sort -t / | cut -c $pwd_offset- | mlist -i
|
||||
fi
|
||||
}
|
||||
|
||||
m_read()
|
||||
|
Loading…
Reference in New Issue
Block a user