Create a gist now

Instantly share code, notes, and snippets.

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
# https://github.com/fish-shell/fish-shell/issues/3337
if status --is-command-substitution
command rsync $argv
return $status
end
# Strip trailing slash on "hi/" but not "/"
command rsync (string replace -r '(.)/$' '$1' -- $argv)
end
@ivan
Owner
ivan commented Aug 25, 2016 edited
@ivan
Owner
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