Skip to content

Instantly share code, notes, and snippets.

@ivan
Last active October 7, 2017 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivan/08dd876ae7bbd4e08e6f3399f634246e to your computer and use it in GitHub Desktop.
Save ivan/08dd876ae7bbd4e08e6f3399f634246e to your computer and use it in GitHub Desktop.
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
Copy link
Author

ivan commented Sep 1, 2016

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

@nvxos
Copy link

nvxos 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