How do I get sudo to find my aliases when using zsh?

I have setup .bash_aliases and source that file in .zshrc and everything works as it should, for that user.
But if I try to use sudo and “tab” it wont search the aliases.

I also add a location to $PATH in .zshrc and THAT is fetched without problems with sudo.

If I use bash instead (with .bashrc) sudo finds my aliases just fine.

I have the alias sudo='sudo ' thing in the aliases…

How do I get zsh to find my aliases as sudo?
(yes, I can add sudo in front of my aliases that needs it in .bash_aliases but I rather not, besides, it works in bash, should be able to work in zsh aswell no?)

That could be an assumption - but you just demonstrated the opposite.

That leads one to think if there is a plugin zsh_completions like there is a plugin bash_completions

Writing this - I think the zsh completion is already there as part of manjaro-zsh-config.

Doing a quick check in Pamac

 $ pamac info manjaro-zsh-config
Name                  : manjaro-zsh-config
Version               : 0.26-1
Description           : Zsh configuration for manjaro
URL                   : https://github.com/Chrysostomus/manjaro-zsh-config
Licenses              : MIT
Repository            : extra
Installed Size        : 464,4 kB
Groups                : --
Depends On            : zsh-autosuggestions zsh-syntax-highlighting zsh-completions
                        zsh-history-substring-search zsh ttf-meslo-nerd-font-powerlevel10k
                        zsh-theme-powerlevel10k
[...]

yes zsh-completions is a dependency for manjaro-zsh-config.

1 Like

Can you point me in a direction of some documentation?
I have spent a couple of hours trying to solve this silly (yes it is very silly) problem for me. xD

Is it this?
https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org

Could be - although I would probably dive into how bash handles the alias.

Wait - wait … I think there is a zsh plugin for oh-my-zsh which is named alias.

The manjaro config builds upon elements from oh-my-zsh … found it - perhaps you can some ideas here

Or this is not what I am thinking it is - the phrase basedon the plugins you have enabled

shortcuts that are currently available based on the plugins you have enabled

In the list of plugins there is the alias-finder - maybe that is more in line of your needs.

I am not sure I am being helpful here

  • I dropped zsh some time ago
  • I was kind of fond of it for a while
  • I don’t know why I started to dislike
  • I was among those advocating a change to zsh for Manjaro

… but now … I find myself liking bash (and oh-my-bash) better.

Thank you.

Not sure if I should place the plugins=(alias-finder) in my ~/.zshrc or in the config that is sourced (/usr/share/zsh/manjaro-zsh-config)

I tried in .zshrc but it did not change anything.
And with plugins=(aliases) I should be able to use als in cli to “show all aliases by group”. The command is not found.

No idea what I should do, I guess “test different config files until I run out of ideas” is what I have to do first.

You pointed me in a direction and I thank you for that sir!

What I think you could try ,is to use the installer script for oh-my-zsh, and create a default install.

You need the oh-my-zsh environment, to actually use the plugin structure.

If I recall correctly - the script will backup your current .zshrc and create a new default.

In any case you can preserve your .zshrc by copying to a bak extension - it is easily restored.

wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
sh install.sh

oh-my-zsh Plugins

Edit your .zshrc and add your desired theme and plugins.

It cannot be stressed enough, that one should not get carried away by the opportunities - too many active plugins make your shell a PIA.

1 Like

Did you actually set up oh-my-zsh?

Thank you, I might look deeper into this.
I have not installed oh-my-zsh (did not understand that was a requirement, I thought I could change the manjaro-zsh configs or .zshrc)

But thank you, I will look into this, sometime, because as I said, it is a bit “silly”.
For now, I will complete my aliases then press home > sudo > space… Because this is outside what I know, but am willing to learn.

Thanks!

1 Like