This guide walks you through setting up a collection of PowerShell functions designed to enhance productivity with directory navigation, Visual Studio Code (VS Code) integration, AI and web search capabilities, and Git utilities. Follow the steps below to install the script and configure it for your environment.
- PowerShell: Version 5.1 or later (Windows PowerShell or PowerShell Core). Check your version by running:
$PSVersionTable.PSVersion
- Visual Studio Code: Installed with the
code
command available in your terminal. Download from code.visualstudio.com. - Git: Installed and accessible via the
git
command. Download from git-scm.com. - Hugging Face Account: Required for AI functions. Sign up at huggingface.co.
-
Download the Script:
- Save the provided PowerShell script as
MyUtilities.ps1
in a directory of your choice (e.g.,C:\Scripts
).
- Save the provided PowerShell script as
-
Load the Script in Your PowerShell Profile:
- Open your PowerShell profile script by running:
If the profile doesn’t exist, PowerShell will prompt you to create it.
notepad $PROFILE
- Add the following line to load the script every time PowerShell starts:
Replace
. C:\Scripts\MyUtilities.ps1
C:\Scripts\MyUtilities.ps1
with the actual path to your script. - Save and close the file.
- Reload your profile by running the following or restart PowerShell:
. $PROFILE
- Open your PowerShell profile script by running:
-
Verify Installation:
- Run the
help
command to see available functions:help
- You should see a list of functions grouped into categories (Directory Navigation, VS Code Launch, AI and Web Search, Git Utilities, and Built-in PowerShell Commands).
- Run the
The ai
and ask
functions query the Hugging Face Mistral AI model, requiring an API key.
-
Obtain an API Key:
- Log in to huggingface.co.
- Navigate to Settings > Access Tokens (huggingface.co/settings/tokens).
- Generate a new token with Read access for “Make calls to Inference Providers.”
- Copy the token.
-
Set the API Key in PowerShell:
- Set the
HF_API_KEY
environment variable permanently:Replace[Environment]::SetEnvironmentVariable("HF_API_KEY", "your-api-key-here", "User")
your-api-key-here
with your actual token. - Alternatively, add it to your PowerShell profile for the current user:
Add:
notepad $PROFILE
Save, close, and reload the profile:$env:HF_API_KEY = "your-api-key-here"
. $PROFILE
- Set the
-
Test the AI Function:
- Run a test query:
ai "What is the capital of France?"
- Expected output: “The capital of France is Paris.”
- If you encounter errors (e.g., 401 Unauthorized), verify your API key and permissions.
- Run a test query:
The script includes functions (codeweb
, codepy
, codecpp
, codejava
) to launch VS Code with specific profiles. You can customize these profiles to match your development environments.
-
Understand VS Code Profiles:
- Profiles in VS Code allow you to save specific extensions, settings, and configurations for different development tasks (e.g., web development, Python, C++, Java).
- The script assumes profiles named “Web Dev,” “Python Dev,” “CPP Dev,” and “Java Dev.” You can rename them or create new ones.
-
Create or Import Profiles:
- Open VS Code.
- Access the Profiles menu:
- Click the gear icon (bottom left) > Profiles > Create Profile.
- Name your profiles (e.g., “Web Development,” “Python,” “C++,” “Java”) or keep the script’s default names.
- Configure each profile with relevant extensions and settings:
- Web Development: Install extensions like “Live Server,” “Prettier,” and “ESLint.”
- Python: Install “Python” and “Pylance” extensions, configure Python interpreter.
- C++: Install “C/C++” extension, configure compiler paths.
- Java: Install “Java Extension Pack.”
- Alternatively, import existing profiles:
- Go to Profiles > Import Profile and follow the prompts.
-
Update the Script (Optional):
- If you used different profile names, modify the
codeweb
,codepy
,codecpp
, andcodejava
functions inMyUtilities.ps1
:function codeweb { code . --profile "Your-Web-Profile-Name" } function codepy { code . --profile "Your-Python-Profile-Name" } function codecpp { code . --profile "Your-CPP-Profile-Name" } function codejava { code . --profile "Your-Java-Profile-Name" }
- Save the script and reload your profile:
. $PROFILE
- If you used different profile names, modify the
-
Test VS Code Functions:
- Run:
codeweb
- VS Code should open in the current directory with your web development profile. Repeat for
codepy
,codecpp
, andcodejava
.
- Run:
The goDesktop
, goDownload
, goCollege
, goPractice
, goProjects
, and goto
functions navigate to specific directories. Customize these paths to match your file structure.
-
Modify Navigation Functions:
- Open
MyUtilities.ps1
in a text editor. - Update the paths in the following functions:
function goDesktop { $desktopPath = [Environment]::GetFolderPath("Desktop") # Usually fine as-is if (Test-Path $desktopPath) { Set-Location $desktopPath } else { Write-Error "Desktop path does not exist: $desktopPath" } } function goDownload { $downloadsPath = Join-Path ([Environment]::GetFolderPath("UserProfile")) "Downloads" # Default Downloads if (Test-Path $downloadsPath) { Set-Location $downloadsPath return } $fallbackDownloadsPath = "D:\Your\Custom\Downloads" # Change to your fallback path if (Test-Path $fallbackDownloadsPath) { Set-Location $fallbackDownloadsPath return } Write-Error "Downloads path does not exist: $downloadsPath or $fallbackDownloadsPath" } function goCollege { Set-Location 'C:\Your\Path\To\College' # Change to your college directory } function goPractice { Set-Location 'C:\Your\Path\To\Practice' # Change to your practice directory } function goProjects { Set-Location 'C:\Your\Path\To\Projects' # Change to your projects directory }
- Open
-
Update Path Bookmarks for
goto
:- The
goto
function uses a hashtable$MyPaths
for bookmarked paths:$MyPaths = @{ "working" = "C:\Your\Path\To\Working" # Change to your working directory "college" = "C:\Your\Path\To\College" # Change to your college directory "down" = "C:\Your\Path\To\Downloads" # Change to your downloads directory }
- Add or remove bookmarks as needed.
- The
-
Save and Reload:
- Save
MyUtilities.ps1
and reload your profile:. $PROFILE
- Save
-
Test Navigation:
- Run:
goCollege goto working
- Verify that you navigate to the correct directories.
- Run:
-
View Available Commands:
help
Use
help 1
tohelp 5
for specific groups (e.g.,help 1
for navigation functions). -
Example Commands:
- Navigate:
goProjects
,goto college
,cdl MyFolder
- Launch VS Code:
codepy
(opens with Python profile) - AI Query:
ai "What is 2 + 2?"
(returns “4”) - Web Search:
webSearch "PowerShell tutorial"
(returns a result or opens a browser) - Git Operations:
gacp "my commit message"
(add, commit, push)
- Navigate:
- AI Function Errors:
- 401 Unauthorized: Check
HF_API_KEY
withecho $env:HF_API_KEY
. Regenerate the token if invalid. - 429 Rate Limit: Wait a few seconds and retry. Consider upgrading your Hugging Face plan for higher limits.
- 401 Unauthorized: Check
- VS Code Profile Not Found: Ensure the profile exists in VS Code. Run
code --list-profiles
(if available) or check the Profiles menu. - Navigation Errors: Verify paths in
MyUtilities.ps1
. Ensure directories exist. - Git Commands Fail: Ensure Git is installed and configured (
git --version
).
Feel free to modify the script or add new functions. Share improvements by forking the repository (if hosted) or contacting the author.
This script is provided as-is for personal use. Modify and distribute freely, but no warranty is provided.