-1

I'm trying to create an alias to activate any given Venv by typing activate [name of Venv].

What I've done:

activate (){
    directory = "~/Programming/path-to-venvs/$1"
    cd $directory
    source "bin/activate"
}

When I try to run it, if I do:

activate Test

I get this error:

activate:cd:3: no such file or directory: ~/Programming/path-to-venvs/Test
activate:source:4: no such file or directory: bin/activate

Any ideas?

oguz ismail
  • 1
  • 16
  • 47
  • 69
451
  • 1
  • 3
  • Use absolute paths instead of relative paths in your function. – mtnezm Jun 10 '20 at 18:27
  • 1
    You can't put spaces around the `=` in an assignment, and `~` doesn't expand when it's in quotes. [shellcheck.net](https://www.shellcheck.net) is good at pointing out problems like this. – Gordon Davisson Jun 10 '20 at 19:03
  • 1
    Check out dynamic named directories in `man zshexpn` to see how to configure the shell to let you define `activate () { cd ~[venv:$1] && source bin/activcate; }`. – chepner Jun 10 '20 at 19:32
  • @451 : I don't see any _alias_ definition in your code. – user1934428 Jun 11 '20 at 07:27

1 Answers1

0

Just to close this question properly:

Use absolute paths instead of relative paths in your function.

Also you may be interested in reading this answer.

mtnezm
  • 1,009
  • 1
  • 7
  • 19