Skip to content

Instantly share code, notes, and snippets.

@Bodix
Last active July 19, 2022 23:25
Show Gist options
  • Save Bodix/93ada16f6c5f6e7f750e9d1fc75a0313 to your computer and use it in GitHub Desktop.
Save Bodix/93ada16f6c5f6e7f750e9d1fc75a0313 to your computer and use it in GitHub Desktop.
PowerShell profile

Install (auto)

  1. Launch install.bat as Administrator.

Install (manual)

  1. Add profile.ps1 to %USERPROFILE%\Documents\WindowsPowerShell folder.

  2. Open PowerShell and enter the following commands:

    Install-Module posh-git
    Set-ExecutionPolicy Unrestricted
    Unblock-File ~\Documents\WindowsPowerShell\profile.ps1
    

Modules

@echo off
xcopy "%~dp0profile.ps1" "%userprofile%\Documents\WindowsPowerShell\profile.ps1*"
powershell -ExecutionPolicy Bypass -File "%~dp0setup.ps1"
echo "Completed"
pause
Import-Module posh-git
Set-Alias g git
Set-Alias go Search-Google
Set-Alias t-ru Open-Translator-To-Ru
Set-Alias t-en Open-Translator-To-En
Set-Alias en Translate-To-En
Set-Alias ru Translate-To-Ru
Set-Alias e Open-Current-Folder
Set-Alias c Open-VSCode
Set-Alias g-config Open-Git-Config
function Open-Current-Folder { explorer . }
function Open-VSCode { code . }
function Open-Git-Config { Invoke-Item ~\.gitconfig }
function Open-Url([string] $url) { Start-Process $url }
function Open-Website([string] $website) { Open-Url "https://$website" }
function Search-Google { Open-Website "google.com/search?q=$([uri]::EscapeDataString([string]::Join(' ', $args)))" }
function Open-Translator([string] $toLanguage) { Open-Website "translate.google.com/#en/$toLanguage/$([uri]::EscapeDataString([string]::Join(' ', $args)))" }
function Open-Translator-To-Ru { Open-Translator "ru" @args }
function Open-Translator-To-En { Open-Translator "en" @args }
function Translate([string] $toLanguage) {
$URL = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=$toLanguage&dt=t&q=$([uri]::EscapeDataString([string]::Join(' ', $args)))"
$WebClient = New-Object System.Net.WebClient
$WebClient.Encoding = [System.Text.Encoding]::UTF8
$WebClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
$Result = $WebClient.DownloadString($url)
Write-Host ($Result | ConvertFrom-Json)[0][0][0]
}
function Translate-To-Ru { Translate "ru" @args }
function Translate-To-En { Translate "en" @args }
Install-Module posh-git
try {
Set-ExecutionPolicy -Scope CurrentUser Unrestricted
}
catch {
}
Unblock-File ~\Documents\WindowsPowerShell\profile.ps1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment