Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
1  
Why not just run zsh? It's built into Mac OS X. –  Spiff Nov 30 '11 at 7:51
    
I guess I'm just used to bash after 12 years of using it... zsh seems like it requires a lot of setup to get it working similar to bash? –  intargc Nov 30 '11 at 16:04
    
Cross-posted on Unix & Linux. Please don't do that. –  Gilles Nov 30 '11 at 23:09

1 Answer 1

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[@]}"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.