Moeologist / scoop-completion

scoop tab completion, work with powershell
MIT License
172 stars 12 forks source link

My computer didn't have the path and file “C:\Users\younger\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1” #12

Closed younger-1 closed 4 years ago

younger-1 commented 4 years ago

All the things are right at first

PS C:\Users\younger> $env:SCOOP
C:\Users\younger\scoop
PS C:\Users\younger> $env:USERPROFILE
C:\Users\younger
PS C:\Users\younger> Import-Module "$env:SCOOP/modules/scoop-completion"

For enable completion in current shell it works

but it fails to enable auto-load

PS C:\Users\younger> Add-Content -Path $Profile -Value "`nImport-Module `"$env:SCOOP/modules/scoop-completion`""
Add-Content : 未能找到路径“C:\Users\younger\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1”的一部分。
所在位置 行:1 字符: 1
+ Add-Content -Path $Profile -Value "`nImport-Module `"$env:SCOOP/modul ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\younge...ell_profile.ps1:String) [Add-Content], DirectoryNotF
   oundException
    + FullyQualifiedErrorId : GetContentWriterDirectoryNotFoundError,Microsoft.PowerShell.Commands.AddContentCommand

I didn't find the path and the file in my computer,so I think it may be PowerShell' config, but I don't know why

Moeologist commented 4 years ago

exec

New-Item -Path $profile -ItemType "file" -Force

before Add-Content

younger-1 commented 4 years ago

exec

New-Item -Path $profile -ItemType "file" -Force

before Add-Content

Thanks.

Cry0nicS commented 4 years ago

@Moeologist please add the force commend to the homepage too.

Moeologist commented 4 years ago

@Cry0nicS Thank you for the advice.I will do it.

Lockszmith-GH commented 4 years ago

I would recommend instead of using $profile use $profile.CurrentUserAllHosts, this way it will be available not only in the Windows supplied console, but in ISE and any other PowerShell host (think vscode, etc..). If you want it machine wide, and not just for the current user, use $profile.AllUserAllHosts

Moeologist commented 4 years ago

Thx, I will add this to README.

younger-1 commented 4 years ago

I would recommend instead of using $profile use $profile.CurrentUserAllHosts, this way it will be available not only in the Windows supplied console, but in ISE and any other PowerShell host (think vscode, etc..). If you want it machine wide, and not just for the current user, use $profile.AllUserAllHosts

Using $profile setting only, it can still work in powershell of VScode, cmder and winTerminal etc... But not working in ISE. So I don't know what's more the setting you said above can do. Maybe I am misunderstanding...