terminalvirtualenvzsh

I wrote deactivate() instead of deactivate at the terminal prompt. How do I get back?


I wanted to deactivate virtual environment by command deactivate but accidentally wrote deactivate(). It then opened console with

function>

I typed some symbols and now, when I call command deactivate it tries to execute those symbols as command and obviously give error that there is no such command. I tried to type deactivate inside of it, but it didn't work.

How can I revert deactivate to its original behavior?


Solution

  • When you wrote deactivate() you told the shell you are starting to define a function with this name. It's waiting for you to complete this, and will return to normal once you finish what you started.

    You don't want to redefine deactivate, so probably break out of this with a simple ctrl-C.

    If you already managed to redefine deactivate, there is no straightforward way to return it to its earlier definition, but don't worry; it won't stick, so just start a new shell (maybe exit the current shell, or leave it open if you still have unfinished business there).

    This assumes you are using a Bourne-compatible shell like Zsh or Bash. They both happen to behave the same with regard to ctrl-C in this scenario.

    When you activate a virtual environment, you basically change some settings in the currently running shell instance. All of those things are ephemeral and will go away once the shell exits.

    Similarly, functions you define are local to the currently running shell instance, and won't carry over; to make a function permanent you have to put its definition in one of your shell's startup files.