如何在不转义空格和特殊 shell 字符的情况下显示文件完成情况?

如何在不转义空格和特殊 shell 字符的情况下显示文件完成情况?

我有一堆带空格的文件名:

[~/music]% ls
Acid Eater - Black Fuzz On Wheels.ogg         Angel'in Heavy Syrup 4.mp3
Akalé Wubé - Akalé Wubé.opus                  Astor Piazzolla & Gary Burton - The New Tango.mp3
Allen Toussaint - The Bright Mississippi.mp3  B.B. King - Live at the Regal.mp3
Angel'in Heavy Syrup 1.opus                   Bar Kokhba Sextet - Lucifer.opus
Angel'in Heavy Syrup 2.opus                   Billy Bang - Vietnam the Aftermath.mp3
Angel'in Heavy Syrup 3.mp3

完成操作会为空格插入转义字符(这也意味着没有足够的空间来将其显示在两列中):

[~/music]% mpv <Tab>
Acid\ Eater\ -\ Black\ Fuzz\ On\ Wheels.ogg
Akalé\ Wubé\ -\ Akalé\ Wubé.opus
Allen\ Toussaint\ -\ The\ Bright\ Mississippi.mp3
Angel\'in\ Heavy\ Syrup\ 1.opus
Angel\'in\ Heavy\ Syrup\ 2.opus
Angel\'in\ Heavy\ Syrup\ 3.mp3
Angel\'in\ Heavy\ Syrup\ 4.mp3
Astor\ Piazzolla\ \&\ Gary\ Burton\ -\ The\ New\ Tango.mp3
B.B.\ King\ -\ Live\ at\ the\ Regal.mp3
Bar\ Kokhba\ Sextet\ -\ Lucifer.opus
Billy\ Bang\ -\ Vietnam\ the\ Aftermath.mp3

这是有道理的,但也很难读懂;我想:

[~/music]% mpv <Tab>
Acid Eater - Black Fuzz On Wheels.ogg         Angel'in Heavy Syrup 4.mp3
Akalé Wubé - Akalé Wubé.opus                  Astor Piazzolla & Gary Burton - The New Tango.mp3
Allen Toussaint - The Bright Mississippi.mp3  B.B. King - Live at the Regal.mp3
Angel'in Heavy Syrup 1.opus                   Bar Kokhba Sextet - Lucifer.opus
Angel'in Heavy Syrup 2.opus                   Billy Bang - Vietnam the Aftermath.mp3
Angel'in Heavy Syrup 3.mp3

[~/music]% mpv Acid<Tab>
# Completes to:
[~/music]% mpv Acid\ Eater\ -\ Black\ Fuzz\ On\ Wheels.ogg

# It's okay to type escapes on the cmdline; it's just the display.
[~/music]% mpv Angel\'in\ H<Tab>
Angel'in Heavy Syrup 1.opus  Angel'in Heavy Syrup 3.mp3
Angel'in Heavy Syrup 2.opus  Angel'in Heavy Syrup 4.mp3

我花了一些时间阅读 zshcompsys(1),但我并没有真正找到一种方法来做到这一点。

答案1

您始终可以键入mpv '<Tab>(并且 zsh 将完成'...'带引号的字符串)。与"或相同$'。如果其中有需要转义的字符(例如'某些文件名中的 ),您仍然会看到反斜杠。

带单引号的屏幕截图

看起来这些's 也影响颜色;可能是一个错误。用双引号更好:

带双引号的屏幕截图

相关内容