0

Suppose I have the file tree

-A_dir/
  - a_test_file1

Doing mv a_test_file1 a_test_file2 results in an annoying correction query. The second argument of mv should never be corrected, as it may or may not point to an existing node on the filesystem. However, the first argument may be corrected because it must always be a valid node.

This is an common use case, where I'd only like zsh to correct certain arguments in a command. How can I achieve this?

tshepang
  • 12,111
  • 21
  • 91
  • 136
PythonNut
  • 6,182
  • 1
  • 25
  • 41
  • `However, the first argument may be corrected because it must always be a valid node.` -> How do you want it corrected? By searching subdirectories? How about when more than one directory contain same file? – konsolebox Jul 21 '14 at 09:19
  • I think the OP is happy with the default corrections applied to the first argument, as long as *no* corrections are applied to the second argument to `mv`. – chepner Jul 21 '14 at 13:23
  • @konsolebox, chepner is correct. – PythonNut Jul 21 '14 at 19:12
  • I still don't get it. Do you need a *correction* i.e. replace the first argument with another? If that's the case if you have `a/a.txt` and you have `b/a.txt`, and your current command is `mv a.txt a2.txt` (which would cause file does not exist error), would you replace `a.txt` with `a/a.txt` or `b/a.txt`? Or do you just need to check if the file exists and do nothing if it doesn't? – konsolebox Jul 22 '14 at 01:23
  • More simply put, the if the second argument to mv is not a valid filesystem node, zsh will try to correct it to one. This is not correct behavior because I could be moving it to a new file (i.e. one that does not yet exist). The first argument should still be corrected because it does need to be a valid filesystem node. – PythonNut Jul 22 '14 at 03:39

1 Answers1

0

Placing this as an answer because it is too much text for a comment... but this is really a comment.

Honestly, a cursory reading of the manual indicates that this is not possible without deep hackery. correct corrects commands and correct_all tries to correct all arguments.

I thought about doing something like

function mv {
  emulate -L zsh
  CORRECT_IGNORE='*'$@[-1]'*'
  command mv $@
}

But it does not work as CORRECT_IGNORE does not apply to the correction of filenames. If you could find out how to produce corrections from a list of arguments, you could generate corrections for all arguments that you want corrected and later call nocorrect mv ....

Francisco
  • 3,980
  • 1
  • 23
  • 27