I'm switching from Fish Shell to Zsh.
I just went through a long process of converting a bunch of my Fish functions into Zsh, and most things are working, but I just noticed that when I type ls
, it not only doesn't work, but actually ends the terminal tab session:
➜ ~ cd code
➜ code ls
[Process completed]
Super perplexing, as I didn't (I don't think) do anything to mess with that command. Most other basic commands seem to work fine. Any ideas what might be causing this mess? I've put my new Zsh functions and my .zshrc
file below.
The functions, which are mostly a bunch of Git/Zeus (a Rails tool) functions to make my life easier:
~/.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
}
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 ...]
Finally, the .zshrc
file that imports these plugins. This answer (despite the different behavior) suggests that it might be a PATH
definition issue, but I think I'm including all necessary paths in my 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
In response to the below question:
➜ .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
UPDATE
I've figured out what is causing it, but not why. It's this line:
ll () ls -lh $@
in my functions file. I figured that would run ls -lh whatever-arguments-follow
when I typed ll
. Any ideas why that woul raise an error when I ran ls
?
Okay, so ls
is both an alias and a function. That's not gonna work because they'll recurse. On my terminal, with ls being an alias and a function, when I run
ls
it thinks for two seconds, then I get
ls:1: maximum nested function level reached
Use either a function, or an alias, but not both.
Edit Oh, it looks like that could work, but the problem is that the ls
function is recursive. It should read
ls () {
command ls -G -lh $@
}
The command
builtin makes sure you execute the actual command, neither an alias nor a function.