Chrysostomus / manjaro-zsh-config

Zsh configuration package for manjaro
MIT License
124 stars 52 forks source link

Revert #36 and #37 #38

Closed squ1dd13 closed 1 year ago

squ1dd13 commented 1 year ago

The shift in the alias for cp emits an error message when cp is used without any arguments:

~ > cp        
f:shift: shift count must be <= $#
cp: missing file operand
Try 'cp --help' for more information.

Furthermore, the aliases don't do what they say they do. The comment of Confirm before overwriting something does not apply, because the -i is only added if no other arguments are provided. This becomes clear when we try the function that cp is aliased to in the shell, but with calls to echo showing the argument array:

cp_alias(){echo initial: $1; fo=${1:--i}; echo modified: $fo; shift; cp $fo $*}

When called with zero arguments, we do get -i:

~ > cp_alias                                                                       
initial:
modified: -i
cp_alias:shift: shift count must be <= $#
...

When called with any arguments at all, we no longer get -i:

~ > cp_alias x
initial: x
modified: x
...

I set up a couple of test files to try out the current cp alias, and it definitely doesn't add -i:

~ > touch x
~ > touch y
~ > cp x y
~ > # It should have asked if I want to overwrite!

Compare this to when we use cp -i:

~ > cp -i x y
cp: overwrite 'y'?

I understand that the original edits were intended to allow the arguments to be overridden, but the current aliases are incorrect and even give error messages. If users want to bypass the aliases, they can just use the built-in backslash feature: running \cp instead of cp will cause the alias to be ignored.

~ > alias cp="cp -i"
# With a backslash, we don't get a prompt
~ > \cp x y
# Without a backslash, we do get one
~ > cp x y   
cp: overwrite 'y'?
squ1dd13 commented 1 year ago

This also fixes the issues caused by name collisions from within the aliases as mentioned here.