ChrisTitusTech / website

My HUGO Website that I use for Videos, Blogs, and Redirects
74 stars 44 forks source link

pretty-powershell/ #72

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Pretty Powershell

Having Fun with Technology

https://christitus.com/pretty-powershell/

REVENGE977 commented 1 year ago

the one link command is not using a raw link btw

jtjh commented 1 year ago

As @REVENGE977 stated earlier

Fixed: irm "https://raw.githubusercontent.com/ChrisTitusTech/powershell-profile/main/setup.ps1" | iex

TheyCallMeZ commented 1 year ago

Need to add Xargs (I forget where I got this from but it works great!)

function Xargs { param( $Cmd ) process { $args += ,$_ } end { & $Cmd @args } }

silverskymedia commented 1 year ago

After installing this, I now receive a ParserError

Line | 125 | if (( $+commands[nvim] )); then | ~ | Missing statement block after if ( condition ).

Nothing changes after installing this. I've installed the font, but it all looks the same. Thanks.

Velosofy commented 1 year ago

Test-CommandExists doesnt exist in my installation of Powershell v7.2.7

hiddengerbil commented 1 year ago

The one -click install gives me this antivirus response..

irm "https://github.com/ChrisTitusTech/powershell-profile/blob/main/setup.ps1" | iex

Suspicious activity blocked 2 minutes ago

Feature: Antivirus

PowerShell tried to load a malicious resource detected as Heur.BZC.ZFV.Boxter.341.1359F945 and was blocked. Your device is safe.

hiddengerbil commented 1 year ago

I turned off my antivirus to get this script to run. After it completed, I now get this PowerShell error

. : File C:\Users\virtualtom\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:3

johnmac78 commented 1 year ago

I get the following error when trying to install the program. Any suggestions?

iex : At line:198 char:17

Rishab6358 commented 1 year ago

having same issue as hiddengerbil it is showing me . : File C:\Users\Rishab\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:3

TheKeiki commented 1 year ago

Having this issue after install:


Set-Alias : Cannot bind the argument to the 'Value' parameter because it is null.
In F:__Documents_WindowsPowerShell__Microsoft.PowerShell_profile.ps1: 142 Character: 28
+ Set-Alias -Name vim -Value $EDITOR
+ ~~~~~~~
    + CategoryInfo : InvalidData: (:) [Set-Alias], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetAliasCom
   mand
PapaHawk14 commented 1 year ago

Having the same error.. as above.

Set-Alias : Cannot bind argument to parameter 'Value' because it is null.
At C:\Users\grant\OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:142 char:28
+ Set-Alias -Name vim -Value $EDITOR
+                            ~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Set-Alias], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetAliasCom
   mand
mendelsphotography commented 1 year ago

How Do I backup my current profile?

Velosofy commented 1 year ago

How Do I backup my current profile?

the script auto-backup current profile as oldprofile.ps1

Velosofy commented 1 year ago

@PapaHawk14 and @TheKeiki

That is because you don't have nvim/vim/pvim/vi installed If you don't intend to use any of those, just remove that part out from the profile

PapaHawk14 commented 1 year ago

Done - awesome….

On Tue, 1 Nov 2022 at 3:40 pm, Velosofy @.***> wrote:

@PapaHawk14 https://github.com/PapaHawk14 and @TheKeiki https://github.com/TheKeiki

That is because you don't have nvim/vim/pvim/vi installed If you don't intend to use any of those, just remove that part out from the profile

— Reply to this email directly, view it on GitHub https://github.com/ChrisTitusTech/website/issues/72#issuecomment-1298036856, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVHPCV7GAVENLEONQGA3L3DWGCQ2ZANCNFSM6AAAAAARTCTNQE . You are receiving this because you were mentioned.Message ID: @.***>

--

Grant Hawksworth Adelaide Sth Australia email: @.***

khurram-hassan commented 1 year ago

I also had some issues with the script execution which I resolved by doing this before executing the script above:

Set-ExecutionPolicy Bypass Process

OR

Set-ExecutionPolicy RemoteSigned

The script is working good and shows up perfectly on powershell but in Windows terminal some icons are missing. icons missing in the prompt

OS: Windows 10 Pro.

Velosofy commented 1 year ago

I also had some issues with the script execution which I resolved by doing this before executing the script above:

Set-ExecutionPolicy Bypass Process

OR

Set-ExecutionPolicy RemoteSigned

The script is working good and shows up perfectly on powershell but in Windows terminal some icons are missing. icons missing in the prompt

OS: Windows 10 Pro.

The template does indeed require a Set-ExecutionPolicy RemoteSigned

Are you sure you're using the right font?

khurram-hassan commented 1 year ago

Are you sure you're using the right font?

Yes, I am sure. As suggested in the article:

  1. I unzipped the cove.zip
  2. Installed all the 4 fonts present there
  3. and then made the default font for Windows Terminal as "Caskaydia Cove Nerd Font"

Windows Terminal settings

In powershell it is looking fine. prompt for powershell

Velosofy commented 1 year ago

Yes, I am sure.

Possible of the "Windows PowerShell" terminal profile overriding the "default" profile font?

khurram-hassan commented 1 year ago

Possible of the "Windows PowerShell" terminal profile overriding the "default" profile font?

You were right. I changed it as well and it worked.

Thanks

MoebiusTesla commented 1 year ago

I have the same issue as Khurram-hassan it seems. How do i override the default profile font?

Velosofy commented 1 year ago

I have the same issue as Khurram-hassan it seems. How do i override the default profile font?

Assuming we're talking Windows Terminal - By simply changing the font for the default profile, but seems like you need to change the font for powershell profile aswell

b3y0ndd34th commented 1 year ago

The following error can be removed from the profile.ps1 files. You should be able to find it in your My Documents\WindowsPowerShell folder called "Microsoft.PowerShell_profile.ps1" and "Microsoft.PowerShellISE_profile.ps1"

Edit the file and remove the following lines:

if (Test-CommandExists nvim) { $EDITOR='nvim' } elseif (Test-CommandExists pvim) { $EDITOR='pvim' } elseif (Test-CommandExists vim) { $EDITOR='vim' } elseif (Test-CommandExists vi) { $EDITOR='vi' } Set-Alias -Name vim -Value $EDITOR"

Save the file and now you can open Powershell and ISE without the error.

It does not seem to be assigning the correct value at the moment. I will look more into this later.

Error:

Set-Alias : Cannot bind argument to parameter 'Value' because it is null. At F:\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:142 char:28

  • Set-Alias -Name vim -Value $EDITOR
  • 
    + CategoryInfo          : InvalidData: (:) [Set-Alias], ParameterBindingValidationException
    + FullyQualifiedErrorId : >ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetAliasCom
    mand
CattopyTheWeb commented 1 year ago

I'm getting this error: Could not find a part of the path 'C:\Users\lukav\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'. At line:8 char:10

TheyCallMeZ commented 1 year ago

The following error can be removed from the profile.ps1 files. You should be able to find it in your My Documents\WindowsPowerShell folder called "Microsoft.PowerShell_profile.ps1" and "Microsoft.PowerShellISE_profile.ps1"

Edit the file and remove the following lines:

if (Test-CommandExists nvim) { $EDITOR='nvim' } elseif (Test-CommandExists pvim) { $EDITOR='pvim' } elseif (Test-CommandExists vim) { $EDITOR='vim' } elseif (Test-CommandExists vi) { $EDITOR='vi' } Set-Alias -Name vim -Value $EDITOR"

Save the file and now you can open Powershell and ISE without the error.

It does not seem to be assigning the correct value at the moment. I will look more into this later.

Error:

Set-Alias : Cannot bind argument to parameter 'Value' because it is null. At F:\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:142 char:28

  • Set-Alias -Name vim -Value $EDITOR
  •                      ~~~~~~~
    • CategoryInfo : InvalidData: (:) [Set-Alias], ParameterBindingValidationException
  • FullyQualifiedErrorId : >ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetAliasCom mand

The problem is none of these editors are installed on the machine or if they are installed they are not in the system's PATH variable.

You can absolutely remove this chunk of code and be fine, but if you wanted a "vim" alias for a quick file editor you can add elseif statements for things you do have installed and are in the path

Case in point

if (Test-CommandExists nvim) {
$EDITOR='nvim'
} elseif (Test-CommandExists pvim) {
$EDITOR='pvim'
} elseif (Test-CommandExists vim) {
$EDITOR='vim'
} elseif (Test-CommandExists vi) {
$EDITOR='vi'
} elseif (Test-CommandExists code) {
$EDITOR='code'
} elseif (Test-CommandExists notepad++) {
$EDITOR='notepad++'
} elseif (Test-CommandExists notepad) {
$EDITOR='notepad'
}
Set-Alias -Name vim -Value $EDITOR

doing notepad last as every machine has notepad.

bertman80 commented 1 year ago

I added the function gotodir. Simply go to the directory even if the parameter is a file.

gd $PROFILE

just add this to youre profile file.

go to a directory even in path is a file.

added 02-nov-2022

function gotodir($dir) { if ((get-item $dir -erroraction silentlycontinue ) -is [system.io.directoryinfo]) { cd $dir } else { cd (split-path -path $dir) } } set-alias -name gd -value gotodir <.sub>

bertman80 commented 1 year ago

Sorry for my previous post, I accidentally posted it too soon. I hoop you will delete it.

I added the function gotodir. Simply go to the directory even if the parameter is a file.

gd $PROFILE

just add this to youre profile file.

#go to a directory even in path is a file.
#added 02-nov-2022
function gotodir($dir) {
if ((get-item $dir -erroraction silentlycontinue ) -is [system.io.directoryinfo]) {
cd $dir
} else {
cd (split-path -path $dir)
}
}
set-alias -name gd -value gotodir
bertman80 commented 1 year ago

For all the EDITOR messages, just put this on line 133 just before the 'if (Test-CommandExists nvim) {' So the editor will be notepad if none of the other commands exist.

$EDITOR="notepad.exe"
CattopyTheWeb commented 1 year ago

I just fixed my error. Also can you do something with cmd too?

Helix70 commented 1 year ago

I get the following error:

Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS C:\Users\lexus> irm "https://github.com/ChrisTitusTech/powershell-profile/blob/main/setup.ps1" | iex
Invoke-Expression:
Line |
   1 |  … thub.com/ChrisTitusTech/powershell-profile/blob/main/setup.ps1" | iex
     |                                                                      ~~~
     | The '<' operator is reserved for future use.

PS C:\Users\lexus>

Any thoughts what I am doing wrong?

Velosofy commented 1 year ago

I get the following error:

Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS C:\Users\lexus> irm "https://github.com/ChrisTitusTech/powershell-profile/blob/main/setup.ps1" | iex
Invoke-Expression:
Line |
   1 |  … thub.com/ChrisTitusTech/powershell-profile/blob/main/setup.ps1" | iex
     |                                                                      ~~~
     | The '<' operator is reserved for future use.

PS C:\Users\lexus>

Any thoughts what I am doing wrong?

Try the script with the latest Powershell v7

numb699 commented 1 year ago

I get the same, Powershell 7.2.7

Velosofy commented 1 year ago

@numb699 @Helix70 Try with this command instead irm "https://github.com/ChrisTitusTech/powershell-profile/raw/main/setup.ps1" | iex

bertman80 commented 1 year ago

I get the same, Powershell 7.2.7

This should do the trick:

irm "https://raw.githubusercontent.com/ChrisTitusTech/powershell-profile/main/setup.ps1" | iex

AlexiRichardson commented 1 year ago

Hello, everything seems to work except oh-my-posh. It appears to have installed but I am getting these errors when attempting to run the extracted command directly since my color scheme is not like the one Chris demonstrated.

 system32  oh-my-posh --init --shell pwsh --config ~/jandedobbeleer.omp.json | Invoke-Expression Get-PSReadLineKeyHandler : A parameter cannot be found that matches parameter name 'Key'. At line:373 char:43

Get-PSReadLineKeyHandler : A parameter cannot be found that matches parameter name 'Key'. At line:376 char:43

AlexiRichardson commented 1 year ago

CORRECTION TO MY PRIOR COMMENT: Color scheme is set to One Half Dark in Terminal settings for Appearance for powershell. Not sure what the problem is with oh-my-posh with those errors. How do I know if oh-my-posh is working correctly? Thanks.

AlexiRichardson commented 1 year ago

Could be my PS version 5 is not compatible with those KeyHandler calls for params Enter and Spacebar. Maybe I have to be upgraded to 7 for these bindings to take.

eric-bixby commented 1 year ago

After installing PowerShell extension for vscode, the linter gives the following warning: "The cmdlet 'reload-profile' uses an unapproved verb."

AlexiRichardson commented 1 year ago

Anyone have any ideas what I can check for the problems Get-PSReadLineKeyHandler? I am getting the same errors when running the reload-profile function. Even when I try to reload my profile by doing . $PROFILE I am getting the same errors for KeyHandler read line; A parameter cannot be found that matches parameter name 'Key' , for both Enter and Spacebar.

AlexiRichardson commented 1 year ago

Solved by doing the following in Admin pwrsh:

Install-Module PowerShellGet -Force Update-Module PowerShellGet -Force Install-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck

Helix70 commented 1 year ago

@numb699 @Helix70 Try with this command instead irm "https://github.com/ChrisTitusTech/powershell-profile/raw/main/setup.ps1" | iex

Thanks numb699, already using 7.2.7 in Administrator mode, tried both commands, results below:

PowerShell 7.2.7
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS C:\Users\lexus> irm "https://github.com/ChrisTitusTech/powershell-profile/blob/main/setup.ps1" | iex
Invoke-Expression:
Line |
   1 |  … thub.com/ChrisTitusTech/powershell-profile/blob/main/setup.ps1" | iex
     |                                                                      ~~~
     | The '<' operator is reserved for future use.

PS C:\Users\lexus> irm "https://github.com/ChrisTitusTech/powershell-profile/raw/main/setup.ps1" | iex
Exception:
Line |
   8 |           throw $_.Exception.Message
     |           ~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Could not find a part of the path 'C:\Users\lexus\OneDrive\Documents\PowerShell\Microsoft.PowerShell_profile.ps1'.
PS C:\Users\lexus>
Helix70 commented 1 year ago

Ok, after creating the powershell directory under the Onedrive directory, the raw version of the command seems to have worked. Thanks.

numb699 commented 1 year ago

Yeah I tried both as well, getting same errors no matter where I run them.

eplyons commented 1 year ago

Thanks @jo20201 but I still get this error:

Cannot bind parameter 'NewerThan'. Cannot convert value "True" to type "System.DateTime". Error: "The string was not recognized as a valid DateTime. There is an unknown word starting at index 0." At line:19 char:10

sarathdm commented 1 year ago

Hi There... I have a problem running the script in powershell admin

Cannot bind parameter 'NewerThan'. Cannot convert value "True" to type "System.DateTime". Error: "The string was not recognized as a valid DateTime. There is an unknown word starting at index 0." At line:19 char:10

Does anyone know how to solve this?

Rishab6358 commented 1 year ago

having this error in another computer Cannot bind parameter 'NewerThan'. Cannot convert value "True" to type "System.DateTime". Error: "The string was not recognized as a valid DateTime. There is an unknown word starting at index 0." At line:19 char:10

th3jesta commented 1 year ago

Looking good except for these little artifacts. I suspect it's because I have Acrylic enabled in Terminal. What do you think? Weird artifacts

VeritasHurtz commented 1 year ago

Help please I have done everything and still cannot get the font to save, it's in the list of fonts but, I struggling to work out how I've gone wrong, I will admit to being a bit of a noob, with a hunger to learn. thanks in advance for any help pwsh help

ChrisTitusTech commented 1 year ago

@VeritasHurtz Reinstall the Caskaydia cove font but systemwide. Just right click the font and do it through the gui.

mariosp91 commented 1 year ago

@ChrisTitusTech how can i unistall your script?