Last active
October 7, 2017 19:59
rsync function in fish that strips trailing slashes from arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Thanks to krader1961 and floam and faho for their suggested improvements.
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
Don't delete; linked to from fish-shell/fish-shell#3253 (comment) and https://ludios.org/fish-for-zsh-users/