scoop-search-multisource icon indicating copy to clipboard operation
scoop-search-multisource copied to clipboard

hook help

Open Suyu6 opened this issue 1 year ago • 1 comments

New-Item -Path "$HOME\Documents" -Name "profile.ps1" -ItemType "file" -Value "Invoke-Expression (&scoop-search-multisource --hook)" I use this command but don't know where the problem is and can't hook

Suyu6 avatar May 26 '23 06:05 Suyu6

From where did you get that code?

That command creates a new file $HOME\Documents\profile.ps1 with the hook code, but that is a non-standard $Profile path and Powershell only loads a few specific $Profile paths automatically.

You can list those paths in this way:

PS C:\> $profile | select *

AllUsersAllHosts       : C:\Program Files\PowerShell\7\profile.ps1
AllUsersCurrentHost    : C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts    : C:\Users\user3\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\user3\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Length                 : 68

So, you can either manually edit one of those profiles OR execute something like this to append the hook to the $Profile file (which defaults to CurrentUserCurrentHost):

"`r`nInvoke-Expression (&scoop-search-multisource --hook)" | Out-File -Append -FilePath $Profile

That blindly appends to the profile, so executing that command more than once will create duplicate lines.

Personally, I don't use the hook much. Instead, I just use the executable alias scoops for searching:

scoops my-search-term

plicit avatar May 26 '23 16:05 plicit