gitbash 2.2.1 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +4 -10
  2. package/bin/gitbash +51 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -54,18 +54,12 @@ winget install junegunn.fzf dandavison.delta sharkdp.bat # needs fzf >= 0.54
54
54
  gitbash --config
55
55
  ```
56
56
 
57
- Shell integration for PowerShell. This creates your profile if needed, loads the functions in every new window, and allows local scripts to run (Windows PowerShell 5.1 blocks them by default):
57
+ `gitbash --config` also sets up the shell integration: it offers to load the gitbash functions in your PowerShell profile (and to allow local scripts, which Windows PowerShell blocks by default) and in `~/.bashrc` for Git Bash. Open a new window afterwards. `switch` is a PowerShell keyword: use `gitbash switch` there.
58
58
 
59
- ```powershell
60
- if (!(Test-Path $PROFILE)) { New-Item -Force $PROFILE }
61
- Add-Content $PROFILE 'gitbash --init --shell=pwsh | Out-String | Invoke-Expression' # switch is a keyword: use gitbash switch
62
- Set-ExecutionPolicy -Scope CurrentUser RemoteSigned # Windows PowerShell 5.1 only
63
- ```
64
-
65
- Shell integration for Git Bash:
59
+ To set it up by hand, add this line to your PowerShell profile (`notepad $PROFILE`):
66
60
 
67
- ```bash
68
- echo 'eval "$(gitbash --init)"' >> ~/.bashrc
61
+ ```powershell
62
+ gitbash --init --shell=pwsh | Out-String | Invoke-Expression
69
63
  ```
70
64
 
71
65
  ### Without npm
package/bin/gitbash CHANGED
@@ -361,14 +361,60 @@ check_dependencies() {
361
361
  }
362
362
 
363
363
  # Offer to add the shell integration to the rc file of the user's shell
364
- check_shell_integration() {
365
- local shell_name shell_rc
366
- # Can't tell PowerShell from Git Bash here: always show the PowerShell line
367
- if gb_is_windows; then
364
+ # Line that loads the PowerShell functions, in $PROFILE
365
+ PWSH_INIT_LINE='gitbash --init --shell=pwsh | Out-String | Invoke-Expression'
366
+
367
+ # Offer to load the functions in the profiles of Windows PowerShell (powershell.exe)
368
+ # and PowerShell 7 (pwsh.exe), and to allow local scripts if needed.
369
+ # PowerShell edits its own profile: it may be UTF-16, which bash can't append to.
370
+ check_pwsh_integration() {
371
+ local exe info profile has policy found=false
372
+ # Prints "<profile>|<True if it loads gitbash>|<execution policy>" (no double
373
+ # quotes in PowerShell commands: they don't survive the Windows command line)
374
+ local query="\$p = \$PROFILE; \$has = (Test-Path -LiteralPath \$p) -and [bool](Select-String -Quiet -SimpleMatch -Pattern 'gitbash --init' -LiteralPath \$p); Write-Output (\$p + '|' + \$has + '|' + (Get-ExecutionPolicy))"
375
+ for exe in powershell.exe pwsh.exe; do
376
+ command -v "$exe" >/dev/null 2>&1 || continue
377
+ info=$("$exe" -NoProfile -NonInteractive -Command "$query" 2>/dev/null | tr -d '\r' | tail -n 1)
378
+ IFS='|' read -r profile has policy <<< "$info"
379
+ [[ -n "$profile" ]] || continue
380
+ found=true
381
+
382
+ echo
383
+ if [[ "$has" == "True" ]]; then
384
+ print_info "PowerShell integration already configured in $profile"
385
+ elif gb_confirm "Load the gitbash functions in PowerShell ($profile)?" y; then
386
+ if "$exe" -NoProfile -NonInteractive -Command \
387
+ "\$p = \$PROFILE; if (!(Test-Path -LiteralPath \$p)) { New-Item -Force -Path \$p | Out-Null }; Add-Content -LiteralPath \$p '$PWSH_INIT_LINE'"; then
388
+ print_success "Added to $profile. Open a new PowerShell window to use it."
389
+ else
390
+ print_error "Could not change $profile. Add this line yourself: $PWSH_INIT_LINE"
391
+ fi
392
+ fi
393
+
394
+ # Restricted (the default of Windows PowerShell) and AllSigned block the profile
395
+ case "$policy" in
396
+ Restricted|AllSigned|Undefined)
397
+ if gb_confirm "PowerShell blocks scripts, including your profile ($policy). Allow local scripts (execution policy RemoteSigned)?" y; then
398
+ if "$exe" -NoProfile -NonInteractive -Command 'Set-ExecutionPolicy -Scope CurrentUser RemoteSigned -Force'; then
399
+ print_success "Local scripts allowed."
400
+ else
401
+ print_error "Could not change the execution policy (it may be set by your organization)."
402
+ fi
403
+ fi
404
+ ;;
405
+ esac
406
+ done
407
+ if [[ "$found" == false ]]; then
368
408
  echo
369
409
  print_info "For PowerShell, add this line to your \$PROFILE:"
370
- echo " gitbash --init --shell=pwsh | Out-String | Invoke-Expression"
410
+ echo " $PWSH_INIT_LINE"
371
411
  fi
412
+ }
413
+
414
+ check_shell_integration() {
415
+ local shell_name shell_rc
416
+ # Can't tell PowerShell from Git Bash here: offer both
417
+ gb_is_windows && check_pwsh_integration
372
418
  shell_name=$(basename "${SHELL:-}")
373
419
  case "$shell_name" in
374
420
  zsh) shell_rc="$HOME/.zshrc" ;;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitbash",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Opinionated git utilities for bash with fzf-powered menus",
5
5
  "author": "jaggli",
6
6
  "license": "MIT",