Skip to content

Commit 0eec84a

Browse files
committed
fix: trying to fix msmt for it to run in Admin.
1 parent 7c0808d commit 0eec84a

File tree

3 files changed

+59
-66
lines changed

3 files changed

+59
-66
lines changed

CLI-Basic.psm1

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ function omniSearchObsidian {
1818
Start-Process "obsidian://omnisearch?query=$query" &
1919
}
2020

21-
function vr() {
22-
$dashArgs = ($args | Where-Object { $_ -like '-*' }) -join " "
23-
$rgArgs = ($args | Where-Object { $_ -notlike '-*' }) -join " "
24-
$command = "ig $dashArgs `"$rgArgs`""
25-
Invoke-Expression $command
26-
}
21+
# function ig() {
22+
# $dashArgs = ($args | Where-Object { $_ -like '-*' }) -join " "
23+
# $rgArgs = ($args | Where-Object { $_ -notlike '-*' }) -join " "
24+
# $command = "ig $dashArgs `"$rgArgs`""
25+
# Invoke-Expression $command
26+
# }
2727

2828
function rgj() {
2929
$dashArgs = ($args | Where-Object { $_ -like '-*' }) -join " "
3030
$rgArgs = ($args | Where-Object { $_ -notlike '-*' }) -join " "
3131
$command = "rg `"$rgArgs`" -g '*Journal.md' (zoxide query obs) -M 400 -A3 $dashArgs"
3232
Invoke-Expression $command
33-
# [`$?` variable](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.4#section-1)
33+
3434
if ($? -eq $false) {
3535
Write-Host "not in those journal.md" -ForegroundColor Magenta
3636
rg "$($args -join " ")" -g !'*Journal.md' (zoxide query obs) -M 400
@@ -53,37 +53,46 @@ function rgo() {
5353
}
5454

5555
# HACK: rg in vault's other files.
56-
function vro() {
56+
function igo() {
5757
$dashArgs = ($args | Where-Object { $_ -like '-*' }) -join " "
5858
$rgArgs = ($args | Where-Object { $_ -notlike '-*' }) -join " "
5959
$command = "ig `"$rgArgs`" -g !'*Journal.md' (zoxide query obs) $dashArgs"
6060
Invoke-Expression $command
6161
}
6262

63-
function vrj() {
63+
function igj() {
6464
$dashArgs = ($args | Where-Object { $_ -like '-*' }) -join " "
6565
$rgArgs = ($args | Where-Object { $_ -notlike '-*' }) -join " "
6666
$command = "ig `"$rgArgs`" -g '*Journal.md' (zoxide query obs) $dashArgs"
6767
Invoke-Expression $command
6868
}
6969

7070
# INFO: yazi quick call.
71-
function yy {
71+
function y {
7272
$tmp = [System.IO.Path]::GetTempFileName()
7373
yazi $args --cwd-file="$tmp"
74-
$cwd = Get-Content -Path $tmp
74+
$cwd = Get-Content -Path $tmp -Encoding UTF8
7575
if (-not [String]::IsNullOrEmpty($cwd) -and $cwd -ne $PWD.Path) {
76-
Set-Location -Path $cwd
76+
Set-Location -LiteralPath ([System.IO.Path]::GetFullPath($cwd))
7777
}
7878
Remove-Item -Path $tmp
7979
}
80-
Set-Alias -Name zz -Value yy
80+
Set-Alias -Name zz -Value y
8181

82+
function Invoke-SudoPwsh {
83+
sudo --inline pwsh -Command "$args"
84+
}
8285
# INFO: mousemaster or something related to mouse controlling
8386
function Invoke-KeyMouse {
84-
Stop-Process -Name mousemaster*
85-
( Start-Sleep -Seconds 2 && mousemaster --configuration-file="$env:usrbinD\mousemaster.properties") &
86-
}
87+
Invoke-SudoPwsh "Stop-Process -Name mousemaster*"
88+
Start-Sleep -Seconds 1
89+
Set-LocationWhere mousemaster
90+
sudo run mousemaster &
91+
}
92+
# function Invoke-KeyMouse {
93+
# Stop-Process -Name mousemaster*
94+
# ( Start-Sleep -Seconds 2 && mousemaster --configuration-file="$env:usrbinD\mousemaster.properties") &
95+
# }
8796
Set-Alias -Name msmt -Value Invoke-KeyMouse
8897

8998
function Get-PathFromFiles() {
@@ -194,3 +203,6 @@ function tree() {
194203
exa --hyperlink -T -L=2 $args
195204
Write-Host "depth flags : -L=2" -ForegroundColor Green
196205
}
206+
207+
208+

quickGitAction.psm1

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,4 @@ function gitCloneClipboard($finalDir = $null, $url = (Get-Clipboard))
4949
}
5050
Set-Alias -Name gccb -Value gitCloneClipboard
5151

52-
53-
function copyFilesFromOnlineRepos($URI = "", $gitDoc = "" , $OutFile = "") {
54-
if ($URI -eq "") {
55-
$processedURI = [URI](Get-Clipboard)
56-
}
57-
else {
58-
$processedURI = [URI]$URI
59-
}
60-
if ($gitDoc -eq "") {
61-
$finalName = $processedURI.Segments[-1]
62-
}
63-
else {
64-
$finalName = $gitDoc
65-
}
66-
if ($OutFile -eq "") {
67-
$destinationFile = $finalName
68-
}
69-
else {
70-
$destinationFile = $OutFile
71-
}
72-
Invoke-WebRequest -Uri $processedURI -OutFile ./$destinationFile && bat ./$destinationFile
73-
}
74-
Set-Alias -Name cpGit -Value copyFilesFromOnlineRepos -Scope Global
52+
Set-Alias -Name gui -Value gitui

quickPSReadLine.psm1

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ $VaultSearchParameters = @{
4141
# WARN: First time I used ScriptBlock
4242
$process_string = {
4343
param($line)
44-
$matchesSearchFunction = "rgj|rgo"
44+
$matchesSearchFunction = "rgj|rgo|ig"
4545
if ($line -match "^($matchesSearchFunction)") {
4646
# TODO: further enhanced by adding different flag at this point.
4747
switch -Regex ($line) {
4848
"^(?!.*-w$)" { $SearchWithQuery = "$line -w"; break }
4949
"^rgj" { $SearchWithQuery = $line -replace "^rgj","rgo"; break }
5050
"^rgo" { $SearchWithQuery = $line -replace "-w$",""; break }
51+
"^igj" { $SearchWithQuery = $line -replace "^igj","ig"; break }
5152
}
5253
}
5354
else {
@@ -79,16 +80,22 @@ $quickZoxide = {
7980
$process_string = {
8081
param($line)
8182
$existedCd = "cd|z|zq"
82-
if ($line -match "^(${existedCd})i") {
83-
$SearchWithQuery = $line
84-
}
85-
elseif ($line -match "^($existedCd)") {
86-
$matchString = $Matches[0]
87-
$SearchWithQuery = $line -replace "${matchString}", "${matchString}i"
83+
switch -Regex ($line) {
84+
"^(${existedCd})i\s" {
85+
$matchString = $Matches[0]
86+
$SearchWithQuery = $line -replace "${matchString}", "zz "
87+
break;
88+
}
89+
"^(${existedCd})(\s|$)" {
90+
$matchString = $Matches[1]
91+
$SearchWithQuery = $line -replace "^${matchString}(\s|$)", "${matchString}i "
92+
break
93+
}
94+
default {
95+
$SearchWithQuery = "$searchFunction $line"
96+
break;
97+
}
8898
}
89-
else {
90-
$SearchWithQuery = "$searchFunction $line"
91-
}
9299
return $SearchWithQuery
93100
}
94101
if ($line -match "[a-z]") {
@@ -408,7 +415,7 @@ $openEditorParameters = @{
408415
$rgToNvimParameters = @{
409416
Key = 'Alt+v'
410417
BriefDescription = 'open `ig`'
411-
LongDescription = 'Invoke vr in place of rg.'
418+
LongDescription = 'Invoke ig in place of rg.'
412419
ScriptBlock = {
413420
param($key, $arg) # The arguments are ignored in this example
414421

@@ -420,7 +427,7 @@ $rgToNvimParameters = @{
420427
if ($line -match '^rg') {
421428
# INFO: Replace could actually increase the length of original strings.
422429
# So I could be longer than the start.
423-
[Microsoft.PowerShell.PSConsoleReadLine]::Replace(0, 2, "vr")
430+
[Microsoft.PowerShell.PSConsoleReadLine]::Replace(0, 2, "ig")
424431
}
425432
else {
426433
# INFO: check history for the latest match commands
@@ -430,7 +437,7 @@ $rgToNvimParameters = @{
430437
| Select-Object -Index 0 `
431438

432439
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($SearchWithQuery)
433-
[Microsoft.PowerShell.PSConsoleReadLine]::Replace(0, 2, "vr")
440+
[Microsoft.PowerShell.PSConsoleReadLine]::Replace(0, 2, "ig")
434441
}
435442
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
436443

@@ -450,30 +457,29 @@ $rgToRggParameters = @{
450457
$cursor = $null
451458
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line,
452459
[ref]$cursor)
453-
if ($line -match '^rg ') {
454-
# INFO: Replace could actually increase the length of original strings.
455-
# So I could be longer than the start.
456-
[Microsoft.PowerShell.PSConsoleReadLine]::Replace(0, 2, "rgr")
460+
$matchFunction = "rg|rgj"
461+
$injectSearch = {
462+
param($command)
463+
$command -match "^($matchFunction)\s"
464+
[Microsoft.PowerShell.PSConsoleReadLine]::Replace(0, $Matches[0].Length, "rgr ")
465+
}
466+
if ($line -match "^($matchFunction)") {
467+
$injectSearch.Invoke($line)
457468
}
458469
else {
459-
# INFO: check history for the latest match commands
460470
$SearchWithQuery = Get-History -Count 40 `
461471
| Sort-Object -Property Id -Descending `
462-
| Where-Object { $_.CommandLine -match "^rg " }
472+
| Where-Object { $_.CommandLine -match "^($matchFunction)" }
463473
| Select-Object -Index 0 `
464474

465475
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($SearchWithQuery)
466-
[Microsoft.PowerShell.PSConsoleReadLine]::Replace(0, 2, "rgr")
476+
$injectSearch.Invoke($SearchWithQuery)
467477
}
468478
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
469479

470480
}
471481
}
472482

473-
474-
475-
476-
477483
$quickEscParameters = @{
478484
Key = 'Ctrl+k'
479485
BriefDescription = 'Open Kicad'
@@ -493,9 +499,6 @@ $quickEscParameters = @{
493499
}
494500
}
495501

496-
function Invoke-SudoPwsh {
497-
sudo --inline pwsh -Command "$args"
498-
}
499502
$sudoRunParameters = @{
500503
Key = 'Ctrl+shift+x'
501504
BriefDescription = 'Execute as sudo (in pwsh).'

0 commit comments

Comments
 (0)