Case-Insensitive ZSH Suffix Aliases
Asked Answered
B

4

6

In my .zshrc I've set up suffix completion aliases like this so that I can open files more easily:

alias -s -- txt='mate -w'

Which allows me to open text files in my text editor without prepending the editor command.

There is a problem, however, when I am attempting to open a file with a capitalized suffix. ZSH will recognize '.txt' and open it in my text editor but not '.TXT.'

Is there any way to make ZSH suffix recognition case-insensitive so that I can open files like these?

Borek answered 18/7, 2009 at 18:28 Comment(1)
hm, even nocaseglob is ignored with alias -sAvner
F
5

Let me hazard a guess :)

alias -s -- TXT='mate -w'
alias -s -- Txt='mate -w'
alias -s -- TXt='mate -w'
alias -s -- tXt='mate -w'
alias -s -- txT='mate -w'
alias -s -- tXT='mate -w'
alias -s -- TxT='mate -w'
Forgather answered 18/7, 2009 at 18:53 Comment(1)
This seems to be the extrapolated version of my single line answer. By interpolation of combinatorics via the shell, I'm able to get the equivalent of your's by doing this: alias -s {t,T}{x,X}{t,T}=cat.Lambert
B
4

This seems to fix it for me:

setopt extendedglob
unsetopt CASE_GLOB

I got the solution from this question

Borek answered 20/7, 2009 at 0:58 Comment(0)
E
0

You can define the suffix aliases once in lower case and redefine them with the extensions programmatically converted to uppercase:

for ext in ${(k)saliases}; alias -s $ext:u=$saliases[$ext]
Elinorelinore answered 18/5, 2020 at 14:14 Comment(0)
L
0

The following uses the extrapolation of t and T, x and X, and finally t and T. This is really just simplistic combinatorics code, an then assigns that cat.

alias -s {t,T}{x,X}{t,T}=cat

If you run something like echo {t,T}{x,X}{t,T} you can see that I'm just interpolating ttt ttT tTt tTT Ttt TtT TTt TTT in to the alias.

Lambert answered 1/4, 2023 at 4:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.