Skip to content

Commit 5e8d5c0

Browse files
authored
Merge pull request #52 from alexs-gitK/winget-post-install
Added section for manually enabling auto command completion
2 parents c65f49a + 5fab502 commit 5e8d5c0

File tree

1 file changed

+181
-14
lines changed

1 file changed

+181
-14
lines changed

README.md

Lines changed: 181 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Check out the [installation instructions](#installation) and [examples](#example
1414

1515
## Installation
1616

17-
### macOS
17+
### macOS
1818
`gk` is available from [Homebrew][brew] and [MacPorts][macports] with the following command:
1919

2020
Homebrew:
@@ -31,28 +31,28 @@ Or download it from the [releases page][] and add it to your binaries folder:
3131

3232
```bash
3333
mv ~/Downloads/gk /usr/local/bin/gk
34-
```
34+
```
3535
______
3636
### Unix / Ubuntu
3737
`gk` is available as a downloadable binary from the [releases page][]. Once you have it, add it to your binaries folder:
3838

3939
```bash
4040
mv ~/Downloads/gk /usr/local/bin/gk
41-
```
41+
```
4242

4343
Or create a new directory, move the binary and add it to $PATH:
4444
```bash
4545
mkdir "$HOME/cli"
4646
mv ~/Downloads/gk "$HOME/cli"
4747
export PATH="$HOME/gk:$PATH"
48-
```
48+
```
4949

5050
You can also [download][releases page] your corresponding package (`.deb`, `.rpm`) and install it with:
5151

5252
```bash
5353
sudo apt install ./gk.deb
5454
```
55-
or
55+
or
5656
```bash
5757
sudo rpm -i ./gk.rpm
5858
```
@@ -70,14 +70,49 @@ You can also download it using [Chocolatey][chocolatey]:
7070
choco install gkcli
7171
```
7272

73+
#### Optional Enable Auto Command Completion
74+
To enable auto-completion for `gk` in PowerShell, follow these steps:
75+
76+
**Create and Save the Install Scripts**
77+
Appendix section with script files:
78+
- [gkcli-update-profile.ps1](#gkcli-update-profileps1)
79+
- [gkcli-uninstall-profile.ps1](#gkcli-uninstall-profileps1)
80+
81+
##### Run the Installer Scripts
82+
- Change to the directory where update-profile.ps1 is located
83+
```sh
84+
cd "C:\Path\To\gkcli-update-profile.ps1"
85+
```
86+
87+
- Run the script to update the profile and sign the auto-completion script
88+
```sh
89+
.\gkcli-update-profile.ps1
90+
```
91+
- Restart PowerShell to apply the changes.
92+
93+
##### Run the Uninstall Script
94+
- Change to the directory where uninstall-profile.ps1 is located
95+
```sh
96+
cd "C:\Path\To\gkcli-uninstall-profile.ps1"
97+
```
98+
99+
- Run the script to remove the auto-completion setup
100+
```sh
101+
.\gkcli-uninstall-profile.ps1
102+
```
103+
104+
- Restart PowerShell to apply the changes.
105+
106+
107+
73108
Or download the binary from the [releases page][] and place the `gk.exe` in a desired folder.
74109
Then edit your environment variables to add it to your PATH.
75110

76111
1. In Search, search for **Environment Variables**.
77112
2. Click on the **Edit the system environment variables** result.
78113
3. In the modal, click on the **Environment Variables...** button.
79114
4. In the **System Variables** section, scroll until you find the **PATH** variable. Click on it.
80-
- If it doesn't exist, create a variable with the name **PATH**.
115+
- If it doesn't exist, create a variable with the name **PATH**.
81116
5. Add the path to the `gk` binary at the end.
82117

83118

@@ -101,13 +136,13 @@ unalias gk
101136

102137
### What are Cloud Patches and why would you want to use them
103138

104-
A Cloud Patch is a Git patch that GitKraken securely stores for you so it can be easily shared with others across the GitKraken CLI, GitKraken Desktop, and GitLens. The patch is directly transferred from your machine into secure storage.
139+
A Cloud Patch is a Git patch that GitKraken securely stores for you so it can be easily shared with others across the GitKraken CLI, GitKraken Desktop, and GitLens. The patch is directly transferred from your machine into secure storage.
105140

106141
Cloud Patches allow the ability to engage early with your team before a pull request. They can be created as soon as you have a work in progress. This can help with collaborating on changes prior to a pull request and minimize the delay of pull request reviews.
107142

108-
### How to setup Cloud Patches
143+
### How to setup Cloud Patches
109144

110-
Cloud Patches are enabled in the GitKraken CLI by default.
145+
Cloud Patches are enabled in the GitKraken CLI by default.
111146

112147
### How to work with Cloud Patches
113148

@@ -145,25 +180,25 @@ If you do not want your Cloud Patch data stored on GitKraken Servers, we offer t
145180

146181
## Code Suggest
147182

148-
GitKraken Code Suggest simplifies code review by allowing you to make suggestions and edits across the entire project, not just on the lines that were changed, within GitLens, GitKraken Desktop, and gitkraken.dev. When a Pull Request is open, you can make suggestions to the pull request that others can then review and accept to include in the pull request.
183+
GitKraken Code Suggest simplifies code review by allowing you to make suggestions and edits across the entire project, not just on the lines that were changed, within GitLens, GitKraken Desktop, and gitkraken.dev. When a Pull Request is open, you can make suggestions to the pull request that others can then review and accept to include in the pull request.
149184

150185
![cli-code-suggest.png](/.github/images/cli-code-suggest.png)
151186

152-
To start, navigate (`cd`) to a repository with an open pull request. Then, check out the branch with the open pull request (`git checkout branch-name`). Next, begin making the desired changes locally that you would like to include as suggestions. The [Launchpad](#-launchpad) can quickly help you see open pull requests, check out branches, and begin working.
187+
To start, navigate (`cd`) to a repository with an open pull request. Then, check out the branch with the open pull request (`git checkout branch-name`). Next, begin making the desired changes locally that you would like to include as suggestions. The [Launchpad](#-launchpad) can quickly help you see open pull requests, check out branches, and begin working.
153188

154-
Once you are ready to suggest the changes, run `gk pr suggest`,
189+
Once you are ready to suggest the changes, run `gk pr suggest`,
155190

156191
![cli-code-suggest.png](/.github/images/cli-create-code-suggestion.gif)
157192

158193
This will include a comment on the pull request with two options: you can select _Code Suggestion for #PR_ to open the suggestion in gitkraken.dev or select _locally on your machine_ to open the suggestion in GitKraken or GitLens.
159194

160195
![gl-code-suggest-comment.png](/.github/images/gl-code-suggest-comment.png)
161196

162-
When selecting the _Code Suggestion for #PR_ you will be taken to gitkraken.dev to review and accept the changes. Here, you can review the changes by selecting each file and once you are ready, you can select _Commit Suggestions_. This will create a new commit on the remote for the existing branch (shown under _COMMIT SUGGESTIONS TO_).
197+
When selecting the _Code Suggestion for #PR_ you will be taken to gitkraken.dev to review and accept the changes. Here, you can review the changes by selecting each file and once you are ready, you can select _Commit Suggestions_. This will create a new commit on the remote for the existing branch (shown under _COMMIT SUGGESTIONS TO_).
163198

164199
![gl-accept-code-suggestion.gif](/.github/images/gl-accept-code-suggestion.gif)
165200

166-
When selecting _locally on your machine_ you can open them on [GitKraken Desktop](/gitkraken-client/pull-requests/#review-code-and-suggest-changes) or [GitLens](gitlens/gitlens-features/#code-suggest-preview). Here, you can review the changes by selecting each file and once you are ready, you can select _Apply_ to apply to the branch you currently have checked out or select the dropdown and then _Apply to a Branch_ to apply to a new branch or select an existing branch. This will apply the patch locally.
201+
When selecting _locally on your machine_ you can open them on [GitKraken Desktop](/gitkraken-client/pull-requests/#review-code-and-suggest-changes) or [GitLens](gitlens/gitlens-features/#code-suggest-preview). Here, you can review the changes by selecting each file and once you are ready, you can select _Apply_ to apply to the branch you currently have checked out or select the dropdown and then _Apply to a Branch_ to apply to a new branch or select an existing branch. This will apply the patch locally.
167202

168203
![gl-accept-code-suggestion-from-gl.gif](/.github/images/gl-accept-code-suggestion-from-gl.gif)
169204

@@ -268,3 +303,135 @@ https://user-images.githubusercontent.com/3358707/231006608-18f3dca2-a67c-4e77-b
268303
[macports]: https://www.macports.org/
269304
[winget]: https://github.com/microsoft/winget-cli
270305
[chocolatey]: https://community.chocolatey.org/packages/GKCLI
306+
307+
308+
309+
## Appendix
310+
311+
### gkcli-update-profile.ps1
312+
>Note: the installer script creates a self-signed certificate and adds it to the trusted root.
313+
314+
```sh
315+
# gkcli-update-profile.ps1
316+
317+
function Test-Admin {
318+
$currentUser = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
319+
$currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
320+
}
321+
322+
if (-not (Test-Admin)) {
323+
Write-Warning "This script requires elevation (run as administrator)."
324+
exit 1
325+
}
326+
327+
$gkPath = (Get-Command gk).Source
328+
329+
$gkDir = Split-Path $gkPath
330+
331+
$completionScriptPath = Join-Path -Path $gkDir -ChildPath "completions\gk.ps1"
332+
333+
if (-Not (Test-Path -Path $completionScriptPath)) {
334+
Write-Error "The auto-completion script gk.ps1 could not be found at $completionScriptPath"
335+
exit 1
336+
}
337+
338+
$signature = Get-AuthenticodeSignature -FilePath $completionScriptPath
339+
if ($signature.Status -ne 'Valid') {
340+
Write-Host "The script is not signed. Creating a self-signed certificate and signing the script."
341+
342+
# Create a self-signed certificate for script signing
343+
$cert = New-SelfSignedCertificate -DnsName "GitKrakenCLI" -Type CodeSigningCert -CertStoreLocation "Cert:\CurrentUser\My"
344+
345+
# Export the certificate to a file
346+
$certPath = "$env:TEMP\GitKrakenCLI.cer"
347+
Export-Certificate -Cert $cert -FilePath $certPath
348+
349+
# Import the certificate into Trusted Root Certification Authorities and Trusted Publishers
350+
Import-Certificate -FilePath $certPath -CertStoreLocation "Cert:\LocalMachine\Root" -ErrorAction Stop
351+
Import-Certificate -FilePath $certPath -CertStoreLocation "Cert:\LocalMachine\TrustedPublisher" -ErrorAction Stop
352+
353+
# Sign the completion script with the certificate
354+
Set-AuthenticodeSignature -FilePath $completionScriptPath -Certificate $cert
355+
356+
Write-Host "Script signed successfully and certificate added to Trusted Root Certification Authorities and Trusted Publishers."
357+
} else {
358+
Write-Host "The script is already signed."
359+
}
360+
361+
$profilePath = [System.Environment]::GetFolderPath('MyDocuments') + "\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"
362+
363+
# Create the profile file if it doesn't exist
364+
if (-Not (Test-Path -Path $profilePath)) {
365+
New-Item -ItemType File -Path $profilePath -Force
366+
}
367+
368+
$content = Get-Content -Path $profilePath
369+
if (-Not ($content -contains ". '$completionScriptPath'")) {
370+
Add-Content -Path $profilePath -Value "`n. '$completionScriptPath'"
371+
Write-Host "The PowerShell profile has been updated to source the auto-completion script."
372+
} else {
373+
Write-Host "The PowerShell profile already sources the auto-completion script."
374+
}
375+
376+
# Source the completion script in the current session
377+
. $completionScriptPath
378+
379+
Write-Host "Auto-completion script sourced successfully. Please restart PowerShell to activate the changes."
380+
381+
```
382+
### gkcli-uninstall-profile.ps1
383+
```sh
384+
# gkcli-uninstall-profile.ps1
385+
386+
function Test-Admin {
387+
$currentUser = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
388+
$currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
389+
}
390+
391+
if (-not (Test-Admin)) {
392+
Write-Warning "This script requires elevation (run as administrator)."
393+
exit 1
394+
}
395+
396+
$certSubjectName = "CN=GitKrakenCLI"
397+
398+
function Remove-Certificate {
399+
param (
400+
[string]$storeName,
401+
[string]$storeLocation,
402+
[string]$subjectName
403+
)
404+
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store($storeName, $storeLocation)
405+
$store.Open("ReadWrite")
406+
$certs = $store.Certificates | Where-Object { $_.Subject -eq $subjectName }
407+
if ($certs.Count -gt 0) {
408+
$store.Remove($certs)
409+
Write-Host "Removed certificate from $storeName."
410+
} else {
411+
Write-Host "Certificate not found in $storeName."
412+
}
413+
$store.Close()
414+
}
415+
416+
Remove-Certificate -storeName "Root" -storeLocation "LocalMachine" -subjectName $certSubjectName
417+
Remove-Certificate -storeName "TrustedPublisher" -storeLocation "LocalMachine" -subjectName $certSubjectName
418+
419+
$gkPath = (Get-Command gk).Source
420+
421+
$gkDir = Split-Path $gkPath
422+
423+
$completionScriptPath = Join-Path -Path $gkDir -ChildPath "completions\gk.ps1"
424+
425+
$profilePath = [System.Environment]::GetFolderPath('MyDocuments') + "\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"
426+
if (Test-Path -Path $profilePath) {
427+
$content = Get-Content -Path $profilePath
428+
$newContent = $content | Where-Object { $_ -notmatch [regex]::Escape(". '$completionScriptPath'") }
429+
Set-Content -Path $profilePath -Value $newContent
430+
Write-Host "Removed the auto-completion script sourcing line from the PowerShell profile."
431+
} else {
432+
Write-Host "PowerShell profile not found."
433+
}
434+
435+
Write-Host "Uninstallation complete. Please restart PowerShell to apply the changes."
436+
437+
```

0 commit comments

Comments
 (0)