-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
BookGenShell.ps1
154 lines (136 loc) · 4.14 KB
/
BookGenShell.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# -----------------------------------------------------------------------------
# BookGen PowerShell Registration script
# Version 2.9.0
# Last modified: 2024-05-20
# -----------------------------------------------------------------------------
# cdg command
function cdg
{
$argsAsString = $args -join ' '
if ([string]::IsNullOrWhiteSpace($argsAsString))
{
BookGen.Shell.exe "cdg"
}
else
{
BookGen.Shell.exe "cdg" "$argsAsString"
}
$location = [Environment]::GetEnvironmentVariable('cdgPath', 'User')
Push-Location $location
}
# www command
function www
{
$argsAsString = $args -join ' '
if ([string]::IsNullOrWhiteSpace($argsAsString))
{
BookGen.Shell.exe "www"
}
else
{
BookGen.Shell.exe "www" "$argsAsString"
}
}
# organize command
function organize
{
$argsAsString = $args -join ' '
if ([string]::IsNullOrWhiteSpace($argsAsString))
{
BookGen.Shell.exe "organize"
}
else
{
BookGen.Shell.exe "organize" "$argsAsString"
}
}
# info command
function bookgen-info()
{
Clear-Host
Get-Content $env:BookGenPath\getting-started.mdr | Out-Host -Paging
}
# lancher Command
function launcher()
{
BookGen.Launch.exe $(Get-Location).Path
}
# intro message
function intro()
{
clear
bookgen version
Write-Host " ____________________________________________________ "
Write-Host "/ To view the getting started doc type: bookgen-info \"
Write-Host "| To get info on using bookgen type: Bookgen Help |"
Write-Host "| To graphicaly select working directory type: cdg |"
Write-Host "| To start the bookgen launcher type: launcher |"
Write-Host "\ To redisplay this message type: intro /"
Write-Host " ----------------------------------------------------- "
Write-Host " \"
Write-Host " \ \"
Write-Host " \ /\"
Write-Host " ( )"
Write-Host " .( o )."
Bookgen.exe terminalinstall -t
if ($LastExitCode -eq 0) {
Bookgen.exe terminalinstall -c
if ($LastExitCode -ne 0) {
Write-Host ""
Write-Host "To install this shell as a windows terminal profile run:";
Write-Host "Bookgen terminalinstall"
}
}
}
#Set UTF8 encoding
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[console]::InputEncoding = [System.Text.Encoding]::UTF8
#Set BookGenRoot variable
$env:BookGenPath = $PSScriptRoot
# register scripts folder to the path
$env:Path += ";$PSScriptRoot"
# set colors
Set-PSReadLineOption -Colors @{
Parameter = 'Red'
String = 'Cyan'
Command = 'Green'
}
# PowerShell parameter completion shim for BookGen
Register-ArgumentCompleter -Native -CommandName BookGen -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
BookGen.exe "Shell" "$wordToComplete" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
# Case invariant registration
Register-ArgumentCompleter -Native -CommandName bookgen -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
BookGen.exe "Shell" "$wordToComplete" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
# PowerShell parameter completion shim for the dotnet CLI
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
dotnet complete --position $cursorPosition "$wordToComplete" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
# PowerShell parameter completion shim for git
Register-ArgumentCompleter -Native -CommandName git -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
BookGen.Shell.exe "git-complete" $cursorPosition "$wordToComplete" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
# set prompt
function prompt {
$git = $(BookGen.Shell.exe "prompt" $(Get-Location).Path)
'PS ' + $(Get-Location) + ' '+$git+ $(if ($NestedPromptLevel -ge 1) { '>>' }) + ' > '
}
# if argument given set to startup folder
if ($args.Count -eq 1) {
Set-Location $args[0]
}
# welcome message
intro