1

I'm on a Mac and the cp and mv commands are killing me due to them copying the contents of a directory if a trailing slash is present. It has bitten me more than once when I use tab completion to specify the directory I want to copy.

I have noticed zsh has a neat feature that removes the trailing slash if it's not needed after a space or enter key is pressed. Is there any way to have bash mimic this behavior?

3

1 Answer 1

0

Bash completion can't capture space or enter key. It's for tab-key only.

To your question, I think you can write a little wrapper script to remove the trailing slash before pass the command line to the actual cp/mv programs.

For example, ~/bin/my_mv:

#!/bin/bash

argv=("$@")
last="${argv[$# - 1]}"
last="${last%/}"
argv[$# - 1]="$last"

mv "${argv[@]}"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .