Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
rsync function in fish that strips trailing slashes from arguments
# rsync, like BSD cp, interprets trailing slashes as "copy the contents of this
# directory". But this interacts very badly with fish, which, unlike zsh, always
# adds a trailing slash when you complete a directory. This rsync function
# fixes this behavior by stripping all trailing slashes. You can still copy the
# contents of a directory by appending "/." instead of "/".
function rsync --wraps rsync
# Don't break fish's rsync completions with our slash-stripping
if status --is-command-substitution
command rsync $argv
return $status
# Strip trailing slash on "hi/" but not "/"
command rsync (string replace -r '(.)/$' '$1' -- $argv)
ivan commented Aug 25, 2016 edited
ivan commented Sep 1, 2016

Thanks to krader1961 and floam and faho for their suggested improvements.

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