切换到 zsh shell -- `ls` 结束终端选项卡

Switching to zsh shell -- `ls` ends terminal tab

我正在从 Fish Shell 切换到 Zsh。

我刚刚经历了一个漫长的过程,将我的一堆 Fish 函数转换成 Zsh,大多数东西都在工作,但我只是注意到当我输入 ls 时,它不仅不起作用,但实际上结束了终端选项卡会话:

➜  ~  cd code
➜  code  ls

[Process completed]

超级令人费解,因为我没有(我不认为)做任何事情来扰乱该命令。大多数其他基本命令似乎都可以正常工作。有什么想法可能导致这种混乱吗?我把我的新 Zsh 函数和我的 .zshrc 文件放在下面。

函数,主要是一堆Git/Zeus(一个Rails工具)函数,让我的生活更轻松:

~/.oh-my-zsh/custom/plugins/functions/functions.plugin.zsh

##############################
######### ZEUS BASED #########
##############################

z () zeus start

rmz () rm .zeus.sock

rr () {
  if [ "$#" -gt 0 ]; then
    r routes | grep "$@" 
  else
    r routes
  fi
}

zeus_on () {
  if ps aux | grep -v grep | grep 'zeus slave: development_environment'; then
    true
  else
    false
  fi
}

mg () r db:migrate "$@"

tprep () {
  if zeus_on; then
    zeus rake db:test:prepare "$@"
  else
    echo "Zeus is not running"
    rake db:test:prepare "$@"
  fi
}

s () { 
  if zeus_on; then
    zeus s
  else
    echo "Zeus is not running"
    rails s
  fi
}

t () {
  if zeus_on; then
    if [ '$#' -gt 0 ]; then
      zeus test "$@"
    else
      zeus test spec
    fi
  else
    echo "Zeus is not running"
    if [ "$#" -gt 0 ]; then
      rspec "$@"
    else
      rspec spec
    fi
  fi
}

tt () zeus rspec --tag  spec

r () {
  if zeus_on; then
    zeus rake "$@"
  else
    echo "Zeus is not running"
    rake "$@"
  fi
}

c () {
  if zeus_on; then
    zeus c "$@"
  else
    echo "Zeus is not running"
    rails c "$@"
  fi
}

jt () {
  if zeus_on; then
    if [ "$#" -gt 0 ]; then
      zeus tr spec:javascript SPEC="$@"
    else
      zeus tr spec:javascript
    fi
  else
    echo "Zeus is not running"
    if [ "$#" -gt 0 ]; then
      rake spec:javascript RAILS_ENV=test SPEC="$@"
    else
      rake spec:javascript RAILS_ENV=test
    fi
  fi
}

# ##############################
# ############ GIT #############
# ##############################

gcurrent () git rev-parse --abbrev-ref HEAD

gclean! () git clean -f -d

gd () git diff "$@"

gds () git diff --staged "$@"

gdh () git diff HEAD^

gr () git rebase "$@"

gri () gr -i "$@"

grc () gr --continue

gback () git reset HEAD^

gh () hub browse

gac () {
  ga
  gc "$@"
}

gacm () gac -m "$@"

ga () {
  if [ "$#" -gt 0 ]; then
    git add "$@"
  else
    git add .
  fi
}

gp () git pull "$@"

gs () git status "$@"

gsp () git stash pop

gss () git stash save

gl () git log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit "$@"

gco () git checkout "$@"

gcom () git checkout master

gpush () git push "$@"

gb () git branch "$@"

gbd () git branch -d "$@"

gc () git commit "$@"

gca () gc --amend

grb () git rebase "$@"

g () git "$@"

gcpick () git cherry-pick "$@"

grh () git reset --hard "$@"

gbdelete () git push origin --delete "$@"


# ###############################
# ######## CD SHORTCUTS #########
# ###############################

fish_dir () cd ~/.config/fish/

# Define code_directory in .zshrc
code () cd /$code_directory/"$@"

f () code "$@"

# ##############################
# ########### OTHER ############
# ##############################


tasks () ps aux | grep $@

b () bundle $@

ll () ls -lh $@

fs () foreman start $@

hcon () heroku run rails console

dtest () tail -f diagnostic.txt

sb () {
  if [ "$#" -gt 0 ]; then
    sublime "$@"
  else
    sublime .
  fi
}

fish_edit () {
  sb ~/.config/fish/config.fish
}

Probably unrelated, but also confusing to me. I get this warning when I open a new shell tab in relation to the uses of grep in that file. This didn't happen before with Fish:

usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
  [-e pattern] [-f file] [--binary-files=value] [--color=when]
  [--context[=num]] [--directories=action] [--label] [--line-buffered]
  [--null] [pattern] [file ...]

最后是导入这些插件的.zshrc文件。 This answer(尽管行为不同)表明它可能是 PATH 定义问题,但我认为我在我的 PATH:

中包含了所有必要的路径
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh

export code_directory=$HOME/code/

ZSH_THEME="robbyrussell"

plugins=(functions github)

# User configuration

export PATH="/Users/sasha/.rvm/gems/ruby-2.2.0/bin:/Users/sasha/.rvm/gems/ruby-2.2.0@global/bin:/Users/sasha/.rvm/rubies/ruby-2.2.0/bin:/Users/sasha/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin"
# export MANPATH="/usr/local/man:$MANPATH"

source $ZSH/oh-my-zsh.sh

回答以下问题:

➜  .oh-my-zsh git:(master) ✗ which ls
ls: aliased to ls -G
➜  .oh-my-zsh git:(master) ✗ typeset -f ls
ls () {
    ls -G -lh $@
}
➜  .oh-my-zsh git:(master) ✗ type ls
ls is an alias for ls -G

更新

我已经弄清楚 是什么 导致了它,但不知道 为什么 。就是这一行:

ll () ls -lh $@

在我的函数文件中。当我输入 ll 时,我认为会 运行 ls -lh whatever-arguments-follow。任何想法为什么当我 运行 ls?

时会引发错误

好的,所以 ls 既是别名又是函数。那是行不通的,因为它们会递归。在我的终端上,当我 运行

时,ls 是一个别名和一个函数
ls

它想了两秒钟,然后我得到了

ls:1: maximum nested function level reached

使用函数或别名,但不能同时使用。

Edit 哦,看起来可以,但问题是 ls 函数是递归的。应该是

ls () {
    command ls -G -lh $@
}

command 内置确保您执行实际命令,既不是别名也不是函数。