Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zsh expands arguments to scp/rsync #232

Closed
skwp opened this issue Aug 6, 2012 · 8 comments
Closed

zsh expands arguments to scp/rsync #232

skwp opened this issue Aug 6, 2012 · 8 comments

Comments

@skwp
Copy link

skwp commented Aug 6, 2012

Sorin, I don't know if you want to integrate this little hack, or if there's a better way around. But I found zsh is a little annoying with the way you have to handle arguments to remote commands like scp/rsync. For example if you try to

rsync remote:/path/to/* . then it gives you an error like no matches found because it tries to expand the star glob locally.

The following link has a small bit of zsh code that combats that by auto escaping globs in remote commands.
http://superuser.com/questions/420525/scp-with-zsh-no-matches-found

Here is the code fragment:

autoload -U url-quote-magic
zle -N self-insert url-quote-magic
zstyle -e :urlglobber url-other-schema \
'[[ $words[1] == scp ]] && reply=("*") || reply=(http https ftp)'

What are your thoughts on this, as I am too much of a zsh noob to know if this is a good solution. It does seem to work...

@sorin-ionescu
Copy link
Owner

Would alias scp='noglob scp' fix that? Right now, I have alias scp='nocorrect scp' in utility/init.zsh.

@skwp
Copy link
Author

skwp commented Aug 6, 2012

Yeah that's another possible solution. Do you think alias is better?

@sorin-ionescu
Copy link
Owner

Yes, the following should fix the problem. I'm not sure why there is a nocorrect scp there. It must be an Oh My Zsh cruft.

alias rsync='noglob rsync'
alias scp='noglob scp'

Is there anything else in utility that should be noglob instead of nocorrect?

@sorin-ionescu
Copy link
Owner

I need an answer to my last question to know if I should just push with just those two aliases.

@skwp
Copy link
Author

skwp commented Aug 8, 2012

Probably ftp and sftp should go into that list as well. That's all I can think of for now.

pbrisbin added a commit to pbrisbin/prezto that referenced this issue Aug 16, 2012
* upstream/master:
  [Fix sorin-ionescu#233] Bind history-substring-search using $key_info
  [Fix sorin-ionescu#232] Disable globbing for rsync, scp, ftp, sftp
  Add missing theme screenshots
  Update comments in themes
  Simplify and clean up the steeef theme
  Remove unnecessary checks in steeef
  [Fix sorin-ionescu#230] Check the expanded command in steeef preexec
  Ensure that $terminfo values are valid
  Rename templates to runcoms
  Clarify a comment about GNU utilities
  Wrap editor module documentation at 80 characters
  Increase heading readability
  [Fix sorin-ionescu#202] Load modules all or nothing
lildude pushed a commit to lildude/prezto that referenced this issue Jan 12, 2014
kodelint pushed a commit to kodelint/prezto that referenced this issue Nov 15, 2016
@claudioabreu
Copy link

claudioabreu commented May 16, 2020

Yes, the following should fix the problem. I'm not sure why there is a nocorrect scp there. It must be an Oh My Zsh cruft.

alias rsync='noglob rsync'
alias scp='noglob scp'

Is there anything else in utility that should be noglob instead of nocorrect?

I know this topic is closed, but my solution for both rsync and scp follows:

In my ~/.zshrc I put:

alias scp='noglob scp_wrap'
function scp_wrap {
  local -a args
  local i
  for i in "$@"; do case $i in
    (*:*) args+=($i) ;;
    (*) args+=(${~i}) ;;
  esac; done
  command scp "${(@)args}"
}

alias rsync='noglob rsync_wrap'
function rsync_wrap {
  local -a args
  local i
  for i in "$@"; do case $i in
    (*:*) args+=($i) ;;
    (*) args+=(${~i}) ;;
  esac; done
  command rsync "${(@)args}"
}

rooney pushed a commit to rooney/prezto that referenced this issue Aug 19, 2020
@sjackman
Copy link

Since the noglob rsync alias is enabled by default, how do you run rsync if you do want globbing for a particular execution of that command? Is there a command like doglob rsync *.txt remote:/tmp/?

@sjackman
Copy link

Answered my own question (less than a minute later, sorry for the noise). The answer is command rsync *.txt remote:/tmp/ to use globbing for this one invocation of the command, and unalias rsync to use globbing for the lifetime of this shell.

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

No branches or pull requests

4 participants