From 7415aa154370219531a7b82ab04e23aed5d40d91 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Tue, 21 Jan 2020 15:03:41 +0100 Subject: [PATCH] Check in! --- Install.ps1 | 11 ++++++++++ LICENSE | 13 ++++++++++++ Load.ps1 | 11 ++++++++++ README.md | 46 ++++++++++++++++++++++++++++++++++++++++++ Vars.ps1 | 5 +++++ install/git.ps1 | 4 ++++ install/ls-colors.ps1 | 1 + install/oh-my-posh.ps1 | 3 +++ install/pscx.ps1 | 1 + mods/ls-colors.ps1 | 1 + mods/posh-git.ps1 | 1 + mods/pscx.ps1 | 3 +++ mods/readline.ps1 | 27 +++++++++++++++++++++++++ scripts/time.ps1 | 3 +++ 14 files changed, 130 insertions(+) create mode 100644 Install.ps1 create mode 100644 LICENSE create mode 100644 Load.ps1 create mode 100644 README.md create mode 100644 Vars.ps1 create mode 100644 install/git.ps1 create mode 100644 install/ls-colors.ps1 create mode 100644 install/oh-my-posh.ps1 create mode 100644 install/pscx.ps1 create mode 100644 mods/ls-colors.ps1 create mode 100644 mods/posh-git.ps1 create mode 100644 mods/pscx.ps1 create mode 100644 mods/readline.ps1 create mode 100644 scripts/time.ps1 diff --git a/Install.ps1 b/Install.ps1 new file mode 100644 index 0000000..5b4c7bd --- /dev/null +++ b/Install.ps1 @@ -0,0 +1,11 @@ +# Run all scripts in the install folder +$list = @() +Get-ChildItem -Path install -Filter:*.ps1 -EA:Ignore | ForEach-Object { + $list += $_.BaseName + . $_.FullName +} +Write-Output "Installed: [$($list -join "] [")]" + +# Add to profile +$loadscript = Join-Path (Get-Location) "Load.ps1" +". $loadscript" | Add-Content -Path $Profile -Encoding UTF8 \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..86f76f9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright (c) 2020, Gatti Alessandro + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file diff --git a/Load.ps1 b/Load.ps1 new file mode 100644 index 0000000..346e179 --- /dev/null +++ b/Load.ps1 @@ -0,0 +1,11 @@ +$list = @() +Get-ChildItem -Path (Join-Path $PSScriptRoot mods) -Filter:*.ps1 -EA:Ignore | ForEach-Object { + $list += $_.BaseName + . $_.FullName +} + +Write-Output "Loaded: [$($list -join "] [")]" + +$Env:PATH += [System.IO.Path]::PathSeparator + "$(Join-Path $PSScriptRoot scripts)" + +. (Join-Path $PSScriptRoot Vars.ps1) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7cf1c30 --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +# The MPGA profile + +Make Powershell Great Again! + +This project will install and load the following mods + +- [posh-git](htts://github.com/dahlbyk/posh-git) (Git extensions) +- [oh-my-posh](https://github.com/JanDeDobbeleer/oh-my-posh) (Theming) +- [Pscx](https://github.com/Pscx/Pscx) (Community extensions) +- [Get-ChildItemColor](https://github.com/joonro/Get-ChildItemColor) (Colored ls/gci) + +and apply some changes: + +- Zsh-like Tab auto-complete (with menus) +- Better CTRL word navigation + +Some scripts are also included: + +- `time.ps1` Returns execution time of the last command + +## Getting started + +### Requirements + +- Powershell v6+ + +### Installation + +Clone or extract somewhere, maybe inside your profile dir? +Where's your profile? Check `$Profile` in powershell. + +Install all modules by running `Install.ps1`. No administrator shell required, everything is installed in the user context! + +Close and reopen the shell and you should be done! + +## Customization + +`Vars.ps1` contains some extra options you might want to change. Or just add more stuff there (or better yet, in your `$profile`). + +If you don't want a particular module, just delete the file off the `install` and `mods` folder. Then it will not be installed/loaded! + +The `scripts` folder is added to the `PATH` during load, you can add/remove scripts there and they will be in `PATH` but only when using this profile! + +## License + +Everything is released under ISC (see `LICENSE`). diff --git a/Vars.ps1 b/Vars.ps1 new file mode 100644 index 0000000..89e61fd --- /dev/null +++ b/Vars.ps1 @@ -0,0 +1,5 @@ +# Set oh-my-posh theme +# +# See https://github.com/JanDeDobbeleer/oh-my-posh#themes +# for other themes and extra options +Set-Theme Robbyrussell \ No newline at end of file diff --git a/install/git.ps1 b/install/git.ps1 new file mode 100644 index 0000000..7094c19 --- /dev/null +++ b/install/git.ps1 @@ -0,0 +1,4 @@ +# Install and add posh-git to profile +PowerShellGet\Install-Module posh-git -Scope CurrentUser -Force +Import-Module posh-git +Add-PoshGitToProfile \ No newline at end of file diff --git a/install/ls-colors.ps1 b/install/ls-colors.ps1 new file mode 100644 index 0000000..17ef804 --- /dev/null +++ b/install/ls-colors.ps1 @@ -0,0 +1 @@ +Install-Module -Scope CurrentUser -AllowClobber Get-ChildItemColor \ No newline at end of file diff --git a/install/oh-my-posh.ps1 b/install/oh-my-posh.ps1 new file mode 100644 index 0000000..05fcd66 --- /dev/null +++ b/install/oh-my-posh.ps1 @@ -0,0 +1,3 @@ +Install-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck +Install-Module posh-git -Scope CurrentUser +Install-Module oh-my-posh -Scope CurrentUser \ No newline at end of file diff --git a/install/pscx.ps1 b/install/pscx.ps1 new file mode 100644 index 0000000..dba0d30 --- /dev/null +++ b/install/pscx.ps1 @@ -0,0 +1 @@ +Install-Module Pscx -Scope CurrentUser \ No newline at end of file diff --git a/mods/ls-colors.ps1 b/mods/ls-colors.ps1 new file mode 100644 index 0000000..a61dad9 --- /dev/null +++ b/mods/ls-colors.ps1 @@ -0,0 +1 @@ +Import-Module Get-ChildItemColor \ No newline at end of file diff --git a/mods/posh-git.ps1 b/mods/posh-git.ps1 new file mode 100644 index 0000000..611bf0f --- /dev/null +++ b/mods/posh-git.ps1 @@ -0,0 +1 @@ +Import-Module posh-git \ No newline at end of file diff --git a/mods/pscx.ps1 b/mods/pscx.ps1 new file mode 100644 index 0000000..acac1c7 --- /dev/null +++ b/mods/pscx.ps1 @@ -0,0 +1,3 @@ +Import-Module Pscx -arg (Join-Path (Split-Path $Profile) Pscx.UserPreferences.ps1) -EA Ignore + +New-Alias -name vs -Value Import-VisualStudioVars diff --git a/mods/readline.ps1 b/mods/readline.ps1 new file mode 100644 index 0000000..2ad2b34 --- /dev/null +++ b/mods/readline.ps1 @@ -0,0 +1,27 @@ +# Set better CTRL bindings +Set-PSReadlineOption -EditMode Emacs +Set-PSReadlineKeyHandler "Ctrl+Delete" KillWord +Set-PSReadlineKeyHandler "Ctrl+Backspace" BackwardKillWord +Set-PSReadlineKeyHandler "Ctrl+LeftArrow" BackwardWord +Set-PSReadlineKeyHandler "Ctrl+RightArrow" NextWord + +# Set the autocomplete handler to a menu one, similar to how ZSH does it +Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete + +# Work around an RS5/PSReadline-2.0.0+beta2 bug (Spacebar is not marked Vital) +Set-PSReadlineKeyHandler "Shift+SpaceBar" -ScriptBlock { + [Microsoft.Powershell.PSConsoleReadLine]::Insert(' ') +} + +# Syntax highlighting! +If ($PSEdition -eq "Core") { + Set-PSReadlineOption -Colors @{ + Type = "`e[38;5;85m"; + String = "`e[38;5;130m"; + Number = "`e[38;5;220m"; + Variable = "`e[38;5;191m"; + Command = "`e[38;5;117m"; + Operator = "`e[38;5;213m"; + Parameter = "`e[38;5;239m"; + } +} diff --git a/scripts/time.ps1 b/scripts/time.ps1 new file mode 100644 index 0000000..6ade647 --- /dev/null +++ b/scripts/time.ps1 @@ -0,0 +1,3 @@ +$command = Get-History -Count 1 +$delta = $command.EndExecutionTime - $command.StartExecutionTime +Write-Output "Last command took $($delta.TotalMilliseconds) ms ($($delta.Days)d $($delta.Hours)h $($delta.Minutes)m $($delta.Seconds)s $($delta.Milliseconds)ms)" \ No newline at end of file