2013/8/15 Andres Perera <andre...@zoho.com>: > On Wed, Aug 14, 2013 at 5:15 AM, Vadim Zhukov <persg...@gmail.com> wrote: >> + p) >> + set -f >> + if [ "${PWD##$OPTARG}" == "${PWD}" ]; then >> + cat >&2 <<EOE >> +${0##*/}: current directory does not seem to be under the >> +specified root directory: $OPTARG >> +EOE >> + exit 3 >> + fi >> + set +f > > there's no need to toggle ``noglob'' > > use ${PWD##"$OPTARG"} to suppress the globbing in the RHS of ``##''
Nice idea, thanks! I was thinking that it won't work in all cases, but see below. :) >> +if [[ -z $portsdir ]]; then >> + set +e >> + portsdir=$(make -V PORTSDIR 2>/dev/null) >> + (($? == 0)) && portsdir= >> + set -e >> +fi > > there's no need to toggle ``errexit'' > > use portsdir=$(make -V PORTSDIR 2>/dev/null) && portsdir= Another nice trick, thanks again! > if the LHS of ``&&'' fails, the shell won't exit even if ``errexit'' > is under effect > >> + >> +if [[ -z $portsdir ]]; then >> + # heuristics mode ON >> + pkgpath="${PWD##*/ports/*(mystuff/|openbsd-wip/|p5-ports-wip/)}" > >> + set -f >> + portsdir="${PWD%/$pkgpath}" >> + set +f > > same as previous unnecessary ``noglob'' toggling I thought that this wouldn't work here, because we already have double quotes around - but looks like they are not needed at all. At least, ksh does not do field splitting or glob expansion of $b in a=$b case... So a quiet a few double quotes could be dropped now. Thanks again! >> + set -f >> + pkgpath="${PWD##$portsdir/}" >> + set +f > > same as previous unnecessary ``noglob'' toggling yep. -- WBR, Vadim Zhukov