jethrokuan / z

Pure-fish z directory jumping
MIT License
1.29k stars 45 forks source link

Z error when launching fish from PyCharm #82

Closed mcarans closed 4 years ago

mcarans commented 4 years ago

~/.config/fish/conf.d/z.fish (line 40): __z_complete ^ from sourcing file ~/.config/fish/conf.d/z.fish called on line 9 of file ~/Applications/pycharm-community/plugins/terminal/fish/config.fish from sourcing file ~/Applications/pycharm-community/plugins/terminal/fish/config.fish called during startup

I'm running PyCharm Community 2019.3 on Linux Mint 19.2. When I start a terminal in PyCharm I get the above error. fish version is version 3.0.2-1953-gcc7ae030.

jethrokuan commented 4 years ago

Can I see the contents of ~/Applications/pycharm-community/plugins/terminal/fish/config.fish? It's likely that PyCharm's terminal doesn't autoload the ~/.config/fish/functions folder, causing this issue.

krobelus commented 4 years ago

It looks like they set XDG_CONFIG_HOME to source their own config; which results in ~/.config/fish/{functions,completions} being missing from $fish_function_path and $fish_complete_path respectively.

Same for $__fish_config_dir, which results in https://youtrack.jetbrains.com/issue/IDEA-189670

mcarans commented 4 years ago

Can I see the contents of ~/Applications/pycharm-community/plugins/terminal/fish/config.fish? It's likely that PyCharm's terminal doesn't autoload the ~/.config/fish/functions folder, causing this issue.

if test -n "$OLD_XDG_CONFIG_HOME"
  set XDG_CONFIG_HOME "$OLD_XDG_CONFIG_HOME"
else
  set -e XDG_CONFIG_HOME
end

if test -d ~/.config/fish/conf.d
  for f in ~/.config/fish/conf.d/*.fish
    source $f
  end
end

if test -d ~/.config/fish/functions
  for f in ~/.config/fish/functions/*.fish
    source $f
  end
end

if test -f ~/.config/fish/config.fish
  . ~/.config/fish/config.fish
end

if test -n "$JEDITERM_USER_RCFILE"
  . "$JEDITERM_USER_RCFILE"
  set -e JEDITERM_USER_RCFILE
end

if test -n "$JEDITERM_SOURCE"
  . "$JEDITERM_SOURCE"
  set -e JEDITERM_SOURCE
end

function override_jb_variables
  if not type "string" > /dev/null
    return
  end
  for variable in (env)
    set name_and_value (string split -m 1 "=" -- $variable)
    set name $name_and_value[1]
    set value $name_and_value[2]
    if string match -q -- "_INTELLIJ_FORCE_SET_*" $name
      set new_name (string sub -s 21 -- $name)
      if [ $new_name ]
        if [ $new_name = "PATH" ]; or [ $new_name = "CDPATH" ]; or [ $new_name = "MANPATH" ]
            set -x $new_name (string split ":" -- $value)
        else
            set -x $new_name $value
        end
      end
    end
  end
end

override_jb_variables
krobelus commented 4 years ago

Disabling shell integration seems in PyCharm Preferences seems to fix it, see https://youtrack.jetbrains.com/issue/IDEA-167217

It would be nice to bring a proper fix upstream, it looks like the shipped config.fish doesn't do much anyways, so it seems unnecessary to execute fish with a different config home.

mcarans commented 4 years ago

I can see that there are lots of fish issues against PyCharm eg.: https://youtrack.jetbrains.com/issue/IDEA-169111 (Fish user functions not loaded) https://youtrack.jetbrains.com/issue/IDEA-189670 (Fish user functions and terminal still broken) https://youtrack.jetbrains.com/issue/IDEA-227054 (Fish terminal integration loads functions after conf.d (unlike fish itself))

The last one specifically mentions the z plugin: "I encountered this after adding a plugin (namely 'z') to fish." A proposed solution is given: "The ~/.config/fish/functions are loaded after the ~/.config/fish/conf.d. Switching the order fixes the issue."

jethrokuan commented 4 years ago

I believe the fix in https://youtrack.jetbrains.com/issue/IDEA-227054 is the ideal one as well, but wow I had no idea fish integration in Pycharm was so hacky

mcarans commented 4 years ago

I've added a comment to that JetBrains issue. Hopefully they'll get around to making the fix. I can confirm that switching the ~/.config/fish/functions to be before instead of after the ~/.config/fish/conf.d lines in pycharm-community/plugins/terminal/fish/config.fish fixes it.

Closing this issue as problem is upstream. Thanks for the help!

mcarans commented 4 years ago

It will be fixed in PyCharm 2020.1: https://youtrack.jetbrains.com/issue/IDEA-227054#focus=streamItem-27-3873336.0-0