windows-powershell-profile/Microsoft.PowerShell_profile.ps1

132 lines
4.3 KiB
PowerShell
Raw Permalink Normal View History

# Set the Window Title of Windows Terminal to The filepath of current directory
2023-08-19 22:57:09 -04:00
$host.ui.rawui.windowtitle="$(Get-Item .) - Windows Terminal"
# powershell.exe -NoExit -command "& {Set-Location $env:systemroot}"
# @args you can pass multi arguments for example
# ga fileName1 fileName2
function gn{git init}
# @args is optional to add argument
function add{git add @args}
function commit {git commit -m @args }
2023-08-19 22:57:09 -04:00
function gac{git add .;git commit -m @args}
function gacc{git add .;git commit -m @args ; git push}
function gpm{git push origin master}
function pull{git pull}
2024-07-02 21:46:24 -04:00
function gp{git pull}
2023-08-19 22:57:09 -04:00
function gpp{git pull}
2024-07-02 21:46:24 -04:00
function gpm{git checkout main ; git pull}
2023-08-19 22:57:09 -04:00
function gl{git log}
function glo{git log --oneline}
function gch{git checkout @args}
function gb{git branch @args}
function gs{git status}
2024-07-02 21:46:24 -04:00
function gss{git status}
2023-08-19 22:57:09 -04:00
function gdd{git diff}
function gdf{git diff}
function gsi{git submodule init}
function gsu{git submodule update --recursive --remote}
2024-07-02 21:46:24 -04:00
function gr{ni README.md;nano README.md} # choco install nano -y to use nano
function gi{ni .gitignore; Add-Content -Path /.gitignore -Value '@args'} # choco install nano -y to use nano
2023-08-19 22:57:09 -04:00
# function gsu{git submodule update --recursive --remote}
# Open up files with specific program
function subl{Start-Process 'C:\Program Files\Sublime Text\sublime_text.exe' @args}
function gimp{Start-Process 'C:\Program Files\GIMP 2\bin\gimp-2.10.exe' @args}
2023-08-19 22:57:09 -04:00
# Useful shortcuts for traversing directories
function cd.. { Set-Location ..\.. }
function cd... { Set-Location ..\..\.. }
function gg { Set-Location $HOME\Syncthing\Git }
function ll { Get-ChildItem -Path $pwd -File }
# https://www.technewstoday.com/powershell-get-ip-address/
# get ip address
function ipa { Get-NetIPAddress | Where-Object {$_.AddressState -eq "Preferred" -and $_.ValidLifetime -lt "24:00:00"}}
# Chocolatey
#------------------------------------------------
2023-08-19 22:57:09 -04:00
# Import the Chocolatey Profile that contains the necessary code to enable
# tab-completions to function for `choco`.
# Be aware that if you are missing these lines from your profile, tab completion
# for `choco` will not function.
# See https://ch0.co/tab-completion for details.
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
# https://gist.github.com/yunga/99d04694e2466e017c5502d7c828d4f4
function cs{choco search @args}
function parus{choco search @args}
function ci{choco install -y @args}
function paru{choco install -y @args}
function cua{choco upgrade all -y}
# Misc
#------------------------------------------------
# Kill Process
function pkill($name) {
Get-Process $name -ErrorAction SilentlyContinue | Stop-Process
}
# https://www.educative.io/answers/what-is-the-powershell-equivalent-of-touch
function touch{ni @args}
2023-08-19 22:57:09 -04:00
# reload profile
# https://stackoverflow.com/questions/567650/how-to-reload-user-profile-from-script-file-in-powershell
function rl{. $profile ; Write-Host "Reloaded"}
# yt-dlp
function ytv{yt-dlp -f bestvideo*+bestaudio/best --embed-thumbnail --add-metadata --no-mtime --no-playlist -o "%(title)s.%(ext)s" @args}
function yta{yt-dlp -f bestaudio --extract-audio --embed-thumbnail --add-metadata --no-mtime --no-playlist -o "%(title)s.%(ext)s" @args}
# Compute file hashes
function md5 { Get-FileHash -Algorithm MD5 $args }
function sha1 { Get-FileHash -Algorithm SHA1 $args }
function sha256 { Get-FileHash -Algorithm SHA256 $args }
# Simple function to start a new elevated process. If arguments are supplied then
# a single command is started with admin rights; if not then a new admin instance
# of PowerShell is started.
function admin
{
if ($args.Count -gt 0)
{
$argList = "& '" + $args + "'"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $argList
}
else
{
Start-Process "$psHome\powershell.exe" -Verb runAs
}
}
# Set UNIX-like aliases for the admin command, so sudo <command> will run the command with elevated rights.
Set-Alias -Name sudo -Value admin
# Edit the Powershell Profile
function editps1
{
Start-Process 'C:\Program Files\Sublime Text\sublime_text.exe' ${profile}
}
# Get Uptime
function uptime {
Get-WmiObject win32_operatingsystem | Select-Object csname, @{LABEL='LastBootUpTime';
EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
}