Last active
July 15, 2020 18:25
-
-
Save catvec/66fe9400893c259849a6f7fc4945cf69 to your computer and use it in GitHub Desktop.
Windows command line setup. Using Windows Terminal + PowerShell 7.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set line edit mode to emacs | |
Set-PSReadLineOption -EditMode Emacs | |
# Git shortcut | |
Set-Alias -Name g -Value git -Option AllScope | |
# Emacs alias | |
Function Emacs-No-Window { | |
~\bin\emacs\bin\emacs.exe -nw $args | |
} | |
Set-Alias -Name emacs -Value Emacs-No-Window -Option AllScope | |
# Edit shortcut | |
Function Edit { | |
emacs $args | |
} | |
Set-Alias -Name e -Value Edit -Option AllScope | |
# Trash alias | |
Set-Alias -Name rm -Value Remove-ItemSafely -Option AllScope | |
Set-Alias -Name trash -Value Remove-ItemSafely -Option AllScope | |
# Turn off terminal beep | |
Set-PSReadlineOption -BellStyle None | |
# Customize prompt | |
Function global:prompt { | |
# Indicate if last command failed | |
if (! $?) { | |
Write-Host -Object "X " -NoNewLine -ForegroundColor Red | |
} | |
# Virtual environment indicator | |
if ($env:VIRTUAL_ENV) { | |
$EnvName = Split-Path $env:VIRTUAL_ENV -Leaf | |
$MaxEnvNameLength = 10 | |
if ($EnvName.Length -gt $MaxEnvNameLength) { | |
$EnvName = $EnvName[0..$MaxEnvNameLength] -join "" | |
$EnvName += "..." | |
} | |
Write-Host -Object "($EnvName) " -NoNewLine | |
} | |
# PWD relative to home | |
$PwdPath = $pwd -replace [regex]::Escape($HOME), "~" | |
Write-Host -Object "$LastCmdStatus$PwdPath" -NoNewLine -ForegroundColor DarkCyan | |
# Git branch | |
$GitBranch = git rev-parse --abbrev-ref HEAD 2> $null | |
if ($GitBranch) { | |
Write-Host -Object " git" -NoNewLine -ForegroundColor Green | |
Write-Host -Object ":" -NoNewLine | |
Write-Host -Object "$GitBranch" -NoNewLine -ForegroundColor Magenta | |
} | |
# Prompt | |
return " % " | |
} | |
# Allows user to refresh various aspects of the terminal | |
Function Meta-Refresh { | |
param ( | |
[ValidateSet("Path", | |
"PowerShellProfile", "PSProfile" | |
)] | |
[String] | |
$Component | |
) | |
Switch -Regex ($Component) { | |
"^Path$" | |
{ | |
# Reloads the PATH environment variable | |
# From: https://stackoverflow.com/a/31845512 | |
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") | |
Write-Host -Object "Refreshed PATH" | |
} | |
"^PowerShellProfile|PSProfile$" | |
{ | |
# Reload Powershell profile | |
. $PROFILE | |
Write-Host -Object "Refreshed profile" | |
} | |
} | |
} | |
# Save location of Windows Terminal settings profile so it can be editted easily | |
$WindowsTerminalProfile = "$HOME\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" | |
# Allow users to edit aspects of the terminal | |
Function Meta-Edit { | |
param ( | |
[ValidateSet( | |
"PowerShellProfile", "PSProfile", | |
"WindowsTerminalProfile" | |
)] | |
[String] | |
$Component | |
) | |
Switch -Regex ($Component) { | |
"^PowerShellProfile|PSProfile$" | |
{ | |
# Edit PowerShell profile | |
emacs $PROFILE | |
} | |
"WindowsTerminalProfile" | |
{ | |
# Edit terminal profile | |
emacs $WindowsTerminalProfile | |
} | |
} | |
} | |
# Open Org mode notebook | |
$MAIN_ORG_NOTEBOOK = "$HOME\Documents\work.org" | |
Function Org { | |
emacs -nw "$MAIN_ORG_NOTEBOOK" | |
} | |
# Custom MOTD | |
Write-Host -Object "┏━━━┓┏┓━━━━━━━━━━━━━━━━━━━━━━━━┏━━━┓━━━━━━━━━┏┓━━━━━━━━┏┓━━━━━ | |
┃┏━┓┃┃┃━━━━━━━━━━━━━━━━━━━━━━━━┃┏━┓┃━━━━━━━━┏┛┗┓━━━━━━━┃┃━━━━━ | |
┃┗━┛┃┃┗━┓┏━━┓┏━━┓┏━┓━┏┓┏┓┏┓━━━━┃┃━┗┛┏━━┓┏━┓━┗┓┏┛┏━┓┏━━┓┃┃━┏━━┓ | |
┃┏━━┛┃┏┓┃┃┏┓┃┃┏┓┃┃┏┓┓┣┫┗╋╋┛━━━━┃┃━┏┓┃┏┓┃┃┏┓┓━┃┃━┃┏┛┃┏┓┃┃┃━┃━━┫ | |
┃┃━━━┃┃┃┃┃┗┛┃┃┃━┫┃┃┃┃┃┃┏╋╋┓━━━━┃┗━┛┃┃┗┛┃┃┃┃┃━┃┗┓┃┃━┃┗┛┃┃┗┓┣━━┃ | |
┗┛━━━┗┛┗┛┗━━┛┗━━┛┗┛┗┛┗┛┗┛┗┛━━━━┗━━━┛┗━━┛┗┛┗┛━┗━┛┗┛━┗━━┛┗━┛┗━━┛ | |
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | |
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file was initially generated by Windows Terminal 1.0.1401.0 | |
// It should still be usable in newer versions, but newer versions might have additional | |
// settings, help text, or changes that you will not see unless you clear this file | |
// and let us generate a new one for you. | |
// To view the default settings, hold "alt" while clicking on the "Settings" button. | |
// For documentation on these settings, see: https://aka.ms/terminal-documentation | |
{ | |
"$schema": "https://aka.ms/terminal-profiles-schema", | |
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", | |
// You can add more global application settings here. | |
// To learn more about global settings, visit https://aka.ms/terminal-global-settings | |
// If enabled, selections are automatically copied to your clipboard. | |
"copyOnSelect": false, | |
// If enabled, formatted data is also copied to your clipboard | |
"copyFormatting": false, | |
// A profile specifies a command to execute paired with information about how it should look and feel. | |
// Each one of them will appear in the 'New Tab' dropdown, | |
// and can be invoked from the commandline with `wt.exe -p xxx` | |
// To learn more about profiles, visit https://aka.ms/terminal-profile-settings | |
"profiles": | |
{ | |
"defaults": | |
{ | |
// Put settings here that you want to apply to all profiles. | |
}, | |
"list": | |
[ | |
{ | |
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", | |
"hidden": false, | |
"name": "PowerShell", | |
//"source": "Windows.Terminal.PowershellCore", | |
"commandline": "pwsh.exe -nologo", | |
"colorScheme": "One Half Dark", | |
"startDirectory": "$HOME/Documents" | |
}, | |
{ | |
// Make changes here to the powershell.exe profile. | |
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", | |
"name": "Windows PowerShell", | |
"commandline": "powershell.exe", | |
"hidden": true | |
}, | |
{ | |
// Make changes here to the cmd.exe profile. | |
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}", | |
"name": "Command Prompt", | |
"commandline": "cmd.exe", | |
"hidden": false | |
}, | |
{ | |
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}", | |
"hidden": true, | |
"name": "Azure Cloud Shell", | |
"source": "Windows.Terminal.Azure" | |
}, | |
{ | |
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}", | |
"hidden": false, | |
"name": "Ubuntu", | |
"source": "Windows.Terminal.Wsl" | |
}, | |
{ | |
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", | |
"hidden": false, | |
"name": "PowerShell", | |
"source": "Windows.Terminal.PowershellCore" | |
} | |
] | |
}, | |
// Add custom color schemes to this array. | |
// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes | |
"schemes": [], | |
// Add custom keybindings to this array. | |
// To unbind a key combination from your defaults.json, set the command to "unbound". | |
// To learn more about keybindings, visit https://aka.ms/terminal-keybindings | |
"keybindings": [ | |
// Unbind C-j just in case | |
{ "command": "unbound", "keys": "ctrl+j" }, | |
// Application-level Keys | |
{ "command": "unbound", "keys": "alt+f4" }, | |
{ "command": "unbound", "keys": "alt+enter" }, | |
{ "command": "unbound", "keys": "f11" }, | |
{ "command": "unbound", "keys": "ctrl+shift+space" }, | |
{ "command": "unbound", "keys": "ctrl+," }, | |
{ "command": "unbound", "keys": "ctrl+shift+f" }, | |
// Tab Management | |
// "command": "closeTab" is unbound by default. | |
// The closeTab command closes a tab without confirmation, even if it has multiple panes. | |
{ "command": "unbound", "keys": "ctrl+shift+t" }, | |
{ "command": "unbound", "keys": "ctrl+shift+1" }, | |
{ "command": "unbound", "keys": "ctrl+shift+2" }, | |
{ "command": "unbound", "keys": "ctrl+shift+3" }, | |
{ "command": "unbound", "keys": "ctrl+shift+4" }, | |
{ "command": "unbound", "keys": "ctrl+shift+5" }, | |
{ "command": "unbound", "keys": "ctrl+shift+6" }, | |
{ "command": "unbound", "keys": "ctrl+shift+7" }, | |
{ "command": "unbound", "keys": "ctrl+shift+8" }, | |
{ "command": "unbound", "keys": "ctrl+shift+9" }, | |
{ "command": "unbound", "keys": "ctrl+shift+d" }, | |
{ "command": "unbound", "keys": "ctrl+tab" }, | |
{ "command": "unbound", "keys": "ctrl+shift+tab" }, | |
{ "command": "unbound", "keys": "ctrl+alt+1" }, | |
{ "command": "unbound", "keys": "ctrl+alt+2" }, | |
{ "command": "unbound", "keys": "ctrl+alt+3" }, | |
{ "command": "unbound", "keys": "ctrl+alt+4" }, | |
{ "command": "unbound", "keys": "ctrl+alt+5" }, | |
{ "command": "unbound", "keys": "ctrl+alt+6" }, | |
{ "command": "unbound", "keys": "ctrl+alt+7" }, | |
{ "command": "unbound", "keys": "ctrl+alt+8" }, | |
{ "command": "unbound", "keys": "ctrl+alt+9" }, | |
// Pane Management | |
{ "command": "unbound", "keys": "ctrl+shift+w" }, | |
{ "command": "unbound", "keys": "alt+shift+-" }, | |
{ "command": "unbound", "keys": "alt+shift+plus" }, | |
{ "command": "unbound", "keys": "alt+shift+down" }, | |
{ "command": "unbound", "keys": "alt+shift+left" }, | |
{ "command": "unbound", "keys": "alt+shift+right" }, | |
{ "command": "unbound", "keys": "alt+shift+up" }, | |
{ "command": "unbound", "keys": "alt+down" }, | |
{ "command": "unbound", "keys": "alt+left" }, | |
{ "command": "unbound", "keys": "alt+right" }, | |
{ "command": "unbound", "keys": "alt+up" }, | |
// Clipboard Integration | |
{ "command": { "action": "copy", "singleLine": false }, "keys": "ctrl+shift+c" }, | |
{ "command": "unbound", "keys": "ctrl+insert" }, | |
{ "command": "paste", "keys": "ctrl+shift+v" }, | |
{ "command": "unbound", "keys": "shift+insert" }, | |
// Scrollback | |
{ "command": "unbound", "keys": "ctrl+shift+down" }, | |
{ "command": "unbound", "keys": "ctrl+shift+pgdn" }, | |
{ "command": "unbound", "keys": "ctrl+shift+up" }, | |
{ "command": "unbound", "keys": "ctrl+shift+pgup" }, | |
// Visual Adjustments | |
{ "command": { "action": "adjustFontSize", "delta": 1 }, "keys": "ctrl+=" }, | |
{ "command": { "action": "adjustFontSize", "delta": -1 }, "keys": "ctrl+-" }, | |
{ "command": "unbound", "keys": "ctrl+0" } | |
] | |
//[ | |
// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json. | |
// These two lines additionally bind them to Ctrl+C and Ctrl+V. | |
// To learn more about selection, visit https://aka.ms/terminal-selection | |
//{ "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" }, | |
//{ "command": "paste", "keys": "ctrl+v" }, | |
// Press Ctrl+Shift+F to open the search box | |
//{ "command": "find", "keys": "ctrl+shift+f" }, | |
// Press Alt+Shift+D to open a new pane. | |
// - "split": "auto" makes this pane open in the direction that provides the most surface area. | |
// - "splitMode": "duplicate" makes the new pane use the focused pane's profile. | |
// To learn more about panes, visit https://aka.ms/terminal-panes | |
//{ "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" } | |
//] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment