jorgebucaran / fisher

A plugin manager for Fish
https://git.io/fisher
MIT License
7.55k stars 257 forks source link

Fisher 4 closes shell after update #655

Closed nathan-gilbert closed 3 years ago

nathan-gilbert commented 3 years ago

Every time I run fisher update, after it completes the shell exits.

I've tried uninstalling everything and reinstalling fisher but the problem persists. Anything I can try to figure out what is causing the shell to exit?

jorgebucaran commented 3 years ago

Maybe there's an extraneous exit or an exec fish in your config.fish. Try commenting out everything in it and run fisher update again. If that goes well, then you know it's an issue with your configuration, not Fisher.

If you share your config.fish, I'm happy to have a look and suggest improvements, you may be missing a status is-interactive somewhere, or writing something to stdout that causes your terminal to break.

nathan-gilbert commented 3 years ago

Thanks, yep. I'll take a look at this today and let you know. Thanks for the pointers

nathan-gilbert commented 3 years ago

Here is my config.fish

# run fortune at startup
function fish_greeting
  #the original greatting...
  #set_color $fish_color_autosuggestion
  #uname -nmsr
  #uptime
  #set_color normal
  #screenfetch
  neofetch
  echo
  fortune -a
  echo
end

function on_exit --on-process %self
  set RUBY /usr/bin/ruby
  if status --is-login
    # randomly select exit message
    set exit_type (random 1 5)
    switch $exit_type
    case 1
      $RUBY $HOME/bin/seeyouspacecowboy.rb
    case 2
      fish_logo
    case 3
      $RUBY $HOME/bin/dsotm.rb
    case 4
      $RUBY $HOME/bin/dataoverload.rb
    case 5
      $RUBY $HOME/bin/space.rb
  end
  sleep 1
  end
end

set -x SSH_ENV $HOME/.ssh/environment
function start_agent
    echo "Initializing new SSH agent ..."
    ssh-agent -c | sed 's/^echo/#echo/' > $SSH_ENV
    echo "succeeded"
    chmod 600 $SSH_ENV
    source $SSH_ENV > /dev/null
    ssh-add
end

function test_identities
    ssh-add -l | grep "The agent has no identities" > /dev/null
    if [ $status -eq 0 ]
        ssh-add
        if [ $status -eq 2 ]
            start_agent
        end
    end
end

if [ -n "$SSH_AGENT_PID" ]
    ps -ef | grep $SSH_AGENT_PID | grep ssh-agent > /dev/null
    if [ $status -eq 0 ]
        test_identities
    end
else
    if [ -f $SSH_ENV ]
        . $SSH_ENV > /dev/null
    end
    ps -ef | grep $SSH_AGENT_PID | grep -v grep | grep ssh-agent > /dev/null
    if [ $status -eq 0 ]
        test_identities
    else
        start_agent
    end
end

function list_select
  read --local --array --null arr
  echo $arr[$argv]
end

function fzf_preview
    if test (file --mime config.json  | string split "=" | list_select 4) = 'binary'
        echo "$argv[1]" is a binary file;
    else
        bat --style=numbers --color=always "$argv[1]" ^ /dev/null; or cat "$argv[1]";
    end
end

# general settings
set -gx TERM xterm-256color
set -gx CLICOLOR 1
set -gx LSCOLORS GxFxCxDxBxegedabagaced
set -gx GOPATH $HOME/.go
set -gx GOBIN $HOME/.go/bin
set -gx GOROOT (go env GOROOT)
set -gx NLTK_DATA $HOME/.nltk_data
set -gx GROOVY_HOME /usr/local/opt/groovy/libexec
set -gx GRADLE_USER_HOME $HOME/.gradle
set -gx PKG_CONFIG_PATH "/usr/local/opt/curl/lib/pkgconfig"
set -gx fish_user_paths "/usr/local/opt/curl/bin" "/usr/local/opt/sqlite/bin" "$HOME/.cargo/bin" $fish_user_paths
set -gx fish_user_paths "/usr/local/opt/openjdk/bin" $fish_user_paths
set PATH $HOME/bin $PATH $GOROOT/bin

# fzf options
set -gx FZF_PREVIEW_FILE_CMD "fzf_preview"
set -gx FZF_ENABLE_OPEN_PREVIEW 1

# bobthefish theme options
set -g theme_title_display_user yes
set -g theme_title_display_process yes
set -g theme_title_display_path yes
set -g theme_title_use_abbreviated_path yes

set -g theme_display_user ssh
set -g theme_display_hostname ssh
set -g theme_display_git_master_branch yes
set -g theme_display_vagrant yes
set -g theme_display_docker_machine yes
set -g theme_display_k8s_context yes
set -g theme_display_hg yes
set -g theme_display_virtualenv yes
set -g theme_display_nix yes
set -g theme_display_ruby yes
set -g theme_display_nvm yes

set -g theme_project_dir_length 1
set -g theme_nerd_fonts yes
set -g theme_show_exit_status yes

# Disable default virtualenv prompt and use bob's mgmt
set -x VIRTUAL_ENV_DISABLE_PROMPT 1

# Solarized Dark & Green highlight man color theme
set -g man_blink -o red
set -g man_bold -o green
set -g man_standout -b black 93a1a1
set -g man_underline -u 93a1a1

# add aliases
source ~/.config/fish/aliases.fish
source ~/.iterm2_shell_integration.(basename $SHELL)
source /usr/local/share/chruby/chruby.fish
source /usr/local/share/chruby/auto.fish
nathan-gilbert commented 3 years ago

It's definitely something in my config -- commenting it all out resolves the issue

jorgebucaran commented 3 years ago

Well, for starters, only code that is meant for interactive use would be better inside an if status is-interactive.

nathan-gilbert commented 3 years ago

Which code would that be? All the set -g stuff?

I found the issue -- it's with this line source /usr/local/share/chruby/chruby.fish

I'm not really even using Ruby much any more so I'll probably remove it for now, but that is what is causing Fisher to exit after update for me.

jorgebucaran commented 3 years ago

Nope, stuff like sourcing chruby.fish, auto.fish, aliases, and iterm2_shell_integration are more like it (what's in chruby.fish by the way?).

status is-interactive || exit

source ~/.config/fish/aliases.fish
source ~/.iterm2_shell_integration.(basename $SHELL)
source /usr/local/share/chruby/chruby.fish
source /usr/local/share/chruby/auto.fish

And not really the issue here, but functions should go in your functions directory. All the SSH_ENV stuff could be in a conf.d snippet (see initialization files) if you want, defining aliases in your config.fish is also inefficient, I personally suggest creating functions to leverage Fish's function autoloading mechanism. Finally, $fish_user_paths better serves you when used interactively, as a universal variable, if you want changes to persist.

Closing since this clearly isn't a Fisher bug, but feel free to ask other questions.

nathan-gilbert commented 3 years ago

Thanks! All great suggestions, I'll look into making these changes.

This is what is in the chruby script (from an old plugin I used to use)

# The MIT License (MIT)
#
# Copyright (c) Jean Mertz <jean@mertz.fm>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

set -gx CHRUBY_FISH_VERSION '0.8.2'

#
# Execute chruby commands through bash.
#
# This method allows any command to be executed through the bash interpreter,
# allowing us to use the original chruby implementation while overlaying a thin
# wrapper on top of it to set ENV variables in the Fish shell.
#
# You can optionally set the $CHRUBY_ROOT environment variable if your
# `chruby.sh` is located in a custom path.
#
function bchruby
  set -q CHRUBY_ROOT; or set CHRUBY_ROOT /usr/local

  if test ! -f "$CHRUBY_ROOT/share/chruby/chruby.sh";
    echo "$CHRUBY_ROOT/share/chruby/chruby.sh does not exist." \
         "Set \$CHRUBY_ROOT to point to the correct path." \
         "(currently pointing to `$CHRUBY_ROOT`)"
    return 1
  end

  set bash_path (env | grep '^PATH=' | cut -c 6-)
  env - HOME="$HOME"           \
        PREFIX="$PREFIX"       \
        PATH="$bash_path"      \
        RUBY_ROOT="$RUBY_ROOT" \
        GEM_HOME="$GEM_HOME"   \
        GEM_ROOT="$GEM_ROOT"   \
        GEM_PATH="$GEM_PATH"   \
        bash -lc "source \"$CHRUBY_ROOT/share/chruby/chruby.sh\"; $argv"
end

# Define RUBIES variable with paths to installed ruby versions.
#
# Gets its list of Rubies from `bchruby`, then adds it to the local RUBIES env.
#
set -gx RUBIES (bchruby 'echo ${RUBIES[@]}' | tr ' ' '\n')
set -gx CHRUBY_VERSION (bchruby 'echo $CHRUBY_VERSION')

#
# Reset chruby-set environment variables.
#
# Calls the `chruby_reset()` method provided by chruby. Removing all custom
# environment variables, returning the ruby version to the system default.
#
function chruby_reset
  set -l IFS ";"
  bchruby 'chruby_reset; echo "$PATH;${GEM_PATH:-_}"' | \
    read -l ch_path ch_gem_path

  if test (id -u) != '0'
    set -e GEM_HOME

    if test "$ch_gem_path" = '_'
      set -e GEM_PATH
    else
      set -gx GEM_PATH "$ch_gem_path"
    end
  end

  set -gx PATH (echo $ch_path | tr : '\n')

  set -l unset_vars RUBY_ROOT RUBY_ENGINE RUBY_VERSION RUBYOPT GEM_ROOT
  for i in (seq (count $unset_vars))
    set -q $unset_vars[$i]; and set -e $unset_vars[$i]; or true
  end
end

#
# Set environment variables to point to custom Ruby install.
#
# Resets current Ruby version then runs chruby in bash, capturing it's defined
# variables and setting them in the current Fish instance.
#
function chruby_use
  set -l args '; echo "$RUBY_ROOT;${RUBYOPT:-_};${GEM_HOME:-_};${GEM_PATH:-_};${GEM_ROOT:-_};$PATH;$RUBY_ENGINE;$RUBY_VERSION;$?"'

  set -l IFS ";"
  bchruby 'chruby_use' $argv $args | read -l ch_ruby_root ch_rubyopt ch_gem_home \
                                         ch_gem_path ch_gem_root ch_path \
                                         ch_ruby_engine ch_ruby_version \
                                         ch_status

  test "$ch_status" = 0; or return 1
  test -n "$RUBY_ROOT"; and chruby_reset

  set -gx RUBY_ENGINE "$ch_ruby_engine"
  set -gx RUBY_VERSION "$ch_ruby_version"

  set -gx RUBY_ROOT $ch_ruby_root
  test "$ch_gem_root" = '_'; or set -gx GEM_ROOT "$ch_gem_root"
  test "$ch_rubyopt" = '_'; or set -gx RUBYOPT "$ch_rubyopt"

  # Fish warns the user when a path in the PATH environment variable does not
  # exist:
  #
  #   set: Warning: path component /path/to/bin may not be valid in PATH.
  #   set: No such file or directory
  #
  # Given that this happens for every Ruby install (until gems are installed in
  # these paths), we pre-create this directory, to silence Fish' warning.
  #
  for gem_path in (echo "$ch_gem_path" | tr : '\n')
    test -d "$gem_path/bin"; or mkdir -p "$gem_path/bin"
  end

  set -gx PATH (echo "$ch_path" | tr : '\n')

  if test (id -u) != '0'
    set -gx GEM_HOME "$ch_gem_home"
    set -gx GEM_PATH "$ch_gem_path"
  end
end

#
# Custom `chruby` command to be called in the Fish environment.
#
# Thin wrapper around the bash version of `chruby`, passing along arguments to
# it, and capturing the outputted environment variables to be set in Fish.
#
function chruby
  switch "$argv[1]"
    case '-h' '--help'
      bchruby "chruby $argv"
    case '-V' '--version'
      bchruby "chruby $argv"
      echo "chruby-fish: $CHRUBY_FISH_VERSION"
    case 'system'
      chruby_reset
    case '*'
      if test "$argv[1]" = ''
        bchruby "chruby $argv"
      else
        set -l dir ruby match
        for dir in $RUBIES
          set dir (echo "$dir" | sed -e 's|/$||')
          set ruby (echo "$dir" | awk -F/ '{print $NF}')

          test "$argv[1]" = "$ruby"; and set match "$dir"; and break
          echo "$ruby" | grep -q -- "$argv[1]"; and set match "$dir"
        end

        if test -z "$match"
          echo "chruby: unknown Ruby: $argv[1]" >&2
          return 1
        end

        set -e argv[1]
        chruby_use "$match" "$argv"
      end
  end
end