Greg Wooledge wrote: > We would need to see the definition of the "include" function, and the > contents of the file that it's presumably sourcing or whatever. > Working on packaging, but to answer your immediate questions:
Assuming attachments work, 'include' is in ~/bin Note, some of these files are "works in progress, so some things aren't finished...which will be obvious)... recycle space uses a non-broken version of 'rm' that really does a depth-first removal of files and doesn't violate depth-first order for special cases -- but you don't need that to see this problem (it never gets there and would only run if you used "-e") The function is defined in /etc/local/aliases.sh There are several other files needed for the whole mess -- am working on putting them in a dir structure that can be packaged...but this should give you the initial files. If I forgot any other files that are needed right away, I can send those off, but getting close to needing to take a break, so not sure how long packaging everything will take... There are mentions of cygwin in the scripts as I try to maintain a common set of scripts that runs on either cygwin or linux, but this script is run on linux. Thanks for any hints and patience...
#!/bin/bash
#echo "include:2<include $@ >"
shopt -s expand_aliases
alias dcl=declare
alias 1>&2
dcl -x _SPATH
dcl -xa _FPATH
dcl -xA _INC
function pathof {
local prog="$1"
local path
for path in $(IFS=:;echo $PATH );do
path="$path/$prog"
if [[ -f $path && -x $path ]]; then echo "$path"; return 0; fi
done
echo "$prog: not found" >&2
}
function _include_h {
# [[ ${0##*/} == include ]] && { exec "$@" ; }
[[ $1 ]] || return 1
dcl fnc="$1"
[[ $PATH != ${_SPATH:-} ]] && {
unset _FPATH
dcl -xa _FPATH=( $(IFS=:;echo $PATH) )
unset _SPATH; dcl -x _SPATH="$PATH"
}
if [[ ! ${_INC["$fnc"]:-""} ]]; then
for pw in "${_FPATH[@]}"; do
if [[ -r $pw/$fnc ]]; then
printf "%s
" "source \"$pw/$fnc\"" &&
_INC["$fnc"]="$pw/$fnc" && return 0
fi
done
echo "ERROR: Missing \"$fnc\" in \$PATH" >&2
exit 2
fi
}
export -f _include_h
read alias_def <<'_alias_def_end_'
alias include='eval "$( _include_h "$1")"'
_alias_def_end_
export
__GLOBAL_ALIASES__="$alias_def${__GLOBAL_ALIASES__:+";$__GLOBAL_ALIASES__"}"
# test if initial include -- if so, restart with aliases defined...
[[ ${0##*/} == include ]] && { exec "$@" ; }
# else include the arg
include "$@"
# vim: ts=2 sw=2
#!/bin/bash -x
#full trace support:
export
PS4='>>${BASH_SOURCE:+${BASH_SOURCE[0]}}#${LINENO}${FUNCNAME:+(${FUNCNAME[0]})}>
'
# gvim=:SetNumberAndWidth #rm 'no' to activate in gvim, '=:' is not error
_prgpth="${0:?}"; _prg="${_prgpth##*/}"; _prgdr="${_prgpth%/$_prg}"
[[ -z $_prgdr || $_prgdr == . || $_prg == $_prgdr ]] && _prgdr="$PWD"
export PATH="$_prgdr:$_prgdr/lib:$PATH"
#printf "prgpth=%s, prg=%s, prgdr=%s\n" "$_prgpth" "$_prg" "$_prgdr"
shopt -s expand_aliases extglob sourcepath xpg_echo; set -o pipefail
#source {errnos,stdlib}.shlib
echo lib/Util/needroot.shh
include "lib/Util/needroot.shh"
# vim: ts=2 sw=2
Recycle_pat='\.recycle$'
function recycle_bins {
locate -e /.recycle|grep $Recycle_pat
}
Ls="$(type -P ls)"
function empty_dir {
local d="$1"
local -i f="$($Ls -A1 "$1"|wc -l)"
return $f
}
m1="Space Consumed in Recycle bins:"
m2="Emptying recycle bins..."
m3="Expiring Recycle bins..."
msg="$m1"
declare -i remove=0 quiet=0 expire=0
declare -a args
while [[ $# > 0 ]]; do
if [[ $1 == "-e" || $1 == "--empty" ]]; then remove=1; msg="$m2"
elif [[ $1 == "-x" || $1 == "--expire" ]]; then
shift && expire=${1:?};
msg="$m3"
elif [[ $1 == "-q" || $1 == "--quiet" ]]; then quiet=1
fi
shift
done
function usage {
shopt -s xpg_echo
local -a msg=(
" recycle_space -- manage 'recycling space'\n\n"
" (no args) -- display space taken by all recycle bins found\n"
" TBD -e -- empty all recycle bins found\n"
" TBD -x <weeks> -- eXpire files older than 'weeks' from bins\n"
" -q -- suppress this message\n\n")
echo -e "${msg[@]}"
}
#if ((remove || expire >-1)); then
# printf "option not yet done...\n"
# exit 0;
#fi
((!quiet)) && usage
printf "%s\n" "$msg"
{
while read dir ; do
empty_dir "$dir" && continue
if ((remove)) ; then
( cd "$dir" && rm --one-file-system -fr .)
elif ((expire)); then :
else
printf " %4s %s\n" "$(sudo du -sh "$dir"|cut -f1)"
"$dir"
fi
done < <(recycle_bins)
} | ( ((!(remove||expire))) && hsort -s || cat)
aliases.sh
Description: Bourne shell script
