From a4cfd46422840d4c532cd00f122a2691f2e25695 Mon Sep 17 00:00:00 2001 From: Anthony Perkins Date: Tue, 18 Jan 2022 11:48:49 +0000 Subject: [PATCH] Add PowerShell profile --- .../files/Microsoft.PowerShell_profile.ps1 | 31 +++++++++++++++++++ roles/home-cli/tasks/dirs.yml | 4 +++ roles/home-cli/tasks/dotfiles.yml | 4 +++ 3 files changed, 39 insertions(+) create mode 100644 roles/home-cli/files/Microsoft.PowerShell_profile.ps1 diff --git a/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 b/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 new file mode 100644 index 0000000..d6c8711 --- /dev/null +++ b/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 @@ -0,0 +1,31 @@ +# Put this in the location of $PROFILE. For PowerShell 5+ this is either +# C:\Users\USERNAME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 +# or +# C:\Users\USERNAME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 + +function Prompt { + $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) + if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { + $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "# " + } else { + $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "> " + } +} + +Set-Alias -Name json -Value ConvertTo-Json +Set-PSReadlineOption -BellStyle None +Set-PSReadlineOption -EditMode Emacs +Set-PSReadlineKeyHandler -Key Tab -Function Complete +Set-PSReadLineKeyHandler -Key UpArrow -ScriptBlock { + [Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchBackward() + [Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine() +} +Set-PSReadLineKeyHandler -Key DownArrow -ScriptBlock { + [Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchForward() + [Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine() +} +Set-PSReadLineKeyHandler -Chord Shift+Spacebar -Function SelfInsert +Set-PSReadLineKeyHandler -Chord Ctrl+LeftArrow -Function BackwardWord +Set-PSReadLineKeyHandler -Chord Ctrl+RightArrow -Function ForwardWord +Set-PSReadLineKeyHandler -Chord Ctrl+Backspace -Function BackwardKillWord +Set-PSReadLineKeyHandler -Chord Ctrl+Delete -Function KillWord diff --git a/roles/home-cli/tasks/dirs.yml b/roles/home-cli/tasks/dirs.yml index bd69213..b4718ad 100644 --- a/roles/home-cli/tasks/dirs.yml +++ b/roles/home-cli/tasks/dirs.yml @@ -47,3 +47,7 @@ ansible.builtin.file: path: "{{ ansible_env.HOME }}/.config/mc" state: directory +- name: Create ~/.config/powershell directory + ansible.builtin.file: + path: "{{ ansible_env.HOME }}/.config/powershell" + state: directory diff --git a/roles/home-cli/tasks/dotfiles.yml b/roles/home-cli/tasks/dotfiles.yml index 196b4a6..24ef570 100644 --- a/roles/home-cli/tasks/dotfiles.yml +++ b/roles/home-cli/tasks/dotfiles.yml @@ -66,3 +66,7 @@ ansible.builtin.copy: src: mc.panels.ini dest: "{{ ansible_env.HOME }}/.config/mc/panels.ini" +- name: Copy Microsoft.PowerShell_profile.ps1 + ansible.builtin.copy: + src: Microsoft.PowerShell_profile.ps1 + dest: "{{ ansible_env.HOME }}/.config/powershell/Microsoft.PowerShell_profile.ps1"