nvbn / thefuck

Magnificent app which corrects your previous console command.
MIT License
84.95k stars 3.43k forks source link

Causes shell crash on first loads #1265

Open bduff9 opened 2 years ago

bduff9 commented 2 years ago

The output of thefuck --version (something like The Fuck 3.1 using Python 3.5.0 and Bash 4.4.12(1)-release):

❯ thefuck --version
The Fuck 3.32 using Python 3.10.1 and ZSH 5.8

Your system (Debian 7, ArchLinux, Windows, etc.):

macOS Monterey 12.1

How to reproduce the bug:

Open a new terminal session

The output of The Fuck with THEFUCK_DEBUG=true exported (typically execute export THEFUCK_DEBUG=true in your shell before The Fuck):

❯ thefuck
usage: thefuck [-v] [-a [ALIAS]] [-l SHELL_LOGGER] [--enable-experimental-instant-mode] [-h] [-y | -r] [-d] [command ...]

If the bug only appears with a specific application, the output of that application and its version:

This only appears the first time I open a new tab in iTerm. With iTerm set to auto close tabs when the session ends, it opens, and then automatically closes after a couple of seconds. I can open a new tab again and then it is fine. However, if I open another tab, it fails again in the same way. When I turn off auto close, I get this output that is crashing my shell the first time each tab is opened:

Last login: Thu Jan 13 12:57:40 on ttys010
Traceback (most recent call last):
  File "/usr/local/bin/thefuck", line 13, in <module>
    sys.exit(main())
  File "/usr/local/Cellar/thefuck/3.32/libexec/lib/python3.10/site-packages/thefuck/entrypoints/main.py", line 38, in main
    shell_logger(known_args.shell_logger)
  File "/usr/local/Cellar/thefuck/3.32/libexec/lib/python3.10/site-packages/thefuck/entrypoints/shell_logger.py", line 77, in shell_logger
    return_code = _spawn(os.environ['SHELL'], partial(_read, buffer))
  File "/usr/local/Cellar/thefuck/3.32/libexec/lib/python3.10/site-packages/thefuck/entrypoints/shell_logger.py", line 51, in _spawn
    _set_pty_size(master_fd)
  File "/usr/local/Cellar/thefuck/3.32/libexec/lib/python3.10/site-packages/thefuck/entrypoints/shell_logger.py", line 29, in _set_pty_size
    fcntl.ioctl(pty.STDOUT_FILENO, termios.TIOCGWINSZ, buf, True)
OSError: [Errno 25] Inappropriate ioctl for device

Anything else you think is relevant:

I see that this sounds similar to #1112, however, the errors are different as this seems to be a Python error, not a permission denied error on /proc. I can open a new tab twice for now as a workaround but would like to know how the first time a tab is opened this fails and then works (working meaning the shell, plus thefuck command itself which seems to work fine once the shell is successfully opened). Happy to provide whatever info or logging is needed to resolve this issue. Thanks!

scorphus commented 2 years ago

Could you please share your ~/.zshrc file with sensitive information filtered out?

bduff9 commented 2 years ago
# Measure startup and disable instant prompt
# ZSHRC_CONFIG_DIAG=1

export DOTFILES="$HOME/.dotfiles"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_CACHE_HOME="$HOME/.cache"
# Where I keep my projects
export PROJECTS="$HOME/projects/"

if [ "$(uname -s)" = "Darwin" ]
then
  export ZSHRC_CONFIG_USER='MAC'
fi

if [[ $ZSHRC_CONFIG_DIAG -eq 1 ]]
then
    zmodload zsh/zprof
    alias diag=zprof

  # No instant prompt with gsh, as gsh is expected to print before first prompt.
elif [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
  # Initialization code that may require console input (password prompts, [y/n]
  # confirmations, etc.) must go above this block; everything else may go below.
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# Dropbox location
export DROPBOX=~/Dropbox

# Check if a command exists
function can_haz() {
  which "$@" > /dev/null 2>&1
}

# Correct spelling for commands
setopt correct

# turn off the infernal correctall for filenames
unsetopt correctall

# Alias-tips options
export ZSH_PLUGINS_ALIAS_TIPS_TEXT="Alias tip: "
export ZSH_PLUGINS_ALIAS_TIPS_EXCLUDES="ls"
export ZSH_PLUGINS_ALIAS_TIPS_EXPAND=1
export ZSH_PLUGINS_ALIAS_TIPS_FORCE=0
export ZSH_PLUGINS_ALIAS_TIPS_REVEAL=0
export ZSH_PLUGINS_ALIAS_TIPS_REVEAL_TEXT="Alias was: "
export ZSH_PLUGINS_ALIAS_TIPS_REVEAL_EXCLUDES=(ls)

# Base PATH
PATH="$PATH:$HOME/bin:/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin"

# Conditional PATH additions
for path_candidate in /Applications/Xcode.app/Contents/Developer/usr/bin \
  /opt/homebrew/bin \
  /opt/homebrew/sbin \
  /opt/local/bin \
  /opt/local/sbin \
  /usr/local/bin \
  /usr/local/sbin \
  ~/.cabal/bin \
  ~/.cargo/bin \
  ~/.rbenv/bin \
  ~/bin \
  ~/src/gocode/bin \
  ~/gocode \
  /usr/local/opt/python/libexec/bin
do
  if [[ -d "${path_candidate}" ]]; then
    export PATH="${PATH}:${path_candidate}"
  fi
done

fpath=(
    "$XDG_DATA_HOME/zsh/generated/functions"
    $fpath
)

# Node development
eval "$(fnm env)"

# Java dev
export JAVA_HOME_8=$(/usr/libexec/java_home -v1.8)
export JAVA_HOME_11=$(/usr/libexec/java_home -v11)
export JAVA_HOME=$JAVA_HOME_8
# export JAVA_HOME=$JAVA_HOME_11

# Go development
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec

# Load any custom zsh files before plugins
setopt nullglob
for file in $DROPBOX/ohmyzsh/before/*.zsh
do
    source "$file"
done
unsetopt nullglob

# zgenom
ZGEN_RESET_ON_CHANGE=(${DROPBOX}/ohmyzsh/zshrc ${DROPBOX}/ohmyzsh/p10k.zsh)
ZGEN_CUSTOM_COMPDUMP="${ZDOTDIR:-$HOME}/.zcompdump_$ZSH_VERSION"*
if [[ ! -f "${HOME}/.zgenom/zgenom.zsh" ]]; then
  git clone https://github.com/jandamm/zgenom.git "${HOME}/.zgenom"
fi
source "${HOME}/.zgenom/zgenom.zsh"

# Check for updates every 7 days
zgenom autoupdate --background

# Only runs when .zgenom/sources/init.zsh doesn't exist.  Use zgenom reset to delete init.zsh
if ! zgenom saved; then
  echo "Creating a zgenom save"
  ZGEN_LOADED=()
  ZGEN_COMPLETIONS=()

  # Ohmyzsh base library
  zgenom ohmyzsh

  # If zsh-syntax-highlighting is bundled after zsh-history-substring-search, they break, so get the order right.
  zgenom load zsh-users/zsh-syntax-highlighting
  zgenom load zsh-users/zsh-history-substring-search

  # Set keystrokes for substring searching
  zmodload zsh/terminfo
  bindkey "$terminfo[kcuu1]" history-substring-search-up
  bindkey "$terminfo[kcud1]" history-substring-search-down

  # Automatically run zgenom update and zgenom selfupdate every 7 days.
  zgenom load unixorn/autoupdate-zgenom

  # Add my collection of miscellaneous utility functions.
  zgenom load unixorn/jpb.zshplugin

  # Colorize the things if you have grc installed. Well, some of the things, anyway.
  zgenom load unixorn/warhol.plugin.zsh

  # macOS helpers. This plugin is smart enough to detect when it isn't running on macOS and not load itself, so you can safely share the same plugin list across macOS and Linux/BSD.
  zgenom load unixorn/tumult.plugin.zsh

  # Warn you when you run a command that you've set an alias for without using the alias.
  zgenom load djui/alias-tips

  # Add my collection of git helper scripts.
  zgenom load unixorn/git-extra-commands

  # Supercharge your history search with fzf
  zgenom load unixorn/fzf-zsh-plugin

  # Much faster cd using frecency
  zgenom load skywind3000/z.lua

  # OMZ plugins
  zgenom ohmyzsh plugins/aws
  zgenom ohmyzsh plugins/brew
  zgenom ohmyzsh plugins/colored-man-pages
  zgenom ohmyzsh plugins/copydir
  zgenom ohmyzsh plugins/copyfile
  zgenom ohmyzsh plugins/docker
  zgenom ohmyzsh plugins/git
  zgenom ohmyzsh plugins/gitfast
  zgenom ohmyzsh plugins/github
  zgenom ohmyzsh plugins/gitignore
  zgenom ohmyzsh plugins/macos
  zgenom ohmyzsh plugins/npm
  zgenom ohmyzsh plugins/per-directory-history
  zgenom ohmyzsh plugins/python
  zgenom ohmyzsh plugins/sudo
  zgenom ohmyzsh plugins/zsh-interactive-cd

  zgenom load chrissicool/zsh-256color

  # Load more completion files for zsh from the zsh-lovers github repo.
  zgenom load zsh-users/zsh-completions

  zgenom load junegunn/fzf shell/completion.zsh # **TAB to completion options in fzf
    zgenom load junegunn/fzf shell/key-bindings.zsh # ^t to list all files from ./ in fzf

  # History search with syntax highlighting
    zgenom load zdharma-continuum/history-search-multi-word
  zgenom load zdharma-continuum/fast-syntax-highlighting

  # Docker completion
  zgenom load srijanshetty/docker-zsh

  # Load me last
  GENCOMPL_FPATH=$HOME/.zsh/complete

  # Very cool plugin that generates zsh completion functions for commands if they have getopt-style help text. It doesn't generate them on the fly, you'll have to explicitly generate a completion, but it's still quite cool.
  zgenom load RobSis/zsh-completion-generator

  # Add Fish-like autosuggestions to your ZSH.
  zgenom load zsh-users/zsh-autosuggestions

  # k is a zsh script / plugin to make directory listings more readable, adding a bit of color and some git status information on files and directories.
  zgenom load supercrabtree/k

  # p10k is faster and what I'm using now, so it is the new default
  zgenom load romkatv/powerlevel10k powerlevel10k

  # Save it all to init script.
  zgenom save
    zgenom compile "$HOME/.zshenv"
    zgenom compile "$XDG_CONFIG_HOME/zsh"
    zgenom compile "$XDG_DATA_HOME/zsh/generated"
fi

# Load generated plugins
setopt nullglob
for file in $XDG_DATA_HOME/zsh/generated/*.zsh
do
    source "$file"
done

bindkey "^[[H" beginning-of-line
bindkey "^[[F" end-of-line

# Docker config to allow option stacking
zstyle ':completion:*:*:docker:*' option-stacking yes
zstyle ':completion:*:*:docker-*:*' option-stacking yes

eval "$(direnv hook zsh)"
eval $(thefuck --alias --enable-experimental-instant-mode)

# Set some history options
#
# You can customize these by putting a file in ~/.zshrc.d with
# different settings - those files are loaded later specifically to
# make overriding these (and things set by plugins) easy without having
# to maintain a fork.
setopt append_history
setopt extended_history
setopt hist_expire_dups_first
setopt hist_ignore_all_dups
setopt hist_ignore_dups
setopt hist_ignore_space
setopt hist_reduce_blanks
setopt hist_save_no_dups
setopt hist_verify
setopt INC_APPEND_HISTORY
unsetopt HIST_BEEP

# Share your history across all your terminal windows
setopt share_history

# Keep a ton of history. You can override these without editing .zshrc by adding a file to ~/.zshrc.d that changes these variables.
HISTSIZE=100000
SAVEHIST=100000
HISTFILE=~/.zsh_history
export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help"

fpath=("$ZDOTDIR/functions" $fpath)

# adds @(|) *(|) ?(|) +(|) which translate to regex: (|) (|)* (|)? (|)+
setopt extendedglob

# Set some options about directories
setopt pushd_ignore_dups
setopt AUTO_CD  # If a command is issued that can’t be executed as a normal command, and the command is the name of a directory, perform the cd command to that directory.

# Add some completions settings
setopt ALWAYS_TO_END     # Move cursor to the end of a completed word.
setopt AUTO_LIST         # Automatically list choices on ambiguous completion.
setopt AUTO_MENU         # Show completion menu on a successive tab press.
setopt AUTO_PARAM_SLASH  # If completed parameter is a directory, add a trailing slash.
setopt COMPLETE_IN_WORD  # Complete from both ends of a word.
unsetopt MENU_COMPLETE   # Do not autoselect the first completion entry.

# Miscellaneous settings
setopt INTERACTIVE_COMMENTS # Enable comments in interactive shell.

setopt extended_glob # Enable more powerful glob features

# This is required by some tools like fastlane.
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

# Disable Oh-My-ZSH's internal updating. Let it get updated when user does a zgen update. Closes #62.
DISABLE_AUTO_UPDATE=true

# Expand aliases inline - see http://blog.patshead.com/2012/11/automatically-expaning-zsh-global-aliases---simplified.html
globalias() {
   if [[ $LBUFFER =~ ' [A-Z0-9]+$' ]]; then
     zle _expand_alias
     zle expand-word
   fi
   zle self-insert
}

zle -N globalias

bindkey " " globalias
bindkey "^ " magic-space           # control-space to bypass completion
bindkey -M isearch " " magic-space # normal space during searches

# Set personal aliases, overriding those provided by oh-my-zsh libs, plugins, and themes. Aliases can be placed here, though oh-my-zsh users are encouraged to define aliases within the ZSH_CUSTOM folder. For a full list of active aliases, run `alias`.
alias nano="/usr/local/bin/nano"
alias zshconfig="nano ~/.zshrc"
alias reloadzsh="exec zsh"
fixmous() {
  rm ~/Library/Preferences/com.apple.driver.AppleBluetoothMultitouch.mouse.plist
  rm ~/Library/Preferences/com.apple.driver.AppleHIDMouse.plist
}
fixnodegyp() {
  sudo touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
  softwareupdate -i -r
  read -s -k '?Press any key once CLTools have been reinstalled.\n'
  sudo rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
}
timezsh() {
  shell=${1-$SHELL}
  for i in $(seq 1 10); do /usr/bin/time $shell -i -c exit; done
}
connectSSH() {
  password=$1
  server=$2
  echo $password | pbcopy
  sshpass -p $password ssh ${server}
}

# Load any custom zsh files after plugins
setopt nullglob
for file in $DROPBOX/ohmyzsh/after/*.zsh
do
    source "$file"
done
unsetopt nullglob

# These need to be done after $PATH is set up so we can find grc and exa

# grc colorizes the output of a lot of commands. If the user installed it, use it.
# Try and find the grc setup file
if (( $+commands[grc] )); then
  GRC_SETUP='/usr/local/etc/grc.bashrc'
fi
if (( $+commands[grc] )) && (( $+commands[brew] ))
then
  GRC_SETUP="$(brew --prefix)/etc/grc.bashrc"
fi
if [[ -r "$GRC_SETUP" ]]; then
  source "$GRC_SETUP"
fi
unset GRC_SETUP

if (( $+commands[grc] ))
then
  function ping5(){
    grc --color=auto ping -c 5 "$@"
  }
else
  alias ping5='ping -c 5'
fi

# Set up colorized ls when gls is present - it's installed by grc
if (( $+commands[gls] )); then
  alias ls="gls -F --color"
  alias l="gls -lAh --color"
  alias ll="gls -l --color"
  alias la='gls -A --color'
fi

# When present, use exa instead of ls
if can_haz exa; then
  if [[ -z "$EXA_TREE_IGNORE" ]]; then
    EXA_TREE_IGNORE=".cache|cache|node_modules|vendor|.git"
  fi

  alias l='exa -al --icons --git --time-style=long-iso --group-directories-first --color-scale'
  alias ls='exa --group-directories-first'

  # Don't step on system-installed tree command
  if ! can_haz tree; then
    alias tree='exa --tree'
  fi
fi

# Speed up autocomplete, force prefix mapping
zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache
zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)*==34=34}:${(s.:.)LS_COLORS}")';

# Load any custom zsh completions we've installed
if [[ -d ~/.zsh-completions ]]; then
  for completion in ~/.zsh-completions/*
  do
    if [[ -r "$completion" ]]; then
      source "$completion"
    else
      echo "Can't read $completion"
    fi
  done
fi

# Define completions for command options
# Commands with gnu style '--help' can be added here.
compdef _gnu_generic \
    ack aria2c \
    bat \
    fd fzf \
    ksdiff \
    pod \
    swiftformat \
    xcpretty xed

compdef g=git
compdef v=_zlua

# Change style of global aliases
FAST_HIGHLIGHT_STYLES[global-alias]=fg=green,bold,underline

# If GOPATH is defined, add it to $PATH
if [[ -n "$GOPATH" ]]; then
  if [[ -d "$GOPATH" ]]; then
    export PATH="$PATH:$GOPATH"
  fi
fi

# Now that .zshrc.d has been processed, we dedupe $PATH using a ZSH builtin
# https://til.hashrocket.com/posts/7evpdebn7g-remove-duplicates-in-zsh-path
typeset -aU path;

# Fix bracketed paste issue
# Closes #73
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste)

# Load iTerm shell integrations if found.
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"

if ! can_haz fzf; then
  echo "$?"
  echo "You'll need to install fzf or your history search will be broken."
  echo
  echo
  echo "Install instructions can be found at https://github.com/junegunn/fzf/"
fi
scorphus commented 2 years ago

Instant mode is an experimental feature, I recommend disabling it. So, please change from

eval $(thefuck --alias --enable-experimental-instant-mode)

to

eval $(thefuck --alias)

Sorry for any inconvenience.

Trongha commented 10 months ago

Instant mode is an experimental feature, I recommend disabling it. So, please change from

eval $(thefuck --alias --enable-experimental-instant-mode)

to

eval $(thefuck --alias)

Sorry for any inconvenience.

Many Thanks ^^