IlanCosman / tide

🌊 The ultimate Fish prompt.
MIT License
2.87k stars 107 forks source link

It barfs with miniconda #78

Closed wirtsi closed 3 years ago

wirtsi commented 3 years ago

Describe the bug

tide doesn't like the way miniconda is hooking itself

Steps to reproduce

Add these lines to config.fish

>>> conda initialize >>>
!! Contents within this block are managed by 'conda init' !!
eval /Users/wirtsi/miniforge3/bin/conda "shell.fish" "hook" | source
<<< conda initialize <<<

And you get these errors

~/.config/fish/config.fish (line 46): Expected a command, but instead found a redirection
>>> conda initialize >>>
^
from sourcing file ~/.config/fish/config.fish
    called during startup
source: Fehler beim Lesen der Datei '/Users/wirtsi/.config/fish/config.fish'
Welcome to fish, the friendly interactive shell
~/.config/fish/config.fish (line 46): Expected a command, but instead found a redirection
>>> conda initialize >>>
^
from sourcing file ~/.config/fish/config.fish
    called during startup
~/.config/fish/config.fish (line 46): Expected a command, but instead found a redirection
>>> conda initialize >>>
^
from sourcing file ~/.config/fish/config.fish
    called during startup
source: Error while reading file '/Users/wirtsi/.config/fish/config.fish'
source: Error while reading file '/Users/wirtsi/.config/fish/config.fish'
~/.config/fish/config.fish (line 46): Expected a command, but instead found a redirection
>>> conda initialize >>>
^
from sourcing file ~/.config/fish/config.fish
    called during startup
source: Error while reading file '/Users/wirtsi/.config/fish/config.fish'
 ~ ~/.config/fish/config.fish (line 46): Expected a command, but instead found a redirection                                                                                                                                                            ✔ 
>>> conda initialize >>>
^
from sourcing file ~/.config/fish/config.fish
    called during startup
source: Error while reading file '/Users/wirtsi/.config/fish/config.fish'

The conda init script outputs this and pipes it to fish, I guess there it clashes with the right prompt setup

set -gx CONDA_EXE "/Users/wirtsi/miniforge3/bin/conda"
set _CONDA_ROOT "/Users/wirtsi/miniforge3"
set _CONDA_EXE "/Users/wirtsi/miniforge3/bin/conda"
set -gx CONDA_PYTHON_EXE "/Users/wirtsi/miniforge3/bin/python"
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
#
# INSTALL
#
#     Run 'conda init fish' and restart your shell.
#

if not set -q CONDA_SHLVL
    set -gx CONDA_SHLVL "0"
    set -g _CONDA_ROOT (dirname (dirname $CONDA_EXE))
    set -gx PATH $_CONDA_ROOT/condabin $PATH
end

function __conda_add_prompt
  if set -q CONDA_PROMPT_MODIFIER
      set_color -o green
      echo -n $CONDA_PROMPT_MODIFIER
      set_color normal
  end
end

if functions -q fish_prompt
    if not functions -q __fish_prompt_orig
        functions -c fish_prompt __fish_prompt_orig
    end
    functions -e fish_prompt
else
    function __fish_prompt_orig
    end
end

function return_last_status
  return $argv
end

function fish_prompt
  set -l last_status $status
  if set -q CONDA_LEFT_PROMPT
      __conda_add_prompt
  end
  return_last_status $last_status
  __fish_prompt_orig
end

if functions -q fish_right_prompt
    if not functions -q __fish_right_prompt_orig
        functions -c fish_right_prompt __fish_right_prompt_orig
    end
    functions -e fish_right_prompt
else
    function __fish_right_prompt_orig
    end
end

function fish_right_prompt
  if not set -q CONDA_LEFT_PROMPT
      __conda_add_prompt
  end
  __fish_right_prompt_orig
end

function conda --inherit-variable CONDA_EXE
    if [ (count $argv) -lt 1 ]
        eval $CONDA_EXE
    else
        set -l cmd $argv[1]
        set -e argv[1]
        switch $cmd
            case activate deactivate
                eval (eval $CONDA_EXE shell.fish $cmd $argv)
            case install update upgrade remove uninstall
                eval $CONDA_EXE $cmd $argv
                and eval (eval $CONDA_EXE shell.fish reactivate)
            case '*'
                eval $CONDA_EXE $cmd $argv
        end
    end
end

# Autocompletions below

# Faster but less tested (?)
function __fish_conda_commands
  string replace -r '.*_([a-z]+)\.py$' '$1' $_CONDA_ROOT/lib/python*/site-packages/conda/cli/main_*.py
  for f in $_CONDA_ROOT/bin/conda-*
    if test -x "$f" -a ! -d "$f"
      string replace -r '^.*/conda-' '' "$f"
    end
  end
  echo activate
  echo deactivate
end

function __fish_conda_env_commands
  string replace -r '.*_([a-z]+)\.py$' '$1' $_CONDA_ROOT/lib/python*/site-packages/conda_env/cli/main_*.py
end

function __fish_conda_envs
  conda config --json --show envs_dirs | python -c "import json, os, sys; from os.path import isdir, join; print('\n'.join(d for ed in json.load(sys.stdin)['envs_dirs'] if isdir(ed) for d in os.listdir(ed) if isdir(join(ed, d))))"
end

function __fish_conda_packages
  conda list | awk 'NR > 3 {print $1}'
end

function __fish_conda_needs_command
  set cmd (commandline -opc)
  if [ (count $cmd) -eq 1 -a $cmd[1] = 'conda' ]
    return 0
  end
  return 1
end

function __fish_conda_using_command
  set cmd (commandline -opc)
  if [ (count $cmd) -gt 1 ]
    if [ $argv[1] = $cmd[2] ]
      return 0
    end
  end
  return 1
end

# Conda commands
complete -f -c conda -n '__fish_conda_needs_command' -a '(__fish_conda_commands)'
complete -f -c conda -n '__fish_conda_using_command env' -a '(__fish_conda_env_commands)'

# Commands that need environment as parameter
complete -f -c conda -n '__fish_conda_using_command activate' -a '(__fish_conda_envs)'

# Commands that need package as parameter
complete -f -c conda -n '__fish_conda_using_command remove' -a '(__fish_conda_packages)'
complete -f -c conda -n '__fish_conda_using_command uninstall' -a '(__fish_conda_packages)'
complete -f -c conda -n '__fish_conda_using_command upgrade' -a '(__fish_conda_packages)'
complete -f -c conda -n '__fish_conda_using_command update' -a '(__fish_conda_packages)'

conda activate base

Expected behavior

Tide play along with miniconda, spacefish managed to do it :-)

Environment (please complete the following information)

fish, version 3.1.2
tide, version 3.2.0
xterm-kitty
IlanCosman commented 3 years ago

I'll look into it. First we should correct some basic stuff though:

>>> conda initialize >>>
!! Contents within this block are managed by 'conda init' !!
eval /Users/wirtsi/miniforge3/bin/conda "shell.fish" "hook" | source
<<< conda initialize <<<

That is not valid fish syntax. Of course fish complains. Can you remove those conda initialize lines? Might fix the issue.

EDIT: Just remove everything but the eval line.

wirtsi commented 3 years ago

Hey ... cool, thanks a lot 👯

The above was a copy & paste error, there are comment hashes before every line except the eval one. Sorry about that. So it actually looks like this

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
eval /Users/wirtsi/miniforge3/bin/conda "shell.fish" "hook" $argv | source
# <<< conda initialize <<<
IlanCosman commented 3 years ago

Are you still getting errors? If so, which ones?

wirtsi commented 3 years ago

Errors are

commandline: Can not set commandline in non-interactive mode                                                                                                                                                                                         ✔ 

~/.config/fish/functions/fish_prompt.fish (Zeile 30): 
    commandline --function force-repaint
    ^
in function '_tide_refresh_prompt' with arguments 'VARIABLE SET _tide_right_prompt_display_60780'
    called on line 1 of file ~/.config/fish/functions/_tide_right_prompt.fish
in event handler: handler for variable '_tide_right_prompt_display_60780'
    called on line 24 of file ~/.config/fish/functions/_tide_right_prompt.fish

(Type 'help commandline' for related documentation)
commandline: Can not set commandline in non-interactive mode

~/.config/fish/functions/fish_prompt.fish (Zeile 30): 
    commandline --function force-repaint
    ^
in function '_tide_refresh_prompt' with arguments 'VARIABLE ERASE _tide_right_prompt_display_60780'
    called on line 1 of file ~/.config/fish/functions/fish_prompt.fish
in event handler: handler for variable '_tide_right_prompt_display_60780'
    called on line 36 of file ~/.config/fish/functions/fish_prompt.fish

(Type 'help commandline' for related documentation)
jorgebucaran commented 3 years ago

Looks very similar to https://github.com/jorgebucaran/hydro/issues/6. Try this in your config.fish:

status is-interactive && eval /Users/wirtsi/miniforge3/bin/conda "shell.fish" "hook" $argv | source
wirtsi commented 3 years ago

👍 That fixed it ... thank you very much, that was incredibly fast! Have a nice evening!