Hello,
I am writing from a fresh install of Manjaro sway.
It appears that the aliases defined in the file /usr/share/zsh/manjaro-zsh-config (lines 58-61) are somehow broken.
Example when I type cp:
> cp
zsh: defining function based on alias `f'
zsh: parse error near `()'
Looks more like some function somewhere is broken. Are you sure itās a fresh install, without a single change on your side?
If you suspect that something causes something else, then you can test it yourself. In this case commenting out those aliases. But as I said, this probably wonāt make any difference, since problem is somewhere else.
Iām sorry, it was my mistake.
After double-checking everything I found out that I had defined my own alias for f which conflicted with the alias definitions from manjaro-zsh-config.
Is it not possible to have my own alias for f, as it is not really used by manjaro-zsh-config? I donāt understand everything what these lines are exactly doing. @TriMoon these are the lines in my file:
## Alias section
alias cp='f(){fo=${1:--i}; shift; cp $fo $*};f' # Confirm before overwriting something
alias df='f(){if test $# -eq 0;then opts=(-h);else opts=("$@");fi; df "$opts[@]"};f' # Human-readable sizes
alias free='f(){if test $# -eq 0;then opts=(-m);else opts=("$@");fi; free "$opts[@]"};f' # Show sizes in MB
alias gitu='git add . && git commit && git push'
It should be ok if you define yours after the imported ones from manjaro-zsh-config, because it shouldnāt be used in those definitions then i guessā¦
If they still clash, just rename your f to f1 or something
Unless you know a way to use anonymous function definition and use at same time in one line in shell-script, like they do in javascript, which i donāt know of
The problem seems to be because of the zsh-syntax-highlighting plugin which is installed and active by default in my installation.
In the file /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh on line 443 it somehow redefines all previously defined aliases by doing this:
eval "$zsh_highlight__aliases"
When I define my own alias for f in .zshrc it will somehow interfere in a bad way with what this plugin is doing. This is all I can investigate with my linux knowledge.
Iām using the defaults also and i donāt have any problems, maybe because i donāt create my own f() anywhere as a standalone function
The solution can only be found when you post your actual .zshrc then i guess
PS:
Please rename the topic title, because it is not the manjaro-zsh-config that is broken but more your definition in .zshrc as it seemsā¦
(Otherwise that file would be broken for everyone)
FYI: I still had the definitions for the modified cp/df/free in my .zshrc because i hadnāt noticed the changes were already present in the updated package, so i removed them again in mine. Thx for reminding me
Because the way i did it, which i found on stack-exchange or similar, is only an inline function that only persists for the duration of that aliasā¦
Hence why i can re-define the same function in another aliasā¦
Defining a function outside an alias would make it a global function, which would need different logic per caller of it.
May i remind you that this was done in /usr/share/zsh/manjaro-zsh-configwhich defined the default aliases i āfixedā with my MR?
Sure the maintainers of that package could use a function definitions instead of those aliases they use now, but then it wouldnāt be an alias anymore. (Which undoubtedly would render them unfit for that file)
Feel free to improve it even more (that way) like i did with a MR
Yes. Probably because in previous aliases, with hacky functions inside, you are defining function āfā and then running it at the end. But in reality when zsh tries to run that last āfā it first looks into aliases that have precedence before functions where it finds a match.
Anyway, itās not exactly like that, since it already errors at function definition, but Iām just thinking loudly how things can go quickly south.
If you have to use functions inside aliases why not do something like this then:
alias df='(){if test $# -eq 0;then opts=(-h);else opts=("$@");fi; df "$opts[@]"}'
Does that work?
I never tried that way, but it is ofcourse better to use anonymous functions ala Javascript if zsh allows stuff like that.
Try it out and if it work, please create a MR to fix the way āi tried to fix itā, weāre all humans and users of each others codes
The solution i used worked for my use-case, and i never thought about the possibility of the problem mentioned here could even happen
PS: As said i found my solution via the internet on a site like stack-exchange, where they discussed things like this.