From 41296185dc67727f91b66476bd5834ff43e35241 Mon Sep 17 00:00:00 2001 From: Lucas Larson Date: Sat, 3 Oct 2020 13:52:31 -0400 Subject: [PATCH] repair `cp` and add `cy` with optional `$2` (994ba9c149ecd3ce52d58173331aa4e60143b647) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the following function works on Alpine Linux, but failed and closed terminal windows on macOS (until I renamed it from `cp` to `cy`). I tested with both `cp` and `cp -r -i --` and as `cp ()` and `function cp ()`. cy () { if [[ -n $2 ]]; then cp -r -i -- "$1" "$2" else cp -r -i -- "$1" "$PWD" fi } --- .oh-my-zsh/custom/aliases.zsh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.oh-my-zsh/custom/aliases.zsh b/.oh-my-zsh/custom/aliases.zsh index 9b43d4c309..abb10d3862 100644 --- a/.oh-my-zsh/custom/aliases.zsh +++ b/.oh-my-zsh/custom/aliases.zsh @@ -65,15 +65,15 @@ alias pip="pip3" # shell -cp () { +# https://mywiki.wooledge.org/BashPitfalls?rev=524#Filenames_with_leading_dashes +alias cp="cp -r -i --" +cy () { if [[ -n $2 ]]; then - # prefix the arguments with `--` for safety - # https://mywiki.wooledge.org/BashPitfalls?rev=524#Filenames_with_leading_dashes - cp -r -i -- "$1" "$2" + cp "$1" "$2" else # if there is no second argument, # then copy to the current directory - cp -r -i -- "$1" "$PWD" + cp "$1" "$PWD" fi } alias mv="mv -v -i" # https://unix.stackexchange.com/a/30950