1
0
Fork 0
linux-conf/install.ps1

71 lines
2.3 KiB
PowerShell
Raw Normal View History

2021-10-28 20:23:27 +02:00
# Check if powershell is start as Admin otherwise runAs Admin
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$script = (Get-Location).Path + "\install.ps1"
Start-Process pwsh -Verb runAs "$script"
Break
}
# Install OhMyPosh
2021-10-27 21:37:29 +02:00
winget list -q JanDeDobbeleer.OhMyPosh
if ($? -eq $False) {
winget install JanDeDobbeleer.OhMyPosh
}
# Reload path
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
# Install modules
2021-10-27 21:37:29 +02:00
if (-not (Get-Module -ListAvailable -Name Terminal-Icons)) {
Install-Module -Name Terminal-Icons -Repository PSGallery -Force
}
if (-not (Get-Module -ListAvailable -Name PSReadLine)) {
Install-Module -Name PSReadLine -AllowPrerelease -Force
}
# Update profile configuration
# 1. Import all required params
$powershellConfig = (Get-Location).Path + "\configs\powershell\phmyposh.json"
Write-Output @'
function Reload-Path {
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
}
Reload-Path
'@ | Out-File -FilePath $PROFILE
Write-Output 'Import-Module -Name Terminal-Icons' | Out-File -FilePath $PROFILE -Append
Write-Output @'
if ($host.Name -eq 'ConsoleHost')
{
Import-Module -Name PSReadLine
}
'@ | Out-File -FilePath $PROFILE -Append
Write-Output "oh-my-posh --init --shell pwsh --config '$powershellConfig' | Invoke-Expression" | Out-File -FilePath $PROFILE -Append
# 2. Configure PSReadLine | Predictive Intellisense
2021-10-27 21:37:29 +02:00
Write-Output @'
$PSReadLineOptions = @{
EditMode = "Windows"
HistoryNoDuplicates = $True
2021-10-28 20:23:27 +02:00
PredictionViewStyle = "ListView"
2021-10-27 21:37:29 +02:00
PredictionSource = "History"
CompletionQueryItems = 5
ShowToolTips = $True
}
Set-PSReadLineOption @PSReadLineOptions
'@ | Out-File -FilePath $PROFILE -Append
# Reload profile
2021-10-27 22:07:57 +02:00
. $PROFILE
# Configure WSL
Get-Command wsl
if ($? -eq $True) {
$linuxWindowsConfPath = (Get-Location).Path.Replace('C:', '/mnt/c').Replace('\', '/')
$linuxHomeConfPath = "/home/$(wsl -e 'whoami')/myconf"
bash -c "ln -s $linuxWindowsConfPath $linuxHomeConfPath"
bash -c "$linuxHomeConfPath/install.sh"
} else {
Write-Output 'WSL is not installed. Ignore...'
}