Skip to content

Commit b717620

Browse files
committed
🎉 Added pwsh/
1 parent 520eaca commit b717620

17 files changed

+1507
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -------------------------------- #
2+
# Microsoft.PowerShell_profile.ps1 #
3+
# -------------------------------- #
4+
#
5+
# Profile for Powershell and PowerShell Core
6+
# ==========================================
7+
8+
# Write-Output "Microsoft.PowerShell_profile.ps1"
9+
10+
Push-Location (Split-Path -parent $profile)
11+
"components-shell" | Where-Object {Test-Path "$_.ps1"} | ForEach-Object -process {Invoke-Expression ". .\$_.ps1"}
12+
Pop-Location
13+
14+
# EOF #

pwsh/aliases.ps1

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# ----------- #
2+
# aliases.ps1 #
3+
# ----------- #
4+
5+
# Write-Output "aliases.ps1"
6+
7+
# Navigation Aliases
8+
# ==================
9+
10+
# Easier Navigation: .., ..., ...., ....., and ~
11+
${function:~} = { Set-Location ~ }
12+
# PoSh won't allow ${function:..} because of an invalid path error, so...
13+
${function:Set-ParentLocation} = { Set-Location .. }; Set-Alias ".." Set-ParentLocation
14+
${function:...} = { Set-Location ..\.. }
15+
${function:....} = { Set-Location ..\..\.. }
16+
${function:.....} = { Set-Location ..\..\..\.. }
17+
${function:......} = { Set-Location ..\..\..\..\.. }
18+
19+
# Navigation Shortcuts
20+
${function:dev} = { Set-Location ~\code }
21+
${function:docs} = { Set-Location ~\Documents }
22+
${function:dl} = { Set-Location ~\Downloads }
23+
${function:dt} = { Set-Location ~\Desktop }
24+
25+
Set-Alias -Name desk -Value dt
26+
Set-Alias -Name desktop -Value dt
27+
28+
# Oddly, Powershell doesn't have an inbuilt variable for the documents directory. So let's make one:
29+
# From: https://stackoverflow.com/a/12949659
30+
# $env:DOCUMENTS = [Environment]::GetFolderPath("mydocuments")
31+
32+
# ------------------------------------------------------------------------------------------------------- #
33+
34+
# PowerShell Utility Aliases
35+
# ==========================
36+
37+
# Reload the shell
38+
Set-Alias -Name reload -Value ReloadPowershell
39+
40+
# Get current PowerShell version
41+
${function:version} = { $PSVersionTable.PSVersion }
42+
43+
# Get installed PowerShell modules
44+
${function:modules} = { Get-Module -ListAvailable }
45+
46+
# Ensure `thefuck` is installed
47+
if (which thefuck){
48+
# Correct the previous command using `thefuck`
49+
$env:PYTHONIOENCODING="utf-8"
50+
Invoke-Expression "$(thefuck --alias)"
51+
# Unset PYTHONIOENCODING environment variable
52+
Remove-Item env:PYTHONIOENCODING
53+
}
54+
55+
# ------------------------------------------------------------------------------------------------------- #
56+
57+
# System Utility Aliases
58+
# ======================
59+
60+
# System Information
61+
${function:neofetch} = { bash C:\bin\neofetch\neofetch }
62+
63+
# Shutdown System
64+
${function:shutdown} = { Stop-Computer -ComputerName localhost }
65+
Set-Alias -Name shut -Value shutdown
66+
67+
# Restart System
68+
${function:restart} = { Restart-Computer }
69+
Set-Alias -Name reboot -Value restart
70+
71+
# Create a new directory and enter it
72+
Set-Alias -Name mkd -Value CreateAndSetDirectory
73+
74+
# Remove a given item
75+
Set-Alias -Name del -Value RemoveItem -option AllScope -Force
76+
77+
# Send an item to the Recycle Bin
78+
Set-Alias -Name trash -Value Remove-ItemSafely
79+
80+
# Empty the Recycle Bin on all drives
81+
Set-Alias -Name emptytrash -Value EmptyRecycleBin
82+
83+
# Cleanup old files all drives
84+
Set-Alias -Name cleandisks -Value CleanDisks
85+
86+
# Reload the shell
87+
Set-Alias -Name reload -Value ReloadPowershell
88+
89+
# Update installed Ruby Gems, NPM, and their installed packages.
90+
# Set-Alias -Name update -Value SystemUpdate
91+
92+
# Set neovim as default vim
93+
Set-Alias -Name vim -Value nvim
94+
95+
# ------------------------------------------------------------------------------------------------------- #
96+
97+
# Unix-like Aliases
98+
# =================
99+
100+
# Git-bash shell
101+
Set-Alias -Name bash -Value "C:\Program Files\Git\bin\bash.exe"
102+
103+
# Directory Listing: Use `lsd.exe` if available
104+
if (which lsd) {
105+
# List directory contents in short format
106+
${function:l} = { Write-Host ""; lsd --color always --icon always @args }
107+
# List directory contents
108+
${function:ll} = { Write-Host ""; lsd -A1 --color always --icon always @args }
109+
# List directory contents in long format
110+
${function:lll} = { Write-Host ""; lsd -al --color always --icon always @args }
111+
# List directory tree
112+
${function:lst} = { Write-Host ""; lsd --tree --color always --icon always --ignore-glob "node_modules" @args }
113+
} else {
114+
${function:l} = { Get-ChildItem }
115+
${function:ll} = { Get-ChildItem | Format-Wide }
116+
${function:lll} = { Get-ChildItem | Format-List }
117+
${function:lst} = { tree }
118+
}
119+
Set-Alias -Name ls -Value ll -option AllScope -Force
120+
121+
# Favour ripgrep over grep if installed
122+
if (Get-Command rg -ErrorAction SilentlyContinue) { Set-Alias -Name grep -Value rg }
123+
124+
# Measure the time taken for a command to execute
125+
Set-Alias -Name time -Value Measure-Command
126+
127+
# --------------------------------------------------------------------------------------------- #
128+
129+
# Git & GitHub Aliases
130+
# ====================
131+
132+
# Git clone and cd
133+
Set-Alias -Name gcd -Value Invoke-GitClone
134+
135+
# ls with git status
136+
${function:lsg} = { Write-Host ""; bash C:\bin\ls-with-git-status\lsg }
137+
# Set-Alias -Name ls -Value lsg -option AllScope -Force
138+
139+
# Git branch status
140+
${function:gbs} = { Write-Host ""; bash C:\bin\git-branch-status\git-branch-status -l }
141+
142+
# Git Multi Status
143+
${function:mgs} = { bash C:\bin\multi-git-status\mgitstatus --depth=0 }
144+
145+
# Favour GitHub's hub client over vanilla git
146+
if (Get-Command hub -ErrorAction SilentlyContinue) { Set-Alias -Name git -Value hub }
147+
148+
# --------------------------------------------------------------------------------------------- #
149+
150+
# EOF #

pwsh/bootstrap.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# ------------- #
2+
# bootstrap.ps1 #
3+
# ------------- #
4+
5+
# TODO: Check current powershell version and reload shell
6+
7+
$profileDir = Split-Path -parent $profile
8+
$componentDir = Join-Path $profileDir "components"
9+
10+
New-Item $profileDir -ItemType Directory -Force -ErrorAction SilentlyContinue
11+
New-Item $componentDir -ItemType Directory -Force -ErrorAction SilentlyContinue
12+
13+
# ? TODO: Exclude windows.ps1
14+
Copy-Item -Path ./*.ps1 -Destination $profileDir -Exclude "bootstrap.ps1"
15+
Copy-Item -Path ./components/** -Destination $componentDir -Include **
16+
17+
Remove-Variable componentDir
18+
Remove-Variable profileDir
19+
20+
# Open a New Shell
21+
# Invoke-Expression "powershell -NoLogo"
22+
# Invoke-Expression "pwsh"
23+
24+
exit
25+
26+
# EOF #

pwsh/components-shell.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -------------------- #
2+
# components-shell.ps1 #
3+
# -------------------- #
4+
5+
# These components will be loaded when running Microsoft.Powershell
6+
7+
# Write-Output "components-shell.ps1"
8+
9+
Push-Location (Join-Path (Split-Path -parent $profile) "components")
10+
11+
# From within the ./components directory...
12+
. .\console.ps1
13+
14+
Pop-Location
15+
16+
# EOF #

pwsh/components.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -------------- #
2+
# components.ps1 #
3+
# -------------- #
4+
5+
# These components will be loaded for all PowerShell instances
6+
7+
# TODO: Add rustup component
8+
9+
# Write-Output "components.ps1"
10+
11+
Push-Location (Join-Path (Split-Path -parent $profile) "components")
12+
13+
# From within the ./components directory...
14+
# . .\cargo.ps1
15+
# . .\dotnet.ps1
16+
. .\choco.ps1
17+
. .\git.ps1
18+
. .\npm.ps1
19+
. .\scoop.ps1
20+
. .\yarn.ps1
21+
22+
Pop-Location
23+
24+
# EOF #

pwsh/components/cargo.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -------------------- #
2+
# components/cargo.ps1 #
3+
# -------------------- #
4+
5+
# Write-Output "components/cargo.ps1"
6+
7+
if ((Get-Command cargo -ErrorAction SilentlyContinue) -and (Get-Module -ListAvailable posh-cargo -ErrorAction SilentlyContinue)) {
8+
Import-Module -Name posh-cargo
9+
}
10+
11+
# EOF #

pwsh/components/choco.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -------------------- #
2+
# components/choco.ps1 #
3+
# -------------------- #
4+
5+
# Write-Output "components/choco.ps1"
6+
7+
# Chocolatey Profile
8+
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
9+
if (Test-Path($ChocolateyProfile)) {
10+
Import-Module "$ChocolateyProfile" -Force
11+
}
12+
13+
# Import-Module “$env:ChocolateyInstall\helpers\chocolateyProfile.psm1” -Force
14+
15+
# EOF #

0 commit comments

Comments
 (0)