106 lines
11 KiB
Plaintext
106 lines
11 KiB
Plaintext
|
|
Episode: 2333
|
||
|
|
Title: HPR2333: VirtualenvWrapper for Fish Shell
|
||
|
|
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr2333/hpr2333.mp3
|
||
|
|
Transcribed: 2025-10-19 01:25:41
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
This is HBR episode 2,333 entitled Virtual and Rapper for Fish Shell.
|
||
|
|
It is hosted by me and is about 14 minutes long and can remain an explicit flag.
|
||
|
|
The summary is in this episode talk about how I created my own Virtual and Rapper like interface using Fish Shell.
|
||
|
|
This episode of HBR is brought to you by An Honesthost.com.
|
||
|
|
Get 15% discount on all shared hosting with the offer code HBR15, that's HBR15.
|
||
|
|
Better web hosting that's honest and fair at An Honesthost.com.
|
||
|
|
Hello Hacker Public Radio fans, this is Be Easy once again.
|
||
|
|
I'm going to do a quick little episode in response to BJB's excellent story about Virtual and Rapper.
|
||
|
|
She did a great job in explaining it. I learned a lot.
|
||
|
|
She briefly talked about how you can do Virtual and other shells.
|
||
|
|
She wanted to keep her shell tight and succinct and I think she did a great job doing that.
|
||
|
|
I'm going to go into how I use a Virtual and Rapper for Fish Shell.
|
||
|
|
For anyone who is not familiar with Fish Shell, Fish Shell is an alternative to Bash.
|
||
|
|
It's ManPage C. It is called, oh that's it, this is it.
|
||
|
|
Fish Shell is a smart user friendly command line shell for Mac OS Linux and the rest of the family.
|
||
|
|
I've been using Fish for a couple of years now because I really like how it does auto completion.
|
||
|
|
It has a nice little set of plugins and a nice ecosystem around it.
|
||
|
|
I have actually started to script a little bit and usually I script in Bash just because I'm more familiar with Bash scripting.
|
||
|
|
I have had an opportunity to do some scripting in Fish as well.
|
||
|
|
It's not as robust of a scripting language but it's much more useful, at least my opinion, much more useful shell.
|
||
|
|
But one thing it doesn't have is it doesn't have a way to run Virtual and Rapper.
|
||
|
|
I first fell out about Virtual and I've been using Python for a couple of years now as well.
|
||
|
|
I've been using Virtual Environments for that entire time and I've just been finding my file and the source that directory been activate.
|
||
|
|
And I always saw in that and when you do that there's always another file in there called Activate Fish and another one is called Activate.csh.
|
||
|
|
So I didn't know there were four but I figured out later when I switched to Fish Shell that yeah, if you did source, been Activate.Fish, it would actually activate your fish.
|
||
|
|
It's just a virtual environment in your Fish Shell in a similar manner as it does for Bash.
|
||
|
|
But there was no real way to do it easily.
|
||
|
|
So after I started to research Virtual of Rapper, how could I have a similar API to that? I could have similar commands to that.
|
||
|
|
So I've updated my Fish config file and I want to go over right now the edits that I've made to that Fish config file to make it so that I have similar functionality.
|
||
|
|
So the function I'm talking about is a way to easily with a single command switch to a virtual environment, easily create a virtual environment and destroy one.
|
||
|
|
And then one extra thing that I made was a way to list all the virtual environments that I have in Active right now.
|
||
|
|
So inside of my Fish Shell I guess to get there I have to go cd.config.fish
|
||
|
|
So then cd.config.flashfish and then I'm just going to go vim config.fish.
|
||
|
|
And so inside of my, and I'm going to put this in the show notes inside of my virtual environment, I have a lot of things inside of my config.
|
||
|
|
I have a lot of things going on, but one of the first things I do is I do a set-dash X and all caps virtual underscore all underscore disable underscore prompt one.
|
||
|
|
And that's a way to, because I'm using a custom power line show, I'm telling default fish to not use its way of adding a virtual long notification, usually in basher and fish inside of parentheses you'll see what the virtual environment you're currently in.
|
||
|
|
And I turned it off because the, the power line that I'm using shows which virtual environment in all of writing, so it's kind of redundant.
|
||
|
|
And I am including, I think either as a cover picture inside the show notes, a picture of what it looks like when I'm in a virtual environment.
|
||
|
|
So, so I, I used and BJB talked about this a little bit about how to use aliases and I, and you can use aliases and functions in fish shell as well.
|
||
|
|
And so, for this purpose, I also made another, another item called export set on the export set all caps work on underscore home equals my home directory slash ENVS.
|
||
|
|
And that's my, so I store all my, I want to store all my virtual environments in this directory.
|
||
|
|
And so, I have a aliases called LSEMVS, which is list LS owns, and that's a way for me to list all my virtual environments.
|
||
|
|
And what I'm, and what I'm doing here is I'm running this aliases, I'm doing LS, LS-EMVS.
|
||
|
|
And then dollar sign will go on home, pipe that into said, and I'm removing a backslash out of there in my said command.
|
||
|
|
And what that is doing the LS-EMVS, if you don't know about that, it actually adds a comma.
|
||
|
|
It puts all of your list on that LS command comma separated.
|
||
|
|
So, when I run the said command, it takes out, there's a extra backslash, there's extra forward slash at the end of, at the end of every one of those directories.
|
||
|
|
So, I don't want to see that extra forward slash. So, I just say said, you know, s, forward slash, backslash, forward slash, forward slash, g.
|
||
|
|
And that's the saying, whenever you find a forward slash, get rid of it with nothing, replace it with nothing.
|
||
|
|
So, my first command is LS-EMVS, when I do LS-EMVS, I see a comma separated list of all my virtual environments.
|
||
|
|
And then I have two functions, three functions.
|
||
|
|
What is that?
|
||
|
|
Yes, a couple, there's four functions actually, because two of them are kind of the same.
|
||
|
|
So, one of them is MK Virtual Alps 2.
|
||
|
|
And that one is, if I wanted to use Virtual Alps, so the command I'm doing, and when I run that, if I write MK Virtual Alps 2, is Virtual Alps-P Python 2.
|
||
|
|
The dollar sign, work on home, slash, dollar sign, argv, semicolon, and source, dollar sign, work on home, slash, dollar sign argv, slash bin, slash activate.fish, semicolon, and echo,
|
||
|
|
virtual environment created in thumb codes.
|
||
|
|
So, what that is doing is I'm just writing a little function that says what I type in MK Virtual Alps 2, and then some text afterwards, I'm going to make a new virtual environment called that text with using Python 2 as the Python interpreter.
|
||
|
|
The only time I really use Python 2 nowadays is if I'm looking at some legacy code, or if I'm using Fabric, which is a wave, it's like a Python wrapper around SSH.
|
||
|
|
It's a good way of describing it.
|
||
|
|
So, I manage my Raspberry Pi's with Fabric, and so servers that I use all the time.
|
||
|
|
So, things like reboot, or update, or that kind of stuff, I just have some Fabric commands to do.
|
||
|
|
So, I can say all these things, all the same time, update, all these things, all the same time, reboot.
|
||
|
|
Anyway, so, usually I use Python 3, so I have one that's just called MK Virtual Alps.
|
||
|
|
I don't put a 3 after it because that's my normal one.
|
||
|
|
It's Virtual Alps.p, Python 3, and everything else about that is the same.
|
||
|
|
So, I'm still going to make a virtual Alps on Workup, Home, Slash, Dollar Sign, RGV, which is the argument that I'm entering,
|
||
|
|
and then sourcing the Activate.Fish file, and then the same virtual environment has been created.
|
||
|
|
So, now I have LSOMs to list all my virtual environments, MK Virtual Alps, or MK Virtual Alps 2 to make new ones,
|
||
|
|
and then once I make whatever I want to install, pick install-r, requirements.txt, if I already have a file that has all the things I want to install.
|
||
|
|
So, that's nice, and then my next one is RM Virtual Alps, which as it sounds like it's removed of a virtual environment.
|
||
|
|
So, in here, it's a little bit different, and this is how fish is different from Bash in the way it does tests.
|
||
|
|
And I'm not going to go into the details about how fish works with this, but I'll just show the command, and how Bash differs.
|
||
|
|
It's like a whole other thing. So, I'm going to avoid it for now.
|
||
|
|
But inside of there, I have if test-n, and then quotes, Dollar Sign, Virtual Alps, deactivate, end, and then RM-RF, work on Home, Slash, RGV.
|
||
|
|
Semicolon, and Echo, Virtual Environment, deleted.
|
||
|
|
So, what that is doing is saying if there is, if that virtual environment exists, then delete it.
|
||
|
|
Oh, if that virtual environment, if I am in that virtual environment right now, that's what the Dollar Sign, if test-n, in double quotes, Dollar Sign, Virtual Alps, that is a fish variable that says, you know, your current virtual environment that you're in.
|
||
|
|
And so, I'm saying, by saying, if test-n, I'm saying, if that exists, then deactivate.
|
||
|
|
So, if I'm in a virtual environment, deactivate it first, and then RM-RF, otherwise, it'll just skip that, and just remove it.
|
||
|
|
So, now I can list them, I can create them, but I don't have an easy way to get into one.
|
||
|
|
So, I use the similar command from Virtual Rapper, which is work-on, and so I made a function.
|
||
|
|
I wanted to do it in alias, but I decided to make a function out of it, because I didn't know if I was going to add more stuff to it later.
|
||
|
|
But I have it, so I probably could just make it in alias.
|
||
|
|
But my function called work-on is just source, Dollar Sign, work-on-home, slash Dollar Sign, argv, slash bin, so I have to activate fish, semicolon, and the word n, echo, switch to virtual environment.
|
||
|
|
And as it sounds like, I'm just sourcing that file.
|
||
|
|
So, if I make up, for instance, that fabric virtual environment, I'll say work-on-fabric, and then it'll switch to virtual environment, and you'll see that I'll be in the fabric virtual environment.
|
||
|
|
So, that's it. It's pretty simple. I really appreciate BJB's posts.
|
||
|
|
I don't want to go too far in the weeds with fish or with Python, but I find both of these things in my daily life just help me tremendously.
|
||
|
|
And I encourage other new committers and new submitters to Hacker Public Radio, and I hope BJB continues to submit, because I really like hearing what she has to say.
|
||
|
|
So, for now, that's it from Be Easy, and from here in Central Command, keep hacking.
|
||
|
|
You've been listening to Hacker Public Radio at HackerPublicRadio.org.
|
||
|
|
We are a community podcast network that releases shows every weekday, Monday through Friday.
|
||
|
|
Today's show, like all our shows, was contributed by an HPR listener like yourself.
|
||
|
|
If you ever thought of recording a podcast, then click on our contributing to find out how easy it really is.
|
||
|
|
Hacker Public Radio was founded by the digital dog pound and the Infonomicom Computer Club, and is part of the binary revolution at binwreff.com.
|
||
|
|
If you have comments on today's show, please email the host directly, leave a comment on the website, or record a follow-up episode yourself.
|
||
|
|
Unless otherwise status, today's show is released under Creative Commons, Attribution, Share a Life, 3.0 license.
|