From 9caac70a4ef4ad0f9b7d24e7200af06cbcc1d6b2 Mon Sep 17 00:00:00 2001 From: ville rantanen Date: Fri, 9 Jun 2017 10:06:43 +0300 Subject: [PATCH] qcd more BSD compliant --- qcd_function | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/qcd_function b/qcd_function index 6731f5b..ab3ded8 100644 --- a/qcd_function +++ b/qcd_function @@ -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 }