Optimizing Visual Studio Code for Powershell Development

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to another session of pwsh24 my name is justin grote i am a data center solutions architect with allied digital and a microsoft mvp and today i'm going to be going through uh optimizing visual studio code for powershell this is going to be a session on really getting into some of the nitty gritty leveraging a lot of the experience that i've had with visual studio code which is a lot i started uh i've been using ise for a long time and a couple other editors but then when vs code came along a couple years ago i really jumped on board really forced myself to really get into it and go through all the pain of learning it and i hope to share some of those lessons with you today so why visual studio code powershell uh together um visual studio code is as most of you probably know by now is just sort of like it's this it's a text editor on steroids as a way is like it's not really an ide but it's got so much power and so much configurability and is really nice um uh tool for editing really anything so whether it's json or text or markdown or c-sharp or python or powershell and uh the microsoft team as well as the powershell team in particular really saw the power and momentum that this uh editing tool was getting early on and made a very powerful very comprehensive extension um tyler leads that current effort and he's doing a great job along with the powershell team to really add features to that and make it really effective and really powerful so uh the main reason we have here is that it will make you faster more effective and better at developing code so this session is going to skip over some of the real basics around vs code as well as basics around things like git and github just for the interest of time to go through those here's a couple places i recommend getting started if you're not familiar with vs code at all um this is a great intro video as well as an intro video done by tyler who writes the extension for the powershell extension writes the powershell extension for vs code and uh these are great uh starters there to get these are good articles to get started on that information and once you're ready to go a little bit further uh we have a couple additional videos again tyler did a great presentation going through some of the more detailed information some of which i'll cover here but really will help you get on-ramps into using visual studio code as your default powershell editor also a scott hanselman has had this excellent excellent series the bot we call him the bob ross of uh computing and he will very nicely guide you through some things like get 101 and even has a really nice section there and just doing basic text editing with vs code but learning maybe some tips and tricks and keyboard stuff that maybe you didn't know that will just help you type faster and help you everywhere not just in powershell and so i highly recommend that series as well so again as we go back to vs code and powershell uh this is the these are the lessons that i've learned as part of this and how i set up my environment and the lessons that i've learned that really helped me be really effective and really powerful in producing good powershell code so as a result of that the things i have here are opinionated and as mentioned you know these are just my opinions so you may disagree you may have particular styles you like i'm happy to have those discussions especially i hope to have this session be a little bit short so we can have discussion in the chat or maybe live um about some alternatives but this is basically just my opinions and there's everybody has their own styles different strokes for different folks and so just uh get that out of the way right up front this is not a religious prescriptive way of doing things it's just what works for me so when we combine powershell and visual studio code there are a few areas that i'm going to cover today that will really help you get supercharged into really using this and really making it powerful for you one of which is something that i developed recently it's the powershell extension pack this is a collection of vs code extensions that you can just simply install one extension that will install the rest of them for you and really help you get started and get rolling right away another thing is to go through is our powershell profile there are things that we can optimize in there to make life a little bit easier with vs code theming and special commands and whatnot and so we'll get into some of that as well we'll go into a lot of the settings tweaks vs code has lots and lots and lots of built-in settings hundreds of them every extension provides its own custom settings and this will both be a demonstration of the settings that i like as well as giving you an idea of how to find those settings how to change them and tune and tweak the environment just how you like it so that you can be as productive as you have and once you've got all that set up you don't want to lose it or maybe you work on multiple machines and you want to keep all that in sync not to set everything back up yet so we'll go through the new built-in setting synchronization that is now built into visual studio code so let's go ahead and get started with the powershell extension pack so the powershell extension pack is a vs code extension in and of itself sort of a meta extension that is an extension that just installs extensions these are actually pretty easy to build there's plenty of great documentation on them but i'm going to skip over that part of it and just go to the installation so here i have a default installation of visual studio code and in fact i want to show you something that you may not know about if i go to a folder here i have actually just downloaded visual studio code just actually just a few minutes ago into a folder so i downloaded the zip which you can get the zip and download it and extract it into a folder and so you can see here i have all my all the files that are here it's just the visual pseudo code and the code here and so what you can do and i actually need to close this because i forgot to do it uh go ahead and just do a new folder and name this folder data and if you do that that basically tells visual studio code that you want to run in portable mode so rather than save the data on your system in your app data or if you're on linux in your sort of user share folder it will save everything about your session or this particular instance of code in this data folder so this instance of visual studio code is now portable you can save it to a usb drive you can uh you can you know copy it up to a onedrive folder so if you like are like me who work for msp and you always want to have your ready to go visual studio code in a place that you can just get it and run it and it's all pre-set up how you like it then this is a great option for doing that um setting the new settings synchronization tool um really helps with this that this is less necessary as it used to be but if you need to go offline or you're working in an environment where you know they don't have internet access so you can't use the sync tool this is a great alternative option so now that i've created that data folder i'm just going to go ahead and reload visual studio code and here i have the default startup for visual studio code this is what it looks like if you've loaded for the first time you've never loaded it before and so in my data folder you'll see now it's starting to remember my extensions tracking my user data everything about my thing is now just being kept in this one folder pretty neat so um first thing i'm going to do is with uh ctrl shift p turn on screencast mode so you can see when i'm doing keystrokes and such so now i hit ctrl shift p you can see that that's what i did the other thing that i'm going to do is increase the zoom level a little bit so that you it's more clear what's going on and so here we have a default installation and so the first thing we're going to do is for that extension pack we're going to search for the powershell extension pack and if i can spell right that would help even better so it comes up so far third in the list i don't know why java extension pack comes up ahead of powershell for the powershell extension pack but hey i just put the thing up there so we'll see here you can get information once you have that and you can see information about the extension pack and most importantly it'll show you here everything that the extension pack is going to install so you can see all these different ones and maybe you don't want everything that i include maybe you just want subsets so you have your little install buttons here where you can just pick and choose the things that you want that i recommend but for instance by default we'll just go ahead and pick everything we'll click install and then this is going to go ahead and download all those extensions and install them and i'll just show with task manager here just showing the uh network performance here of it just pulling down all that information and then installing it you can see my disk ssd here going crazy on my surface laptop and so we're just going to wait for that to install here for a minute but you'll start seeing oh we got some new icons showing up here all these extensions are all installing together which is great saves us so much time having to go out find them install them ourselves but you also have the flexibility of installing even more extensions beyond that once that gets done i'm just going to go ahead and pause this recording for just a second while that gets installed and then we'll resume all right so now that that is installed we got a bunch of extra new icons over here we had a couple like welcome check this stuff out icons and all that kind of stuff we'll go through some of this here in a minute but i'm just going to go ahead and close down a bunch of this stuff for now and just kind of get back to my sort of nice little starting point here so we got a bunch of new icons we got all this stuff but again before we move forward the first thing that we're going to want to do as as i discussed is now we have our powershell package installed and so we're going to want to move on and go ahead and get those settings sync setup so that we can make sure that whatever we do here gets backed up and is synchronized so that if our computer gets destroyed or we want to go to another area we already have that synced to an account so we will go back to uh visual studio code i'm going to sign in here with my github account which i have already signed in you can also use you can use either github login or a microsoft login and it's your choice you can choose either you can um it just depends on where it stores it either stores it in a special github storage or a special storage for your microsoft account um it's either or doesn't really have um you know it's just kind of your preference they both work the exact same i tend to use the microsoft for my work one because our work logins are all azure active directory so i just use that one so but then i'm just going to go ahead and turn on settings sync here it's going to let you know that this is still a preview feature but it works pretty well i've been using it with the vs code insiders for quite a while now and i haven't had really too many issues with it there's plenty of documentation about it including like if there's certain settings you don't want to sync like they're specific to your local machine all that kind of stuff all that detail is there but we're going to go and turn it on here so it's going to pop up and ask me which things i want to synchronize so definitely want my settings my keyboard shortcuts i like having those synchronized uh any custom snippets i have snippets are little pieces of code that you might write they're like you type that thing over and over and over again you just want to type like three letters to bring up that code again your extensions the actual full extension information about them and which ones you want to have installed on each system as well as the ui state so there are some things that don't get managed by settings but things like moving windows around and uh hiding things under other things and just rearranging your screen that don't really get controlled by um the the settings file and so that's a matter of maintaining those so usually i have no reason to uncheck any of those i'm just gonna go and take them all i'm gonna use my github account and you'll see that the sync will start uh this is a custom one that i have here so i'm just going to go ahead and merge it i cleared it earlier so there shouldn't be too many changes here and you can see the whole details of the synchronization so again because i cleared it before haven't been any changes and so um that's you know this is just a basic starting setup and now as i make changes uh this sync will automatically keep things in sync and keep my stuff backed up which is great so uh we're gonna go ahead and move on to getting to the next section that we want to take care of so now we have our settings sync the next thing that we want to do is actually start tuning tweaking and customizing our environment how we want it so i'm going to go back to my visual studio code here and let's start going through some of these settings that we can tweak and i'm going to go ahead and first thing i'm going to do is what are the possible things you can tweak well now that i have all these things installed i can go to default settings after hitting ctrl shift p and here's a list of all the settings and what their possible options are and any help that's involved in them as you can see there are a lot of them if i scroll this file this file which is automatically generated has over 5881 lines so that's you know thousands and thousands of settings you can tune tweak and this is one of the really great things about vs code is it's so good about like not telling you how to work if you want to do your work a certain way you know go for it there's some things you like great some things you don't change it and uh the whole philosophy around vs code and a lot of the extension officers follow that is that there's no one right way to do it and if you know whatever your preference is whatever makes you most efficient for what you work on um you have the ability to change it so again these are my opinions this is what works best for me feel free to change any of this to however you like it so that's the default settings another way to view this is with ctrl shift p is just opening the settings view with the ui and if you're a little less about the command line you just kind of want some nice wizards that's all here too again same information all that information about these settings and all the details here so at that level let's go ahead and open my little prescriptive file here so this is just going to be a settings file which will have the detail that i'm looking to set up for my settings and then i'm also going to open my current settings in the json mode and split this to the right so that now we can see uh the settings that are going to be added as well with my preferred settings and then what will be nice here is vs code tends to update as we make these changes in real time so as i put the settings over here vs code will go ahead and apply those settings as we go so let's go through some of the first settings here these are just kind of general vs code settings and let me uh go ahead and i'm going to move this one over a little bit here and blow this up just a tiny bit so that that's pretty legible should already be pretty legible but um actually go ahead and take this down just a little bit so first what i'm gonna do is uh this is i think the most important setting you can do in visual studio code is changing your work bar so it's on the right so when i save that change notice this work bar moved over here to the right this is a huge difference because normally when it's on the left i'll go ahead and comment this back out again move it back you'll notice whenever i click here my code moves so if i'm doing something i want to look at something oh i got to move my eyes and i got to move back so for me this is always really jarring i'm just like no i'm trying to do something over here and i can't my code's constantly moving back and forth well if i put this setting in here and save it now when i do this my code stays in the same place so i can do this do my searches do any source control stuff i need to do and it all stays in the same place which is great it's super useful and really helps you stay focused on what you're doing without impacting your work as you need to do these side things from time to time so very very important setting highly recommended another thing is there's this little mini map here which kind of shows you your code in a nice little kind of like uh gutter view so for navigating your code like if you're looking at a code base and you kind of have a general idea of where you are this is kind of helpful to get to things i don't really use this i tend to use like go to function and if i'm familiar enough with my code to see it in this view i'm generally familiar enough to know generally which line to scroll on so i generally just kind of consider this wasted space so by putting this in here that goes away and now i have more screen space to focus on my code and don't have to worry about that so much another simple setting um debug on task errors tasks are things that when you set up in visual studio code like starting up azure functions or starting up a linter and then you want to start debug after that um a lot of times it'll pop up annoying um pop-ups if this doesn't quite start up right or maybe you have errors that you want to ignore and those pop up a bunch they tend to annoy me i like to live dangerously it doesn't really affect anything when i'm just debugging so i go ahead and turn that on uh some additional settings um as far as column selection this is a way to do uh selecting columns where it selects them in big long vertical sections as opposed to highlighting like this i'm not a fan of it so i turn that off extension recommendations when you install some extensions there's a setting extension authors can do that say hey if you like this extension you can install all these other extensions and so i typically at this point know what extensions i want so thanks but no thanks um some editing stuff here um i like to use vs code as my diff editor for not just vs code stuff but for like when using fiddler or when doing git differentials and very often especially when working with fiddler and wearing with raw http requests white space matters a white space in a in a request in one place that doesn't exist in the other like a trailing white space can cause the request to fail versus work so that's something where i tend to want to see that white space in a diff and have it not ignore it and so i go ahead and add that in some other items here so as far as fonts go here we've kind of had the default font so far there's this font called cascadia cove so cascadia code as you see here is sort of the new the windows terminal font and also a new font that microsoft developed it's really nice i like how it looks um there's a fork of it called cascadia cove which if you just google it you'll find it but that fork basically adds a whole bunch of extra symbols and emojis and uh and ligatures and things basically it makes it supercharges that to work really well and now you have all kinds of cool console stuff and prompt features and that kind of stuff so i uh installed this separately uh which you can go out and download and install it and then this just sets it up my fonts for both my editor and my debug console to use that and i also want those cool font ligatures so to demonstrate what a font ligature is i'll go ahead and bring up my terminal here so my powershell terminal by default you'll see it kind of has the squiggly line of this weird little box that's because i have a special custom prop which we'll get into here in a second but those characters that i use in the prompt are not present in this default font so but if i take this and i go ahead and add them in if i copy the right thing and just to demonstrate what a ligature looks like knows my equal and arrows here just looks like an equal and arrows as you would expect let's see where i messed up here need a comma there hit save and you see that my editor changed to this so that now and i haven't updated the terminal font because that's later so forget what i said here but you'll see now that the font ligatures is true you notice the font changes a little bit and then we will so you'll see the font here changed a little bit and now i can do these things called ligatures which i do an exclamation mark and that becomes not equals that becomes that and these are just kind of helpful to like make different symbols for various combinations of characters that you do um more obvious so there's more about ligatures you can find on other things those will come up etc but that kind of season so i like this font i think this font is very nice for both the editor and console view and so i use it everywhere and so that's that um auto saving files because i use git a lot um i'm not really i usually don't i usually commit changes very frequently and then upload them later so i like to have auto save on my files so basically after 10 seconds my files are automatically going to save and then i have that information and i don't have to worry about those files missing and i don't worry so much about like making a change having auto save and oh it broke because i can just revert my get back to what my previous one is so once you get comfortable with git once you really get used to it you really can rely on it as a safety net and you kind of keep let it kind of keep versions for you like you would think like with onedrive or sharepoint like keeping file versions as you go and so i don't really have much compunction with turning this on and so i like it and so when a file is not saved you see this little icon there when you save it'll do that and so eventually now that'll just turn off automatically uh always remember unsaved files uh i like this one this is if my program crashes or i close if i just close the window or anything if i left like an untitled file open i want that untitled file to be back when it shows back up i don't want any of those files to go away until i explicitly close it and hit an x on it so that's what that setting is good for this is just a little quality of life thing if you have multiple editors open in your thing by default you have to kind of hold down shift to use the mouse wheel to go between them this just removes that shift requirement so if i put that in here now i can just scroll the wheel without having to hold down shift and i like that so that's that's my personal thing i don't need that kind of a lock i'm i'm pretty uh disciplined with my wheel mouse i think so that's how that works for me um another thing too is i like when my workbench starts up like the vs code kind of welcome is nice but i really like to just get right to work so when i have a new uh vs code window i like it to just start at an untitled file so when i close this and reopen it assuming that i didn't have anything open which i did let me go and close all these down see i like it to start just ready to go ready to write like that first screen is great show me old files show me new things but i've used vs code long enough at this point that i know how to do all that stuff with ctrl shift p so i don't need it to be there so let's get back to our editors again go to my recent there's my uh existing settings and then my personal settings split this guy back to the right again whoops let's flip that the other way okay so um other items along these uh the file default language powershell another very useful one if your primary thing that you do in vs code is powershell you might as well make it so that when you when you do a new file it automatically opens it as a powershell file so you can just start writing powershell right off the bat you're good to go you don't have to go down here and change it to powershell any of that kind of stuff um just your default new file is a powershell file so i like that be my default so that's why i put that there uh rulers so this has just adds a nice little line on the side i'm gonna have to zoom out here to really demonstrate it let's go and close this for now but if i zoom out here a bit uh this just adds this nice little line here and that's just a nice little guide we tend to like 120 characters for our source files um you can set this to whatever you want 80 120 160. but it's a nice reminder that if i've gone this far maybe i need to wrap it in and powershell is really good with having all kinds of ways to make your code more vertical than horizontal so it's easier to read so it's a nice little reminder that like hey maybe i've written this thing too long and i need to wrap it back so let me open my settings again okay for intellisense um when you're writing powershell code uh and the integrated console is loaded when you do different commands it will uh provide all kinds of intellisense for you as far as commands that you can run and so but sometimes it'll also provide a little kind of all the various text text snippets that exist and i don't like those um i want to make sure that those suggestions start with um command line items so i go ahead and put these in so that i want to make sure that any snippet suggestions that come in terms of snippets i want those to come below suggestions for like parameters or commandlets or that kind of thing so i had to add that in um i also wanted to prevent the quick suggestions in certain scenarios and then this is how powershell behaves i can power shell at the console if you do you know new item dash pa and hit tab it auto completes the path i like that so i like that to happen in my editor too so if i start a new powershell file and i do new item and you know there's those completions whoops where's my shark i don't know why this is not picking up my intellisense well typically this will show path here now and within these if you hit tab it'll do the autocomplete whereas normally the tab will just actually do a tab and you actually have to choose and point control space also works for getting more information about all the ones etc no i didn't want to say that go away so we have another item typically vs code updates in the background and so when you close it it'll just update for you um i use it uh vs code insiders which is sort of like the beta version a lot and that updates pretty much daily so i pretty much only want that to update when i tell it to update and it'll just give me an icon down here and choose restart to update so that way if i'm working on something for a project or something i don't want to close my vs code window and then all of a sudden open it up and it broke because of something insiders thankfully that rarely ever happens insiders is actually pretty stable but this is just a safety thing that if i'm doing work i don't want to update it till the end of the day so i'm closing windows opening windows i'm not surprised and i just know at the end of the day or the beginning of my day i can go down there and update it and then test to see if anything broke for this setting i like to um let me blow up the view again sorry oh and turn on my screencast mode sorry about that so i'm just hitting ctrl shift uh equals or just control equals to blow up and minimize the zoom there just as a tip there so uh here we have tab completion uh we have enable auto detect color scheme this is off by default but i like it if i switch my windows to a light theme i want my vs code theme to switch to light as well in this case it'll switch to ise mode for me i like whenever i start a new vs code window or a new terminal i like to have my vs code start maximized i don't need it to remember where i was if it was a smaller window and i start up vs code again i don't want it to remember that smaller window i just always wanted to start a full screen that's just how i am and as far as like if i had like 12 vs code windows when i closed them all for work yes the day before i don't want it to reopen all those windows uh if it if it crashed or something because then it's got to start up all those power shell processes start up all those extensions hammers my system i'm just going to go ahead and open the things that i needed because i probably had too many things open at that time anyways so i like having this setting to just give me one vs code window start me over and this is a nice one for changing how the window title works at the top uh rather than a dash it changes it to a vertical line and changes some of the separations like if i'm working with vs code remoting as well as what editor it is it just makes it easier so that when you're looking at it down in your taskbar which you can't see for me here but your taskbar it's a lot easier to distinguish between different windows with this different title setting okay so let's move on to some terminal stuff and by the way this you see how this is getting all kind of messed up this is another nice thing i can just choose format document and my settings are all nice and clean nice thing about json and then with one of the extensions that come in this extension pack the json if i want to i can sort my json alphanumerically all kinds of different ways and that'll work great too so one of the items that comes in the pack which we'll talk about here in a second so for my terminal stuff this just sets up the terminal so that i like a blinking cursor i like my cursor style to be a line instead of a box uh it's a box by default i like a line um uh the font size i like to have a lot of scroll back so i can scroll back up if i got a wall of text of errors in powershell or whatnot and then some windows customization i use a tool called scoop which is a tool like chocolaty or anything like that to install programs on your computer what makes scoop great is that scoop installs things completely in user space it installs them all directly in a particular folder it updates really fast it's a great tool for installing those little command line tools that you use kind of every day like like the dotnet framework or nmap or any of those things where you just want to have it available at the command line you don't need a full chocolate install really great tool everything's the repositories are github i'm not going to go too much into scoop but i'll just show you the repository scoop.sh it's my favorite um it's my favorite uh package management tool and it's all written in powershell so i'll just bring up scoop.sh here real quick just to show you what that looks like um this will give you information about it show you the demo install super easy check it out there's my scoop plug sorry chocolaty guys i use chocolatey on here too for other stuff but i love scoop but anyhow this because i install my powershell and keep it up to date using scoop i just need to tell um the terminal that when i do a new terminal i want it to be that's that scoop version of powershell not like my system built-in one and i don't like having all the uh like see all this logo and stuff coming up uh usually i like to keep that pretty terse so when i put that in here and i save it actually put all this in here and save it now when i start a new powershell window it just comes up with my terminal and earlier i was mentioning when i turn on that that cascadia cove setting i forgot that requires a restart of the terminal and so now you see that i get this nice little arrow with my um with my code prompt i get the nice little uh little ligature for powerline props which let my prompts look nice and pretty and if i go to something like well we'll do that we'll get into that a little bit later sorry i'm getting ahead of myself all right so moving on to the next item um this is one of the so now we're going to get in some extension specific stuff bracket pair colorizer is an extension that comes in the pack i really like this because what it does is it lines up all your brackets in your powershell code if you're doing like nested a lot of nested stuff it colorizes them so that they line up and so you can see you know if you have a misplaced bracket uh this is a real common thing powershell is usually not very good about like you usually just get this message missing closing i'll discuss this error lens thing here in a minute too but i should bring this over here for a better example so you can see if you're missing a bracket makes it really easy to figure out where you screwed up in your brackets because oh these brackets don't align so this is this has saved me so many times with all kinds of stuff from json to powershell and again this is a powershell file so i mean you know if i make these hash tables and that kind of stuff all that works it works with parentheses too just really nice really nice little thing that makes a huge difference now there is a different um colorizer out there this one i like the best because it uses the native vs code colorizer and so it's really fast really effective and really powerful so a couple of these settings i just like what these do is these make it so that this little thing is called the ruler over here so you notice when i click true it showed me very easily everywhere where true existed same thing if i like highlight cursor style if that doesn't exist anywhere um really nice little thing to line up so what this does with this setting enabled which i'll go ahead and take these and stick them into my system also um it does sometimes conflict with the built-in one i think this has been fixed recently but i still turn this on because vs code has some of its own built-in matching bracket stuff that um i prefer this extension so i tend to turn that off too so by putting that in there now you'll see um if i didn't completely break everything i might need to reload my vs code here i do have bracket pair colorizer right it puts there oh there it goes okay it just took it a second okay so uh so by enabling that you'll just see over here you see how the now it shows blue and purple so it makes it really easy if you have like a really long code file again trying to figure out those bracket problems it's like oh this is a missing bracket i can't find that where's the next closest one okay it's down here and now i find that matching i was like oh okay i screwed up and i didn't put enough of these brackets in there or i put in this case i didn't leave a trailing one and then that fixes it so again that just shows that really makes it easy to figure out how these brackets align that's what that setting does pretty helpful these are some git and github items in the interest of time i'm not going to go through too much of this but i do recommend the pull request extension which is a new github extension it's really nice i'm just going to go ahead and open a folder start start this up in a new folder we'll call this poch24 examples and so a lot of those settings are related to this pull request ascension but i'm just going to show you real quick why this is so cool is i'm just going to go typically when you make a new repository if you're signed into github in which i probably need to do here real quick sign into github pull requests and just off screen here i'm just doing a login to github allow it to go get me a pack token okay so now i can see all my pull requests and issues around this guy and so i just i just made this a folder and so now i can do publish to github allow it to do what it wants to do here real quick uh what do i want to name it make it a public repository because i'll put my examples in here my settings things you can go and just select this because it's a default and just like that this is now a project on github so if i go to my github there it is i just created that just now i didn't pre-create that all i did was make a new folder and click publish to github so great extension check it out i'm not going to go too much into that today but that just gives you an idea but while i'm here why don't i go ahead and copy over my fancy new settings files and the presentation so you guys can get that later okay so there's my example settings again let's go ahead and close this and again see doing this doesn't affect my code over here that's why i like it on the right i don't know why that i think that's not the default because i think vs code default or visual studio defaults on the left keep people comfortable but that's just again my preference so let me split right again here and then open my default settings oh and see i got these backwards again vs code is really nice about letting you just move this stuff around so no worries okay so let's get back down here so yeah so this is a lot of get stuff for there a couple extensions which i would like to go through here is for instance get graph now that i have um an actual git repository i can click get graph and see i guess i don't haven't actually committed anything so that warning of a setting later that makes that warning go away because it annoys me and so now i have this and it'll show you a graph of your commits if you have multiple branches if i make a new branch test and make this commit test2 make it i'll just make it an empty commit real quick you see in real time it shows you what's happening with your git so if you're a visual person really helpful for knowing what's going on and get lots of other tools do this greatly but this helps you have it right here in vs code and it's not just read only you can do checkouts rebases all that fun stuff great extension to have and the more information about that gets tied in through get lens so get lens kind of get you that even more about getting blame information hey who made this change oh i made that change or so and so made that change all that detail again not enough time to go too much into that right now but just kind of give you an idea of that uh so we're just going to skip through these settings but these are just think more settings that i like to have i like to make sure that auto i'm always up to date with my github repository so that if somebody else made a commit i wanted to always grab it whenever i commit something i want to do a push rebase i like to do squashes when doing merges all that kind of stuff and then get lens i like to have my get lens here under my source control view so i'm going to take all this and throw it in to my settings and again i forgot to turn on screencast mode again sorry about that take all this stuff throw it in here i don't have this github and this github actions extension i don't have in my default pack because you may not be using github actions but it is a great extension and this just enables auto refresh so you can watch your github actions in real time run and see if they complete it or not without having to go to the github portal back and forth all the time really helpful anyhow now that i've just done that uh rather than have the git lens as a separate button as you saw here before now it's all just here under my source which i like i like to be able to just go here and look at my repositories because i want everything involved with source control being under this source and so i typically also take like my pull requests and issues and do the same thing take my issues and just bring it here under source control and there it is and again that state thing will remember that and so i take my pull requests do the same thing and so now that icon goes away because now i have my pull requests and issues just visible right here so nice nice way to organize things okay let's get into the good stuff the powershell stuff so powershell i have a custom path for where i want my integrated console to run so this is just kind of a nice thing it will usually detect it but you don't need to do that and so here's where we get into the code formatting so these are code formatting settings that i like um i like my aliases corrected these are basically non-default settings there's many more settings to tune and tweak but this is my non-default settings i like i like autocorrect i like braces to open on new lines i want uh opening braces on the same lines i like it that if i write a double quoted string and it doesn't have it doesn't have any variables or anything in it i want when i do a formatter to just convert that to a single quoted string it's just that way i can basically just always write in double quotes and it'll automatically figure it out for me uh other main setting here there are many uh opinions on different ways to do brackets and such like that i like the one true brace style which basically will open brackets on new lines you'll see this when i do a formatting but basically whether you want your bracket on the same line as your function whether you want it to be a new line any of that kind of stuff there are lots of different ways to do that this just helps however you want to format your code you can even define custom formats this controls that uh i don't like i don't like this banner you know like it's it's it's cute but i don't need to know it so i like to keep it clean that goes away this is some pester stuff because i use pester five turn that off i don't need it to prompt me to update powershell because i update that with scoop separately i like my default version to actually be windows powershell 51 when i start new projects because a lot of my stuff i need to do is 51 compatible but on a per project setting in the workspace settings you can override this so i have some projects where my default seven i don't like this command explorer on the side here i don't ever use it so i just turned it off with this and on linux i want my i use my powershell as a login shell a lot so i want to have that these little run buttons if you have a powershell script started show up here they're nice especially if you use ise these are really comforting feely and fuzzy but i never use them i always use f5 and f8 as they show here so it's just wasted space to me and then here's the thing that goes under the radar a bunch but not sure that a lot of people know about is typically with launch configurations you're defining them inside a project most of the documentation puts it that way in terms of like how you debug but you can actually define those in your user configuration file and then they're available globally so even though i haven't defined a launch json i can have all my run commands available to me so right now see there's no configurations and typically i have to do add configuration and do all that stuff and it drops it in the folder if i take all this stuff and put it in specifically the launch configurations and because i just changed my powershell i like to do a new session so now i put those launch configurations in here and unfortunately i hit the bug where i had a key typed in here and my powershell froze so pause the second while i bounce my all right and we're back and so to uh reiterate now in my debug here or when i go to run debug i now have this drop down i have all these ready to go for interactive session run the current script run it with arguments run my pester tests wherever they are in the system or attach to an existing pester session if i'm doing things like azure functions and i don't have a task json defined here it's just now whenever i do or if i'm even not even have a folder open i have these debug options available to me so really handy really useful to put in your user settings and since i use settings sync everywhere i go has these ready to go so for all those formatting options that i added let me go ahead and do a new powershell and pick up an example out of my existing so here's an example of a very tersely written powershell script and you can go ahead and write this manually um but you have things like if you can read this this is basically um basically set makes a hash table with the variable test expands it out to just get test and then write what i expanded out so if i copy this and i put it in my terminal it works fine but what i can do here is now that i've turned on live formatting i can do format document and it will expand it expand to the pipeline change the question mark to where i object change the percent to four each change that right alias to right output put all the brackets in the right place if i do these on new lines or excuse me do this new lines non fancy style i do it on new lines and format it notice how it automatically indates the brackets or by the pipeline so you can have this and then there's a setting you can enable which i don't have here which is format on save where you can do this edit as you go and then when you save it'll automatically do it so you can write super shorthand and then when you save have it in a format that's nice legible avoiding aliases like we always harp on that's ready to go for your um for your code base and if you work with other people there's a new setting that was added to vs code very recently if you have the latest version that let will only format the sections of code that you have changed which is great for uh doing pull requests like you're doing a pull request or repository and maybe they don't they haven't formatted all their code this will just format your section of code that you're adding which is great so now we're getting down into the theming stuff one thing i like i really like the default theme of vs code as you've seen there's lots of crazy themes dracula etc solarize and those are all great but there's something about the default theme that i just really like i like the black i like the colors that are involved it works really well for me it may just be that i'm using it but there are some little inconsistencies like for instance the terminal down here isn't quite accurate the bracket pair colors don't quite match um what's in the terminal so i do a little bit of theme these are some theming tweaks that exist so i take these this is for bracket pair colorizer this is for indent rainbow let me close this so it's a little more obvious turn on my screencast mode again sorry about that uh and then some color corrections for both air lens which i'll show here in a second and um the actual terminal so these are all just colors that i've painstakingly gone through and customized to make things so that everything lines up and everything matches and then peacock which i probably won't have time up time to demo today peacock is a way of putting like different colored boundaries on different projects so you can have one project with a pink outlined vs code another project with a red outline vs code great if you're working on multiple projects you don't want to mix them up at the same time but i'm going to take that as well as the nice icon themes i like a couple little custom icons and i like a nice pretty blinking cursor i'm gonna go ahead and open my settings json put those in here hopefully it doesn't break anything okay so now i have nice fancy icons you notice my power my powerpoint now is a nice fancy powerpoint icon and if i go to um my vs code now if you look this matches this as best as i can do given limitations in um ps readline and such but so now when i'm writing down here and i'm writing code and i do things like you know function prompt when i copy and paste that up here it's going to match as close as i can get it so that again having that consistency having that highlighting consistency helps me be more productive because i'm expecting things to look a normal way so i also mentioned something called error lens so typically when you have problems with your code you see it down here in this little problems box i like to have it more immediate and so this air lens thing will take these errors and put them right here next to where the problem is really helpful when you're developing quickly to find issues and it also works with suggestions so if i make a parameter that's uh meaning password uh it's always running all the script analyzer stuff and it lets me know hey you know you really should use secure string this shouldn't just be a string that's a that's a bad practice but i i get told it the second i write that code as opposed to maybe seeing it down here okay maybe i should fix it all that kind of stuff like okay fine make it a secure string for me great and then that goes away the default colors are really strong and really bold so that's where some of this theming comes in is i like it to be a little less in your face and so that's where uh this theming comes in these uh error lens colors okay so that handles the color theming and that covers most of the main things this is just some ssh remoting stuff i'm not gonna have time to really go too much into vs code remoting but definitely check that out really helpful i'll do a separate session later on how to set up for container development with powershell but that kind of gets you there where you need for the settings so that is the very long portion of the presentation of which is the settings tweak but now you're at a place where you have this and you also now have it synced so you can go to another vs code start it up sign into the settings sync and it will set it all up just how it was in fact i'm going to demonstrate what that looks like right now
Info
Channel: PowerShell.org
Views: 6,950
Rating: 4.9389315 out of 5
Keywords: powershell, windows powershell, techsession, powershell summit
Id: 9uMorgBB_RU
Channel Id: undefined
Length: 51min 26sec (3086 seconds)
Published: Mon Oct 26 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.