|
| 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 # |
0 commit comments