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

时间:2015-01-28 21:33:27

标签: bash shell command-line zsh fish

我从Fish Shell转到Zsh。

我刚刚经历了将一堆Fish函数转换为Zsh的漫长过程,大多数事情都有效,但我注意到当我输入ls时,它不仅没有工作,但实际上结束了终端标签会话:

➜  ~  cd code
➜  code  ls

[Process completed]

超级困惑,因为我没有(我不这么认为)做任何事情来搞乱这个命令。大多数其他基本命令似乎工作正常。什么可能导致这个混乱的想法?我已将新的Zsh功能和我的.zshrc文件放在下面。

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

〜/·OH-MY-zsh的/定制/插件/功能/ 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 $1 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
}
  

可能不相关,但也让我感到困惑。当我打开与该文件中grep的使用相关的新shell选项卡时,我收到此警告。这与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 $@

在我的函数文件中。我想当我输入ls -lh whatever-arguments-follow时会运行ll。当我跑ls时,有什么想法可能会引起错误?

1 个答案:

答案 0 :(得分:3)

好的,所以ls既是别名又是函数。这不会起作用,因为他们会逃避。在我的终端上,当我运行

时,ls是别名和功能
ls

它认为两秒钟,然后我得到了

ls:1: maximum nested function level reached

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

编辑哦,看起来可行,但问题是ls函数是递归的。它应该读

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

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