Last active
March 11, 2022 08:44
-
-
Save eramella/e8aa81c1c817557a9c7e149b38ad2bcf to your computer and use it in GitHub Desktop.
PS Win 10 Set up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[push] | |
default = simple | |
[core] | |
pager = cat | |
editor = code --wait | |
autocrlf = true | |
[color] | |
ui = true | |
[color "status"] | |
changed = red bold | |
untracked = red bold | |
added = green bold | |
[color "diff"] | |
meta = yellow bold | |
frag = magenta bold | |
old = red bold | |
new = green bold | |
[color "branch"] | |
current = cyan bold | |
local = yellow | |
remote = green bold | |
upstream = magenta bold | |
[format] | |
pretty = tformat:%C(yellow bold)%h %C(green bold)%>>|(22)%ad %C(white bold)%>>|(42)%aN %C(dim white)%s %C(yellow bold)%d^I | |
[log] | |
date = relative | |
[alias] | |
dt = difftool | |
mt = mergetool | |
st = status | |
logtree = log --graph --abbrev-commit --decorate --format=tformat:'%C(bold yellow)%h %C(bold green)%ar %C(white bold)%aN %C(dim white)%s%C(bold yellow)%d%C(reset)' --all | |
outgoing = log @{u}.. --oneline | |
incoming = "!git remote update -p; git log ..@{u} --oneline" | |
branchdiff = "!f() { git diff --stat --color ..; }; f" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Add-Path { | |
<# | |
.SYNOPSIS | |
Adds a Directory to the Current Path | |
.DESCRIPTION | |
Add a directory to the current path. This is useful for temporary | |
changes to the path or, when run from your profile, for adjusting | |
the path within your powershell prompt. | |
.EXAMPLE | |
Add-Path -Directory "C:\Tools\Git\cmd" | |
.PARAMETER Directory | |
The name of the directory to add to the current path. | |
#> | |
[CmdletBinding()] | |
param ( | |
[Parameter( | |
Mandatory=$True, | |
ValueFromPipeline=$True, | |
ValueFromPipelineByPropertyName=$True, | |
HelpMessage='What directory would you like to add?')] | |
[Alias('dir')] | |
[string[]]$Directory | |
) | |
PROCESS { | |
$Path = $env:PATH.Split(';') | |
foreach ($dir in $Directory) | |
{ | |
if ($Path -contains $dir) | |
{ | |
Write-Verbose "$dir is already present in PATH" | |
} | |
else | |
{ | |
if (-not (Test-Path $dir)) | |
{ | |
Write-Verbose "$dir does not exist in the filesystem" | |
} | |
else | |
{ | |
$Path += $dir | |
} | |
} | |
} | |
$env:PATH = [String]::Join(';', $Path) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is my reminder for Win 10 Powershell Dev Enviroment set up. | |
# It is a facsimile (with small changes) of Erik Lieben great blog post about this same subject: https://www.eriklieben.com/my-windows-development-environment-in-2016/ | |
# Install latest Powershell version | |
# Set Execution policy | |
Set-ExecutionPolicy RemoteSigned | |
# Unblock script files if necessary | |
Unblock-File script.ps1 | |
# or unblock a directory | |
gci | Unblock-File | |
#Create a PowerShell profile | |
New-Item -Path (Split-Path -parent $profile) -ItemType Directory | |
New-Item $profile -ItemType file | |
#Create these 2 directory where most appropriate in your system | |
md Tools #This directory is for PowerShell tool scripts | |
md Repository #This is for you Git repos | |
#Now create a "Module" folder under the WindosPowerShell directory in ~\Documents | |
cd c:\Users\{UserName}\Documents\WindowsPowerShell | |
md Modules | |
#Update the $Profile file with the contact of the attached Microsoft.PowerShell_profile.ps1 | |
#Create a folder named PowerShellScripts in your Tools folder | |
cd Tools:\ | |
md PowerShellScripts | |
#Inside the PowerShellScripts folder create a file named Add-Path.ps1 | |
cd PowerShellScripts | |
New-Item Add-Path.ps1 -ItemType file | |
#See attachment for content | |
#Also add the "Load default script libraries" section to the $profile file (see attached) | |
#Download the latest version of PortableGit from https://github.com/git-for-windows/git/releases and unpack it to the C:\Tools folder | |
#Add the following to the $profile file | |
##------------------------------------------- | |
## Add paths to PATH | |
##------------------------------------------- | |
Add-Path (Get-Item "Tools:\PortableGit-2.12.2.2-64-bit\usr\bin").FullName, #Adjust based on your PoretableGit Folder name | |
(Get-Item "Tools:\PortableGit-2.12.2.2-64-bit\cmd").FullName #Adjust based on your PoretableGit Folder name | |
########## | |
#Setup your user information for Git, this information is used when you perform commits. | |
git config --global user.name "Your name" | |
git config --global user.email [email protected] | |
#Create a default .gitignore file | |
cd $env:USERPROFILE | |
New-Item .gitignore -ItemType file | |
git config --global core.excludesfile $env:USERPROFILE/.gitignore | |
#Now you can add your gitignore content | |
#Set the default push mode to simple | |
git config --global push.default simple | |
#Modify the default pager from less to cat | |
git config --global core.pager cat | |
#Change the colors used - Beter color for git with powershell | |
git config --global color.ui true | |
git config --global color.status.changed "red bold" | |
git config --global color.status.untracked "red bold" | |
git config --global color.status.added "green bold" | |
git config --global color.diff.meta "yellow bold" | |
git config --global color.diff.frag "magenta bold" | |
git config --global color.diff.old "red bold" | |
git config --global color.diff.new "green bold" | |
git config --global color.branch.current "cyan bold" | |
git config --global color.branch.local "yellow" | |
git config --global color.branch.remote "green bold" | |
git config --global color.branch.upstream "magenta bold" | |
#Or you can add update the .gitconfig file under your user forlder (c:\Users\{UserName}\ | |
#Modify the way the git log output looks like | |
git config --global format.pretty "tformat:%C(yellow bold)%h %C(green bold)%>>|(22)%ad %C(white bold)%>>|(42)%aN %C(dim white)%s %C(yellow bold)%d^I" | |
git config --global log.date relative | |
#Or see .gitconfig file attached | |
#Creating aliases for common tasks | |
git config --global alias.dt difftool | |
git config --global alias.mt mergetool | |
git config --global alias.st status | |
#Or check attached .gitconfig file | |
#Creating an alias to show the log as tree | |
git config --global alias.logtree "log --graph --abbrev-commit --decorate --format=tformat:'%C(bold yellow)%h %C(bold green)%ar %C(white bold)%aN %C(dim white)%s%C(bold yellow)%d%C(reset)' --all" | |
#Or check attached .gitconfig file | |
#Creating aliases to see incoming and outgoing commits | |
git config --global alias.outgoing "log @{u}.. --oneline" | |
git config --global alias.incoming "!git remote update -p; git log ..@{u} --oneline" | |
#Or check attached .gitconfig file | |
#Creating an alias to see difference between branches | |
git config --global alias.branchdiff "!f() { git diff --stat --color $1..$2; }; f" | |
#Or check attached .gitconfig file | |
#Set the default text editor to use | |
git config --global core.editor "code --wait" | |
#Line endings | |
git config --global core.autocrlf true | |
#Set the tool to use for performing diff | |
#We will use VS Code. Just add the followings to the .gitconfig file | |
##[diff] | |
## tool = default-difftool | |
##[difftool "default-difftool"] | |
## cmd = code --wait --diff $LOCAL $REMOTE | |
#Extending the command prompt info | |
#Install Posh-Git powershell extension https://github.com/dahlbyk/posh-git | |
#Follow instructions. There might be the need to install Nuget | |
PowerShellGet\Install-Module posh-git -Scope CurrentUser | |
#Now update this module to latest | |
Update-Module posh-git | |
#Insert the following before Set-Location in the profile | |
Import-Module posh-git | |
#Installing SSH certificate | |
#Create certificate first based on your e-mail and pass phrase | |
ssh-keygen -t rsa -C "[email protected]" | |
#Open $profile and add the "Start-SSHAgent" above the Goto Repository folder section (see profile file attached | |
Adding the SSH key to GitHub | |
#Copy the public key to the clipboard by performing the following command in PowerShell | |
cat $Home/.ssh/id_rsa.pub | clip.exe | |
# -Go to your GitHub settings page | |
# -Click in the left menu on SSH keys | |
# -Press the button 'Add SSH key' | |
# -Provide a name for your key so you know what it is | |
# -And paste the public key inside the key textbox | |
# -Press add key | |
#DONE (more can be done, see Erik Lieben blog) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##------------------------------------------- | |
## Create the default drives to common paths | |
##------------------------------------------- | |
New-PSDrive -name Repository -psprovider FileSystem -root D:\Repository | Out-Null #Update based on your directory location | |
New-PSDrive -name Tools -psprovider FileSystem -root G:\Tools | Out-Null #Update based on your directory location | |
New-PSDrive -name Modules -psprovider FileSystem -root $Home\Documents\WindowsPowerShell\Modules | Out-Null | |
##------------------------------------------- | |
## Load default script libraries | |
##------------------------------------------- | |
Get-ChildItem -Path "Tools:\PowerShellScripts\" -Recurse -Filter *.ps1 | ForEach-Object {. $_.FullName} | Out-Null | |
##------------------------------------------- | |
## Add paths to PATH | |
##------------------------------------------- | |
Add-Path (Get-Item "Tools:\PortableGit-2.12.2.2-64-bit\usr\bin").FullName, | |
(Get-Item "Tools:\PortableGit-2.12.2.2-64-bit\cmd").FullName | |
##------------------------------------------- | |
## Setup posh-git | |
##------------------------------------------- | |
Import-Module posh-git | |
##------------------------------------------- | |
## Start SSH Agent | |
##------------------------------------------- | |
Start-SSHAgent | |
##------------------------------------------- | |
## Goto repository folder | |
##------------------------------------------- | |
Set-Location Repository: | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment