qcd more BSD compliant

This commit is contained in:
ville rantanen
2017-06-09 10:06:43 +03:00
parent 2e8bd83dcd
commit 9caac70a4e

View File

@@ -1,10 +1,17 @@
## improved CD commands:
_QCD_FIND=find
case $OSTYPE in
darwin*)
alias tac=gtac
_QCD_FIND=gfind
;;
esac
function gcd() {
# guess cd, find first match in folder, or ask if multiple hits
local cdto QCDPATH
QCDPATH=$( dirname ${BASH_SOURCE[0]} )
QCDPATH=$( dirname $( realpath ${BASH_SOURCE[0]} ) )
cdto=$( python "$QCDPATH"/files/gcd-findmatch.py "$@" )
[[ -z "$cdto" ]] && return
\cd "$cdto"
@@ -221,7 +228,7 @@ function scd() {
} || {
cdfrom="$2"
}
cdto=$( find "$cdfrom" -mindepth 1 -type d -iname "*$1*" | sort -V | head -n 1 )
cdto=$( $_QCD_FIND "$cdfrom" -mindepth 1 -type d -iname "*$1*" | sort -V | head -n 1 )
echo $cdto
[[ -z "$cdto" ]] && return
\cd "$cdto"
@@ -297,7 +304,7 @@ function rmv () {
# remove empty folders from sources (not last argument)
for (( i=1; i<=$(($#-1)); i++ ))
do if [ -d "${!i}" ]
then find "${!i}" -depth -type d -exec rmdir \{\} \;
then $_QCD_FIND "${!i}" -depth -type d -exec rmdir \{\} \;
fi
done
}