ohmyzsh / ohmyzsh

🙃 A delightful community-driven (with 2,300+ contributors) framework for managing your zsh configuration. Includes 300+ optional plugins (rails, git, macOS, hub, docker, homebrew, node, php, python, etc), 140+ themes to spice up your morning, and an auto-update tool so that makes it easy to keep up with the latest updates from the community.

Home Page:https://ohmyz.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`omz plugin disable` breaks .zshrc file when disabling common substring

alexrosenfeld10 opened this issue · comments

Describe the bug

omz plugin disable git will break a zshrc file with plugins that look like this:

plugins=(
    git
    git-open
    autoupdate
    zsh-syntax-highlighting
    zsh-autosuggestions
    autojump
    brew
    docker
    fzf
    rust
    thefuck
    zsh-interactive-cd
    zsh-bat
    asdf
)

Steps to reproduce

  1. Set up OhMyZsh
  2. Set up plugins, for example:
plugins=(git autoupdate git-open zsh-syntax-highlighting zsh-autosuggestions autojump brew docker fzf rust thefuck zsh-interactive-cd zsh-bat asdf)

or

plugins=(
    git
    autoupdate
    git-open
    zsh-syntax-highlighting
    zsh-autosuggestions
    autojump
    brew
    docker
    fzf
    rust
    thefuck
    zsh-interactive-cd
    zsh-bat
    asdf
)
  1. run omz plugin disable git

Expected behavior

The git plugin gets removed, and the git-open plugin isn't impacted. This isn't quite what happens though, the actual result is:

plugins=(
    autoupdate
-open
    zsh-syntax-highlighting
    zsh-autosuggestions
    autojump
    brew
    docker
    fzf
    rust
    thefuck
    zsh-interactive-cd
    zsh-bat
    asdf
)

Note - the same behavior happens when plugins is one line:

# this:
plugins=(git autoupdate git-open zsh-syntax-highlighting zsh-autosuggestions autojump brew docker fzf rust thefuck zsh-interactive-cd zsh-bat asdf)

# gets turned into:
plugins=(autoupdate-open zsh-syntax-highlighting zsh-autosuggestions autojump brew docker fzf rust thefuck zsh-interactive-cd zsh-bat asdf)

Screenshots and recordings

No response

OS / Linux distribution

macOS

Zsh version

5.9

Oh My Zsh version

master (668ca3a)

Terminal emulator

iTerm2

If using WSL on Windows, which version of WSL

None

Additional context

No response

Oops that's my bad, thanks for the submission! I'll take a look shortly.

Can you test in your macOS whether #12401 fixes this correctly? I'm not too sure about AWK regex support in there. You can test it out with omz pr test 12401.

@mcornella thanks for the quick reply. Here's the result of the test:

take one, all in one line

~/.zshrc file plugins section before:

plugins=(git autoupdate git-open zsh-syntax-highlighting zsh-autosuggestions autojump brew docker fzf rust thefuck zsh-interactive-cd zsh-bat asdf)

result:

❯ omz pr test 12401
❯ code ~/.zshrc
❯ omz plugin disable git
/Users/alexrosenfeld/.zshrc:81: parse error near `)'
omz::plugin::disable: broken syntax in '~/.zshrc'. Rolling back changes...

~/.zshrc file plugins section after, unchanged.

take two, with newlines instead

~/.zshrc file plugins section before:

plugins=(
  git
  autoupdate
  git-open
  zsh-syntax-highlighting
  zsh-autosuggestions
  autojump
  brew
  docker
  fzf
  rust
  thefuck
  zsh-interactive-cd
  zsh-bat
  asdf
)

command result:

❯ omz pr test 12401
❯ code ~/.zshrc
❯ omz plugin disable git
omz::plugin::disable: plugins disabled: git.

~/.zshrc file plugins section after, result looks good:

plugins=(
  autoupdate
  git-open
  zsh-syntax-highlighting
  zsh-autosuggestions
  autojump
  brew
  docker
  fzf
  rust
  thefuck
  zsh-interactive-cd
  zsh-bat
  asdf
)

take three, bonus round, new error case discovered

starting state, same as take two (plugins separated by newlines):

plugins=(
  git
  autoupdate
  git-open
  zsh-syntax-highlighting
  zsh-autosuggestions
  autojump
  brew
  docker
  fzf
  rust
  thefuck
  zsh-interactive-cd
  zsh-bat
  asdf
)

shell commands:

❯ omz plugin disable git
omz::plugin::disable: plugins disabled: git.
❯ omz plugin enable git
omz::plugin::enable: plugins enabled: git.
❯ omz plugin disable git
/Users/alexrosenfeld/.zshrc:127: parse error near `\n'
omz::plugin::disable: broken syntax in '~/.zshrc'. Rolling back changes...

state after the first disable + first enable:

plugins=(
  autoupdate
  git-open
  zsh-syntax-highlighting
  zsh-autosuggestions
  autojump
  brew
  docker
  fzf
  rust
  thefuck
  zsh-interactive-cd
  zsh-bat
  asdf
 git)

Fixed that now as well, can you try again?

@mcornella still seems there are some issues:

results:

plugin array without newlines

❯ omz pr test 12401
omz::pr::test: fetching PR #12401 to ohmyzsh/pull-12401...
remote: Enumerating objects: 13, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 3), reused 2 (delta 1), pack-reused 0
Unpacking objects: 100% (4/4), 850 bytes | 212.00 KiB/s, done.
From https://github.com/ohmyzsh/ohmyzsh
 + 141a154...2d7a73e refs/pull/12401/head -> ohmyzsh/pull-12401  (forced update)
omz::pr::test: rebasing PR #12401...
Successfully rebased and updated refs/heads/ohmyzsh/pull-12401.
omz::pr::test: fetch of PR #12401 successful.
omz::pr::test: running `zsh` to test the changes. Run `exit` to go back.
❯ omz plugin disable git
/Users/alexrosenfeld/.zshrc:81: parse error near `)'
omz::plugin::disable: broken syntax in '~/.zshrc'. Rolling back changes...

plugin array with newlines

❯ omz plugin disable git
omz::plugin::disable: plugins disabled: git.
❯ omz plugin enable git
omz::plugin::enable: plugins enabled: git.
❯ omz plugin disable git
/Users/alexrosenfeld/.zshrc:129: parse error near `\n'
omz::plugin::disable: broken syntax in '~/.zshrc'. Rolling back changes...

Maybe there's a way for you to test your changes without back and fourth? I don't mind helping at all, but at the same time, it doesn't seem the most efficient

OK that should be all the edge cases fixed now. I introduced a test suite which will be refactored into its own thing in the future. Sorry for the back and forth, I was in a rush this morning to get this out.

The tests already done here are working correctly.

@mcornella thanks for fixing. I think there are still some issues here though:

~/.zshrc:

plugins=(
  git
  git-open
  autoupdate
  zsh-syntax-highlighting
  zsh-autosuggestions
  autojump
  brew
  docker
  fzf
  rust
  thefuck
  zsh-interactive-cd
  zsh-bat
  asdf
)

result:

❯ omz plugin disable git
omz::plugin::disable: plugin 'git' is not enabled.

same behavior for

plugins=(git git-open autoupdate zsh-syntax-highlighting zsh-autosuggestions autojump brew docker fzf rust thefuck zsh-interactive-cd zsh-bat asdf)

The function only disables a plugin if it's in the $plugins array within the session. That's by design. If you make changes to it, you should omz reload beforehand.

ah, got it, ok. thanks!!