I know I can probably get around this by defining a function, but I was curious why the semicolon gives me so many bugs?
>Solution :
; is a special shell character used to separate commands; for example this:
% ls /; ls /etc
Is (mostly) the same as if you had typed:
% ls /
% ls /etc
A : on the other hand is merely a special shell builtin, and can be overridden.
There may be tricks to override this; you can’t "just" override it with functions either, but I would strongly recommend against it as I suspect it will only bring you confusion and errors. There are plenty of other characters on the keyboard that can be used 🙂
That said, you can use a global alias to override ; to call a function:
% alias -g ';'='semicolon'
% semicolon() { print -r -- semicolon: $@ }
% ;hello
semicolon: hello
You’ll have to modify that semicolon function though.
Note this will apply everywhere on the commandline, including in the middle of a command:
% ls ; ls
ls: cannot access 'semicolon': No such file or directory
ls: cannot access 'ls': No such file or directory
You could modify the semicolon() function a bit to be smart about at least some scenarios, but I would strongly recommend against it.