Reputation: 415
I am currently trying to work on a dotfiles repository using several git submodules such as dotbot and a dotbot-brewfile. I'm looking to ask a few questions in this post to help make sure I better handle zsh related plugins and the powerlevel10k theme.
~/dotfiles/Homebrew/Brewfile
tap 'romkatv/powerlevel10k'
brew 'zsh-syntax-highlighting'
If I'm installing powerlevel10k with homebrew do I still need to add this command?
- description: install powerlevel10k
command: "if [ ! -d ~/.oh-my-zsh/custom/themes/powerlevel10k ]; then git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $HOME/.oh-my-zsh/custom/themes/powerlevel10k; fi"
I'm also trying to figure out what I am missing so that the following zsh plugins can be used inside of my zshrc file. Do I need to download each of them from homebrew? Then I need to figure out since this is for my dotfiles is there files I need to source so that my zshrc file knows where those plugins are.
~/dotfiles/zsh/.zshrc
plugins=(zsh-autosuggestions zsh-syntax-highlighting)
Upvotes: 1
Views: 14419
Reputation: 420
The command you asked about will download and install zsh-syntax-highlighting
into a specific place. Also, it should have been written differently to account for anyone who set their ZSH_CUSTOM variable to a non-default value. The $HOME/.oh-my-zsh/custom/themes/powerlevel10k
section should be ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
for it to work as expected regardless of your custom folder setup.
That said, you may not want to use that command (if you want to brew install). If using it fixes things, that just means you may not be using the location that brew had installed it into. That could be confusing when trying to update or find stuff. The alternative is to remove your brew installation of the plugin and just use this command (replacing the part I mentioned) instead.
It looks like you are probably using Oh-My-Zsh. Typically that sets the environment variable ZSH
to the directory it is installed (typically in your home directory, in a directory starting with a period, AKA $HOME/.oh-my-zsh
). You may also see it sets the environment variable ZSH_CUSTOM
(default is $ZSH/custom
which in the default context is another way to say $HOME/.oh-my-zsh/custom
, but I personally like setting it somewhere else, like a different directory inside by dotfiles
directory).
Understanding $ZSH
and $ZSH_CUSTOM
, and knowing the values, makes it easier to understand if (and from what location) a plugin can be installed. In each of those directories (for whatever location they are each set to) we expect them to have plugins/
and themes/
directories. We also expect a sub-directory, written to match the desired plugin name, to be in at least one of $ZSH_CUSTOM/plugins
or $ZSH/plugins
directories. If a plugin exists in both places, the $ZSH_CUSTOM/plugins
one will take priority.
If you had the following (using fake plugin names) in your .zshrc
file:
plugins=(first-plugin another-plugin third-doohickey favorite-thingy)
While the following directories existed (notice the incorrect dash vs underline):
$ZSH_CUSTOM/plugins/first-plugin/
$ZSH_CUSTOM/plugins/another_plugin/
$ZSH_CUSTOM/plugins/fourth-thing/
...
$ZSH/plugins/some-plugin/
$ZSH/plugins/another-plugin/
$ZSH/plugins/favorite-thingy/
...
<some-other-directory>/plugins/third-doohickey/
...
Then, assuming the directories had the expected files, the actual source of the plugins loaded (in order) would be:
$ZSH_CUSTOM/plugins/first-plugin/
$ZSH/plugins/another-plugin/
$ZSH/plugins/favorite-thingy/
Notice it would never find third-doohickey
because it was not in a valid location. Of course plugins not listed in the plugins variable are ignored.
While uncommon, sometimes the order you list (and thus sourced) the plugins does matter. Specifically, I believe I've heard it is best to have zsh-syntax-highlighting
as close to the end as you can, and that zsh-autosuggestions
should come after it. AKA, they should be the last two in that order. I'm not 100% sure how much that is true, but that's what I got.
This all brings out, that if your brew install (or even the command you mentioned) puts the plugin in a directory not matching $ZSH_CUSTOM/plugins
or $ZSH/plugins
, it won't work. You can change the file location, or change the variable values as you see fit.
Likewise, plugins later in the list can overwrite earlier plugin settings but plugins needing to know the context of others needs to be listed later. Otherwise it won't work as you want, at least until you fix the order.
#zsh #oh-my-zsh #shell #dotfiles #zshrc
Upvotes: 3