Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing aliases with their full proper names #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions sudo.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Set-StrictMode -Off;

if(!$args) { "usage: sudo <cmd...>"; exit 1 }
if (-not $args) { "usage: sudo <cmd...>"; exit 1 }

$powershellExe = Get-Process -Id $pid | Select-Object -ExpandProperty Path
$commandPrefix = ''
if ($host.Version.Major -gt 5) {
$commandPrefix = '-Command'
$commandPrefix = '-Command'
}

function is_admin {
return ([System.Security.Principal.WindowsIdentity]::GetCurrent().UserClaims | ? { $_.Value -eq 'S-1-5-32-544'})
return ([System.Security.Principal.WindowsIdentity]::GetCurrent().UserClaims | Where-Object { $_.Value -eq 'S-1-5-32-544' })
}

function sudo_do($parent_pid, $dir, $cmd) {
Expand Down Expand Up @@ -38,21 +38,21 @@ function sudo_do($parent_pid, $dir, $cmd) {
}

function serialize($a, $escape) {
if($a -is [string] -and $a -match '\s') { return "'$a'" }
if($a -is [array]) {
return $a | % { (serialize $_ $escape) -join ', ' }
if ($a -is [string] -and $a -match '\s') { return "'$a'" }
if ($a -is [array]) {
return $a | ForEach-Object { (serialize $_ $escape) -join ', ' }
}
if($escape) { return $a -replace '[>&]', '`$0' }
if ($escape) { return $a -replace '[>&]', '`$0' }
return $a
}

if($args[0] -eq '-do') {
if ($args[0] -eq '-do') {
$null, $dir, $parent_pid, $cmd = $args
$exit_code = sudo_do $parent_pid $dir (serialize $cmd)
exit $exit_code
}

if(!(is_admin)) {
if (-not (is_admin)) {
[console]::error.writeline("sudo: you must be an administrator to run sudo")
exit 1
}
Expand Down