Create a gist now

Instantly share code, notes, and snippets.

Embed
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
# 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

This comment has been minimized.

Show comment
Hide comment
Owner

ivan commented Aug 25, 2016

@ivan

This comment has been minimized.

Show comment
Hide comment
@ivan

ivan Sep 1, 2016

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

Owner

ivan commented Sep 1, 2016

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

@ngoudal

This comment has been minimized.

Show comment
Hide comment
@ngoudal

ngoudal Oct 7, 2017

What is the purpose to '--wraps rsync' if the function has the same name as the wrapped command?

ngoudal commented Oct 7, 2017

What is the purpose to '--wraps rsync' if the function has the same name as the wrapped command?

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