-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicrosoft.PowerShell_profile.ps1
73 lines (64 loc) · 2.59 KB
/
Microsoft.PowerShell_profile.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# custom functions
function wga {
$command = "winget update --all"
Write-Output $command
Invoke-Expression $command
}
function conssh {
$command = "explorer $env:USERPROFILE\.ssh"
Write-Output $command
Invoke-Expression $command
}
function copyssh {
<#
.SYNOPSIS
Kopiert den SSH Public Key auf einen Remote-Server.
.DESCRIPTION
Diese Funktion kopiert den Public Key aus dem lokalen `.ssh`-Ordner in die `authorized_keys`-Datei eines Remote-Servers.
.PARAMETER user
Der Benutzername für die SSH-Verbindung.
.PARAMETER ip
Die IP-Adresse des Remote-Servers.
.EXAMPLE
copyssh -user username -ip 192.168.1.1
Kopiert den Public Key zu `[email protected]`.
.NOTES
Stellen Sie sicher, dass der SSH-Dienst auf dem Zielserver aktiv ist.
#>
param (
[Parameter(Mandatory=$true, HelpMessage="Geben Sie den Benutzernamen an.")]
[string]$user,
[Parameter(Mandatory=$true, HelpMessage="Geben Sie die IP-Adresse des Remote-Servers an.")]
[string]$ip
)
$command = "Get-Content `"$env:USERPROFILE\.ssh\id_rsa.pub`" | ssh $user@$ip 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys'"
Write-Output $command
Invoke-Expression $command
}
function posh {
$command = "oh-my-posh upgrade"
Write-Output $command
Invoke-Expression $command
}
function Invoke-AdminShell {
Invoke-Expression gsudo
}
function Invoke-LastCommandAsAdmin {
# Hole den letzten Befehl aus der Historie
$lastCommand = (Get-History | Select-Object -Last 1).CommandLine
# Starte eine neue PowerShell-Sitzung mit Admin-Rechten und führe den letzten Befehl aus
gsudo $lastCommand
}
# design
oh-my-posh init pwsh --config "C:\Users\BartholomaiK\AppData\Local\Programs\oh-my-posh\themes\montys.omp.json" | Invoke-Expression
[Console]::OutputEncoding = [Text.Encoding]::UTF8
# features
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()
$Local:word = $wordToComplete.Replace('"', '""')
$Local:ast = $commandAst.ToString().Replace('"', '""')
winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}