-
Notifications
You must be signed in to change notification settings - Fork 1
Console
Cengiz Ilerler edited this page May 1, 2024
·
49 revisions
%USERPROFILE%
=$env:userprofile
=$HOME
=~
e.g.C:\Users\CILERLER
~/Source/local
~/Source/local/notes
~/Source/local/backups
~/Source/local/!nuget
~/Source/github/<username>/<repositoryname>
~/Source/vsts/<username>/DefaultCollection/<repositoryname>
~/Source/gitlab/<username>/<repositoryname>
~/Source/bitbucket/<username>/<repositoryname>
~/Source/assembla/<username>/<repositoryname>
...
New-Item -ItemType "directory" -Path "~" -Name "Source";
New-Item -ItemType "directory" -Path "~" -Name "Source\local";
New-Item -ItemType "directory" -Path "~" -Name "Source\local\notes";
New-Item -ItemType "directory" -Path "~" -Name "Source\local\!nuget";
New-Item -ItemType "directory" -Path "~" -Name "Source\github";
$o = new-object -com shell.application;
$o.Namespace("$env:userprofile\Source").Self.InvokeVerb("pintohome");
$o.Namespace("$env:userprofile\AppData\Roaming\Microsoft\UserSecrets").Self.InvokeVerb("pintohome");
$o.Namespace("$env:userprofile\.docker\volumes").Self.InvokeVerb("pintohome");
$o.Namespace("C:\ProgramData\chocolatey\lib").Self.InvokeVerb("pintohome");
$o.Namespace("$env:userprofile\Documents\PowerShell").Self.InvokeVerb("pintohome");
$o.Namespace("$env:userprofile\AppData\Roaming\NuGet").Self.InvokeVerb("pintohome");
$o.Namespace("$env:userprofile\.nuget").Self.InvokeVerb("pintohome");
$o.Namespace("$env:userprofile\AppData\Roaming\npm").Self.InvokeVerb("pintohome");
More info can be found here
# Download, and install `Caskaydia Cove Nerd Font Complete Windows Compatible` from https://www.nerdfonts.com/font-downloads
Invoke-WebRequest -Uri "https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/CascadiaCode.zip" -OutFile "~\Downloads\CascadiaCode.zip"
# Download a template
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/wiki/cilerler/cilerler.github.io/documents/oh-my-posh-theme.omp.json" -OutFile "~\source\local\notes\oh-my-posh-theme.omp.json";
Install-Module -Name oh-my-posh -Repository PSGallery -Scope CurrentUser
Install-Module -Name Terminal-Icons -Repository PSGallery
function prompt
{
return;
}
function Cd-Local() {
Set-Location $env:userprofile\source\local;
}
function Type-HostFile()
{
Get-Content -Path "C:\Windows\System32\drivers\etc\hosts";
}
function CloudFlare-Up()
{
docker run -d cloudflare/cloudflared:latest tunnel --no-autoupdate run --token <token>
}
function CloudFlare-Down()
{
docker rm -f $(docker ps -q -f ancestor=cloudflare/cloudflared)
}
Set-Alias -Name k kubectl;
Set-Alias -Name d docker;
Set-Alias -Name dc docker-compose;
function ShellToK8SContainer([string]$namespace, [string]$podName) {
kubectl -n $namespace exec -it $podName -- bash;
}
function Update-K8sSecrets([string]$namespace, [string]$deploymentName, [string]$secretName, [switch]$restart) {
$secretPath = "$env:userprofile\AppData\Roaming\Microsoft\UserSecrets\$secretName\appsettings.Secrets.json\$namespace.$deploymentName.json";
if (!(Test-Path($secretPath))) {
Write-Error "Secret file not found: $secretPath";
return;
}
kubectl delete secret -n $namespace $deploymentName;
kubectl create secret generic -n $namespace $deploymentName --from-file=appsettings.Secrets.json=$secretPath;
if ($restart) {
kubectl rollout restart -n $namespace deployment/$deploymentName;
}
}
function SetGitUserSettingsRecursively([string]$name, [string]$email) {
Push-Location;
Get-ChildItem -Directory | ForEach-Object {
if (Test-Path (Join-Path $_.FullName ".git")) {
Write-Host "- $([System.IO.Path]::GetFileName($_.FullName))";
Set-Location $_;
git config user.name "$name";
git config user.email "$email";
}
}
Pop-Location;
}
function GitBranches([string]$branch, [switch]$pull, [switch]$prune, [switch]$compare, [switch]$delete, [switch]$all) {
Push-Location;
(Get-ChildItem -Directory).FullName | Where-Object { $([System.IO.Path]::GetFileName($_)) -notin "G" } | ForEach-Object {
Write-Output "----- $([System.IO.Path]::GetFileName($_))";
Set-Location $_;
$activeBranch = $(git rev-parse --abbrev-ref HEAD);
if ([string]::IsNullOrWhiteSpace($branch)) {
$updatedBranch = $activeBranch;
}
else {
$updatedBranch = $branch;
}
if ($prune) {
if ($pull) {
git pull --all --prune;
}
else {
git fetch --all --prune;
}
git branch -v | Select-String -Pattern '^ (?<branchName>\S+)\s+\w+ \[gone\]' | ForEach-Object {
if ($delete -eq $true) {
git branch -D $_.Matches[0].Groups['branchName'];
}
else {
Write-Output $_;
}
};
}
else {
if ($pull) {
if ($all.IsPresent) {
if (git status --porcelain) {
Write-Output "There are uncommitted changes in the repository. Aborting script.";
}
else {
$branches = git branch | ForEach-Object { $_.TrimStart('*').Trim() };
foreach ($branchToUpdate in $branches) {
Write-Output "Checking out branch [$branchToUpdate]";
git checkout $branchToUpdate;
git pull --all;
}
git checkout $activeBranch;
}
} else {
git pull --all;
}
}
else {
git fetch --all;
}
}
if ($compare) {
git branch -r;
$remoteHead = $(git symbolic-ref --short -q 'refs/remotes/origin/HEAD');
$errOutput = $( $output = & git diff --numstat "refs/remotes/origin/$updatedBranch" "refs/remotes/$remoteHead" ) 2>&1;
if (!$?) {
$err = ($errOutput[0] | out-string).Trim();
if ($err.StartsWith("fatal: ambiguous argument") -or $err.StartsWith("error: Could not access 'refs/remotes/origin/$updatedBranch'")) {
Write-Output "'origin/$updatedBranch' branch does not exist in the repository.";
}
else {
Write-Output "Unknown error occured while runing diff command: $err";
}
}
elseif ($output) {
$list = $output.Split([System.Environment]::NewLine, [System.StringSplitOptions]::RemoveEmptyEntries);
Write-Output "$($list.length) files are different between 'origin/$updatedBranch' and '$remoteHead'"
}
else {
Write-Output "There are no files that are different between 'origin/$updatedBranch' and '$remoteHead'"
}
} else {
git branch -a;
}
}
Pop-Location;
}
function SaveExtentionsVSCADS() {
code --list-extensions | ForEach-Object { "code --install-extension " + $_ + ";" } | Out-File "G:\My Drive\Source\github\cilerler\cilerler.github.io.wiki\documents\VisualStudioCode.ps1";
azuredatastudio --list-extensions | ForEach-Object { "azuredatastudio --install-extension " + $_ + ";" } | Out-File "G:\My Drive\Source\github\cilerler\cilerler.github.io.wiki\documents\AzureDataStudio.ps1";
}
function BackupLocal([switch] $files) {
git -C "G:\My Drive\Documents\Personal" pull;
if ($files) {
#$backupFolder = "$env:userprofile\Source\local\backups\$(hostname)\$([DateTime]::UtcNow.ToString('yyyyMMddHHmmss'))";
$backupFolder = "G:\My Drive\Source\local\backups\$(hostname)\$([DateTime]::UtcNow.ToString('yyyyMMddHHmmss'))";
if (Test-Path $backupFolder) {
Write-Host "Removing $backupFolder";
Remove-Item $backupFolder -Recurse -Force;
}
Copy-Item "$env:userprofile\.gitconfig" -Destination (New-Item -Path (Split-Path -Path "$backupFolder\$env:username\*" ) -Type Directory);
Copy-Item "$env:userprofile\.kube\config" -Destination (New-Item -Path (Split-Path -Path "$backupFolder\$env:username\.kube\*" ) -Type Directory);
Copy-Item "$env:userprofile\Documents\PowerShell\Microsoft.PowerShell_profile.ps1" -Destination (New-Item -Path (Split-Path -Path "$backupFolder\$env:username\Documents\PowerShell\*" ) -Type Directory);
Copy-Item "$env:userprofile\AppData\Roaming\Code\User\settings.json" -Destination (New-Item -Path (Split-Path -Path "$backupFolder\$env:username\AppData\Roaming\Code\User\*" ) -Type Directory);
Copy-Item "$env:userprofile\AppData\Roaming\azuredatastudio\User\settings.json" -Destination (New-Item -Path (Split-Path -Path "$backupFolder\$env:username\AppData\Roaming\azuredatastudio\User\*" ) -Type Directory);
Copy-Item "$env:userprofile\AppData\Roaming\Microsoft\UserSecrets" -Destination (New-Item -Path (Split-Path -Path "$backupFolder\$env:username\AppData\Roaming\Microsoft\UserSecrets" ) -Type Directory) -Recurse;
Copy-Item "$env:userprofile\AppData\Roaming\NuGet\NuGet.Config" -Destination (New-Item -Path (Split-Path -Path "$backupFolder\$env:username\AppData\Roaming\NuGet\*" ) -Type Directory);
Copy-Item "$env:userprofile\AppData\Local\Red Gate\SQL Prompt 10\Styles" -Destination (New-Item -Path (Split-Path -Path "$backupFolder\$env:username\AppData\Local\Red Gate\SQL Prompt 10\Styles") -Type Directory) -Recurse;
# Copy-Item "$env:userprofile\AppData\Roaming\npm" -Destination (New-Item -Path (Split-Path -Path "$backupFolder\$env:username\AppData\Roaming\npm" ) -Type Directory);
code --list-extensions | ForEach-Object { "code --install-extension " + $_ + ";" } | Out-File "$backupFolder\$env:username\VisualStudioCode.ps1";
azuredatastudio --list-extensions | ForEach-Object { "azuredatastudio --install-extension " + $_ + ";" } | Out-File "$backupFolder\$env:username\AzureDataStudio.ps1";
Set-Location $backupFolder;
}
}
function SwitchComputers() {
BackupLocal -files;
git -C "$env:userprofile\Source\local\notes\personal" pull;
Set-Location "G:\My Drive\Source\github\cilerler\";
GitBranches -pull -prune;
}
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
Import-Module -Name Terminal-Icons;
Import-Module -Name oh-my-posh;
oh-my-posh --init --shell pwsh --config "$env:userprofile\Source\local\oh-my-posh-theme.omp.json" | Invoke-Expression;
# dotnet suggest shell start
$availableToComplete = (dotnet-suggest list) | Out-String
$availableToCompleteArray = $availableToComplete.Split([Environment]::NewLine, [System.StringSplitOptions]::RemoveEmptyEntries)
Register-ArgumentCompleter -Native -CommandName $availableToCompleteArray -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$fullpath = (Get-Command $commandAst.CommandElements[0]).Source
$arguments = $commandAst.Extent.ToString().Replace('"', '\"')
dotnet-suggest get -e $fullpath --position $cursorPosition -- "$arguments" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
$env:DOTNET_SUGGEST_SCRIPT_VERSION = "1.0.1"
# dotnet suggest script end
# ~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
# ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
$profile
New-Item -ItemType "directory" -Path (Split-Path -Path $profile);
Get-Content .\profile.ps1 > $profile;
winget source update;
if not exists, go to https://winget.run/ and hit Install winget
(or alternatively https://winstall.app/)
winget upgrade;
install the rest from here
Use https://chocolatey.org/install#individual to install it
install the rest from here
Visual Studio
-*.vssscc;-*.vspscc;-*.dbmdl;-bin\;-obj\;-.git\;-.vs\;-TestResults\;-node_modules\;-bower_components\;-typings\
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"
git config --global fetch.prune true
git config --global core.editor "code --wait"
git config --global diff.tool bc;
git config --global difftool.bc.path "$env:USERPROFILE/AppData/Local/Programs/Beyond Compare 5/bcomp.exe";
git config --global merge.tool bc;
git config --global mergetool.bc.path "$env:USERPROFILE/AppData/Local/Programs/Beyond Compare 5/bcomp.exe";
Install-Module -Name SqlServer
dotnet tool install --global apiport;
dotnet tool install --global dotnet-aspnet-codegenerator;
dotnet tool install --global dotnet-counters;
dotnet tool install --global dotnet-ef;
dotnet tool install --global dotnet-format;
dotnet tool install --global dotnet-outdated-tool;
dotnet tool install --global dotnet-project-licenses;
dotnet tool install --global dotnet-sql-cache;
dotnet tool install --global dotnet-suggest;
dotnet tool install --global PlantUmlClassDiagramGenerator;
dotnet tool install --global git-flow-version;
dotnet tool install --global microsoft.dotnet.mage;
dotnet tool install --global try-convert;
dotnet tool install --global upgrade-assistant;
dotnet tool install --global docfx --version "3.0.0-*" --add-source https://docfx.pkgs.visualstudio.com/docfx/_packaging/docs-public-packages/nuget/v3/index.json;
$fileContext = @"
@echo off
REM download latest nodejs & npm from https://nodejs.org/en/
REM CALL npm install -g npm-windows-upgrade
REM CALL npm install -g typings
REM CALL npm install -g gulp
REM CALL npm install -g bower
CALL npm install -g autorest
CALL npm install -g firebase-tools
CALL npm install -g @angular/cli
CALL npm install -g generator-ngx-rocket
"@;
$fileContext | Out-File -FilePath "$env:userprofile\AppData\Roaming\npm\install.cmd";
$fileContext = @"
@echo off
ECHO -=[NODE]=-
CALL node -v
ECHO -=[NPM]=-
CALL npm -v
ECHO -=[AUTOREST]=-
CALL autorest --version
ECHO -=[FIREBASE]=-
CALL firebase --version
ECHO -=[NG]=-
CALL ng version
ECHO -=[NGX]=-
CALL ngx -v
"@;
$fileContext | Out-File -FilePath "$env:userprofile\AppData\Roaming\npm\versions.cmd";
$fileContext = @"
@echo off
REM download latest nodejs & npm from https://nodejs.org/en/
REM or RUN command below in administrative mode
REM CALL npm-windows-upgrade
CALL autorest --latest
CALL npm i -g firebase-tools
CALL npm uninstall -g @angular/cli
CALL npm uninstall -g generator-ngx-rocket
CALL npm cache verify
CALL npm install -g @angular/cli@latest
CALL npm install -g generator-ngx-rocket
rd %USERPROFILE%\Source\local\angular /s/q
md %USERPROFILE%\Source\local\angular
cd %USERPROFILE%\Source\local\angular
rd .\_templates /s /q
md .\_templates
cd .\_templates
md ng
md ngx
md ngx\demo
cd ng
CALL ng new demo --style=scss
cd ..\ngx\demo
CALL ngx new demo
"@;
$fileContext | Out-File -FilePath "$env:userprofile\AppData\Roaming\npm\upgrade.cmd";
- Visual Studio
- BeyondCompare
- FileZilla
- Remote Desktop connections