【发布时间】:2015-03-27 23:26:30
【问题描述】:
我正在从 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 $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 $@
在我的函数文件中。当我输入ll 时,我认为它会运行ls -lh whatever-arguments-follow。任何想法为什么在我运行ls 时会引发错误?
【问题讨论】:
-
which ls或typeset -f ls或type ls说什么? -
上面已经回答了——看起来它在某处有别名?我会四处寻找,但我不明白为什么
ls -G会破坏终端选项卡。 -
这可能是由
ls的递归(无限)定义引起的吗?如果将ls别名为/bin/ls -G会发生什么? -
我在函数文件中添加了
alias ls=/bin/ls -G,打开了一个新选项卡并尝试了它,不幸的是,它再次杀死了该选项卡。 -
尝试在子shell中输入
ls,即运行zsh,然后在zsh提示符下输入ls。如果zsh在死机时打印错误消息,那应该让您在选项卡关闭之前看到它(并带您返回父 shell)。
标签: bash shell command-line zsh fish