tl;dr - I want to override OhMyZsh's Git aliases with multi-line aliases / functions.
I'm trying to make the switch over from bash
to zsh
and migrate my aliases. I'm able to override Git aliases from OhMyZsh via this (example):
alias grs="git restore --staged ."
However, when I try to use zsh
functions (for aliases that already exist in OhMyZsh):
grs() {
if [ $# -eq 0 ]
then
git restore --staged .
else
git restore --staged "$@"
fi
}
it results in this error:
/Users/StevenChoi/.aliases/.zsh_aliases/.g_aliases.zsh:102: defining function based on alias `grs'
/Users/StevenChoi/.aliases/.zsh_aliases/.g_aliases.zsh:102: parse error near `()'
When I try bash
-style functions:
function grs() {
They just get ignored.
Things I've tried
I've moved around when I export or source OhMyZsh and my aliases within
.zshrc
(citation here), but no difference.I've tried using
ZSH_CUSTOM=/Users/StevenChoi/.aliases/.zsh_aliases
and creating aplugins
folder (I think I followed these directions correctly), but same result.I've added
#!/bin/zsh
at the top of each file and.zsh
at the end of each filename, just to be thorough (not that I expected much).NOTE: I also want to avoid touching
.oh-my-zsh/plugins/git/git.plugin.zsh
and the.oh-my-zsh
directory, unless it's the only way.EDIT: Condensing the commands into one line sacrifices parameter handling. I've been using the solution I've provided for myself for now, but it cannot handle parameters, returning them only as empty string. For a better solution, it must be a multi-line alias / function that both replaces an alias in OhMyZsh and also accepts and handles parameters.
alias
with a ZSH function doing something different [specifically, handling parameters]. If that's the case, why not just unset the existing alias prior to creating a function with the same name in your~/.zshrc
? Loadoh-my-zsh
, unset things you want to replace, replace them? See this – Dewan