Escape or quote shell characters by default when pasting a path-like string
Feature Request
Summary
Often I run a find
or similar command, look at the output, and copy one of the paths to perform some action (cd
, delete, open, etc). If the path contains spaces and I don't notice, I get an error when I run the command because it's interpreted as two separate paths. I see the "Advanced Paste" functionality allows for escaping shell characters (spaces etc) when pasting, but this is awkward compared to a regular paste. It would be nice if iTerm could (optionally/based on a preference) detect if the string being pasted looks like a path, and perform this escaping automatically if so. "Looks like a path" could be determined by criteria like:
- Exactly one line
- Contains at least one slash
- Contains no slashes adjacent to a space (which might indicate actually a list of paths where the spaces are intended as shell delimiters) Further possible refinements:
- Do this only in certain commands--shells by default, but some users might want similar behavior in other language REPLs.
- Option for enclosing in single or double quotes instead of escaping with backslashes
- Detect if an open quotation mark is already present on the command line and insert only the corresponding closer, or none at all
Alternatives
If the Python API can reliably intercept paste events that could be an equally effective solution, but I only see options to intercept keystrokes. This can't handle users with custom paste shortcuts (including due to international keyboard layouts), or other ways of pasting like scripts or middle-click. So it could be a stopgap but isn't ideal. For detecting text already present at the command line I'm also not sure the Python API has the necessary access.
Concerns
Features like this always have the possibility of being "too clever" and doing more harm than good, but the potential damage here is no worse than the potential damage of not having the feature, i.e. getting an error if you aren't paying enough attention before hitting Return.