Skip to content

Instantly share code, notes, and snippets.

@markusfisch
Created October 10, 2012 11:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save markusfisch/3864786 to your computer and use it in GitHub Desktop.
Save markusfisch/3864786 to your computer and use it in GitHub Desktop.
Make BSD/OSX find/cp/mv behave like the GNU/Linux tools
# Simply put that into your ~/.profile or ~/.bash_aliases
# Auto-complete BSD/OSX find to behave like GNU find
#
# @param ... - find params
find --version &>/dev/null || find()
{
local P=
[ -d "$1" ] || P=.
command find $P "$@"
}
# Make BSD/OSX cp/mv behave like GNU cp/mv i.e. fix that counter-intuitive
# behaviour of copying/moving files instead of directories when given with
# a closing slash
#
# @param ... - argument to cp
cp --version &>/dev/null || {
fix_cp_mv()
{
local C
for C in cp mv
do
eval "$C()
{
local A ARGS=()
for A in \"\$@\"
do
[ -d \"\$A\" ] && A=\${A%/}
ARGS=( \"\${ARGS[@]}\" \"\$A\" )
done
command $C \"\${ARGS[@]}\"
}"
done
}
fix_cp_mv
unset fix_cp_mv
}
@mgol
Copy link

mgol commented Oct 21, 2012

I get this error:

-bash: eval: line 14: syntax error near unexpected token `('
-bash: eval: line 14: `cp()'
-bash: eval: line 14: syntax error near unexpected token `('
-bash: eval: line 14: `mv()'

I'm on OS X Mountain Lion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment