Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I was trying new dev environments including zsh and oh-my-zsh. Now that I have installed oh-my-zsh, it starts by default on my terminals (iTerm2 and terminal) always start with zsh and with the settings on from oh-my-zsh. I was wondering if it was possible to "disable" or stop using zsh and its setup with oh-my-zsh without having to uninstall oh-my-zsh? It would also be nice to know how to turn them back on too.

Currently, my terminals goes into zsh automatically (I think) and use the oh-my-zsh automatically. I want to have more control over that and me able to control both, when the zsh is being used and when the oh-my-zsh features are being used.

One thing I am also interested on knowing is, how do the terminal applications know which shell to start running on start up. That would be nice to be able to control too!

If you explain as much as you can of the "why" of every command you give me, that would useful! :)


I am on OS X. Not sure if that matters, but I tend to like answers more that are more applicable to more general Unix environments rather to my own.

share|improve this question
    
you want to stop using zsh? or oh-my-zsh? which? –  strugee Jun 15 at 3:12
    
either and both. i.e. I want to be able to control both, when I am using zsh and oh-my-zsh –  Charlie Parker Jun 15 at 3:21
add comment

3 Answers 3

The wording of your question is ambiguous, so I can't tell if you mean you want to stop using zsh or you want to stop using oh-my-zsh. I will cover both.

Disabling zsh

Simply run chsh and select whatever shell you were using before. If you don't know what shell you were using before, it is almost certainly bash. This command changes the "login shell" that is associated with your user. Essentially, it changes your default shell.

You will need to open a new terminal window for changes to take effect. If this does not work, you will need to log out and log back in again to reinitialize your environment.

Disabling only oh-my-zsh

  1. Check if ~/.zshrc.pre-oh-my-zsh exists. It probably does. (This file will have been created when the oh-my-zsh installation script moved your previous .zshrc out of the way. .zshrc is a startup file of zsh, similar to .bashrc for bash.)
  2. If it does, do mv ~/.zshrc ~/.zshrc.oh-my-zsh. This will put the oh-my-zsh-created .zshrc out of the way, so we can restore the original, by doing mv ~/.zshrc.pre-oh-my-zsh ~/.zshrc.
  3. If it does not exist, open ~/.zshrc in a text editor. Find the line that says source $ZSH/.oh-my-zsh and either comment it out or remove it. This will disable the initialization of oh-my-zsh.

You will need to restart your shell for changes to take effect.

share|improve this answer
    
I apologize about my wording. I believe I clarified it. Is it clear now? Thanks btw. –  Charlie Parker Jun 15 at 3:29
    
@CharlieParker yeah, I was being lazy. I'll expand the answer, maybe explain a bit of the "why". –  strugee Jun 15 at 3:31
    
@CharlieParker in case you didn't notice, I updated this answer. let me know if anything can be improved. –  strugee Jun 16 at 0:03
add comment

ZSH Config Switching

If you want to test different zsh configuration frameworks (oh-my-zsh, zprezto, etc) and switch between them, your best bet is using symbolic links for ~/.zsh, ~/.zshrc, ~/.zlogin, ~/.zlogout, ~/.zprofile, and ~/.zshenv. You may want to create a shell scripts for each framework to create those symlinks for faster switching.

Put your framework configurations in their own folders. For each framework.

  • Install the framework in its own folder if possible, otherwise
  • If the framework forces installation to ~/.zsh, then
    • Protect the current ~/.zsh first. Either
      • remove the ~/.zsh symlink; rm ~/.zsh, or
      • move the ~/.zsh folder; mv ~/.zsh ~/.zsh.backup
    • Run the framework installer.
    • Move the framework folder to its own directory. e.g. mv ~/.zsh ~/.oh-my-zsh.
  • Repeat for each framework.

Once done, create a shell script for each framework to create the necessary symlinks. Here's an example for zprezto, since I already use it.

$ mkdir ~/bin
$ cat <<EOF > ~/bin/use-zprezto
#!/bin/bash
SYMLINKS=".zsh .zshrc .zshlogin .zshlogout .zshprofile .zpreztorc .zshenv .zshrc"
CONFIG_HOME="$HOME/.zprezto"

# check for unexpected error conditions
for sym in $SYMLINKS; do
   # report an error and quit if $sym exists and is not a symlink
   [[ -e "$HOME/$sym" -a ! -h "$HOME/$sym" ]] && { echo "error:  '$HOME/$sym' is not a symlink!"; return 1; }
done

# now create the symlinks now that nothing should go wrong
for sym in $SYMLINKS; do
   # remove old symlink if it exists
   [[ -h "$HOME/$sym" ]] && rm -f "$HOME/$sym"
   # create new symlink
   ln -s "$CONFIG_HOME/$sym" "$HOME/$sym"
done

# uncomment next line to start a new zsh shell.  CAUTION: each call is a zsh shell inside a zsh shell.  Too many calls will put you in limbo :D
#/usr/bin/env zsh
EOF

$ chmod 700 ~/bin/use-zprezto

This script is fairly simple and relies on the fact that all my symlinks are organized with the same pattern. You can copy&paste the remove and create lines after the loop for symlinks you have that don't follow the pattern.

Once done, use ~/bin/use-zprezto--or ~/bin/use-whatever--to switch between zsh frameworks.

Note that changes only take effect in new zsh shells, not existing shells.

Shell Switching

It's a bit dangerous, but if you're so inclined, you can use a symlink for your shell command and set the symlink as your default shell. You can then follow the use-* script method above to change your default shell.

As an example with zsh...

$ mkdir ~/bin
$ cat <<EOF > ~/bin/use-zsh
#!/bin/bash
# check for valid shell symlink
if [[ ! -h "$HOME/.shell" ]]; then
  echo "error: $HOME/.shell is not a symlink!"
  return 1
fi

# remove existing shell symlink if it exists
[[ -h "$HOME/.shell" ]] && rm -f "$HOME/.shell"

# create new shell symlink, but warn user if this fails!
if ! ln -s /usr/bin/zsh "$HOME/.shell"; then
  echo "ERROR: failed to create $HOME/.shell symlink.  Manually create the symlink or future logins will fail!."
  return 2
fi
EOF

$ chmod 700 ~/bin/use-zsh

The reason this is dangerous is that you cannot login under a user if the shell stored in /etc/passwd is not a valid program. So you can lock yourself out of your account if you're not careful; i.e. your ~/.shell symlink is broke or doesn't point to an interactive program. You're welcome to try this with a user account, but this is NOT RECOMMENDED for your root account.

If you still want to continue, then

$ ~/bin/use-zsh         # ensures ~/.shell exists for chsh
$ echo "$HOME/.shell | sudo tee -a /etc/shells    # add symlink to system's list of valid shells
$ chsh -s ~/.shell      # changes default shell in /etc/passwd for $USER
share|improve this answer
add comment

You can tell zsh to load its per-user configuration files from a different directory by setting the environment variable ZDOTDIR before starting zsh.

If you want to start zsh without loading your configuration files, set ZDOTDIR to a non-existent directory. If you want to skip system configuration files (apart from /etc/zshenv), you can run zsh -f. If you want to skip system configuration files but run the per-user files, run zsh -d.

For example, if you want to test-drive oh-my-zsh without making it the default, don't put the .zshrc from oh-my-zsh in your home directory. Instead, put it somewhere else, eg. in ~/.oh-my-zsh, and then run ZDOTDIR=~/.oh-my-zsh zsh when you want to use oh-my-zsh.


Terminal applications run the shell indicated by the SHELL environment variable. If this variable is unset, they run the login shell indicated in the user database (/etc/passwd). You can request a different application when you start a terminal emulator, e.g. xterm -e fish.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.