Sample Header Ad - 728x90

Set alias to run python venv setup based on current directory name

2 votes
2 answers
2472 views
Can't seem to figure out what the issue is. This is on a Fedora 37 with default setup (bash, gnome, etc...). What I want to achieve is to create an alias that creates a python virtual environment, where the folder name for the virtual environment is the name of the current working directory (something akin to python3 -m venv $cwd).
This is helpful especially when activating the venv (and later switching directories between project) you can easily identify which venv is enabled. But for some odd reason this is not working as I expected. To note that I don't have much experience in creating complex aliases but still. I have created the following vars in .bashrc: - export cwd="pwd | rev | cut -d '/' -f1 | rev" - If I run this in termnial it displays the directory name test as I need it, but when running $cwd in the terminal I get home//Projects/VueJS/test - export cwd2="${PWD##*/}" - This one just displays my username for some reason. I've searched here on stackoverflow and this was one of the suggested methods to get the current directory name Some indication on how to get started or where to look for info are appreciated. I've tried to search on multiple sources but I can't seem to figure it. I read somewhere that double and single quotes make a difference, but I couldn't understand why and if it would affect this behaviour. EDIT: To clarify, what I want my alias to run is i.e: - python3 -m venv && source /bin/activate && [ ! -f ./requirements.txt ] || pip install -r requirements.txt - This creates a virtual for python projects - python3 -m venv && source /bin/activate && pip install nodeenv && nodeenv -p - This creates virtual environments for projects that depend on nodejs, which in itself depend on python venv
Asked by calexandru (210 rep)
Feb 8, 2023, 11:09 PM
Last activity: Feb 11, 2023, 12:29 AM