tfv 6.1.1 → 6.1.3

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.
@@ -11,11 +11,20 @@ _tfv_auto_switch() {
11
11
  fi
12
12
  }
13
13
 
14
- _tfv_cd() {
15
- builtin cd "$@" && _tfv_auto_switch
16
- }
17
-
18
- alias cd='_tfv_cd'
14
+ # Hook into directory changes without touching cd
15
+ if [ -n "\${ZSH_VERSION:-}" ]; then
16
+ autoload -Uz add-zsh-hook
17
+ add-zsh-hook chpwd _tfv_auto_switch
18
+ elif [ -n "\${BASH_VERSION:-}" ]; then
19
+ _tfv_prev_dir="\$PWD"
20
+ _tfv_dir_check() {
21
+ if [ "\$PWD" != "\$_tfv_prev_dir" ]; then
22
+ _tfv_prev_dir="\$PWD"
23
+ _tfv_auto_switch
24
+ fi
25
+ }
26
+ PROMPT_COMMAND="\${PROMPT_COMMAND:+\${PROMPT_COMMAND}; }_tfv_dir_check"
27
+ fi
19
28
 
20
29
  # Run for the current directory on shell startup
21
30
  _tfv_auto_switch
@@ -59,7 +68,6 @@ elif [ -n "\${ZSH_VERSION:-}" ]; then
59
68
  esac
60
69
  }
61
70
  compdef _tfv_complete tfv 2>/dev/null
62
- compdef _tfv_cd=cd 2>/dev/null
63
71
  fi
64
72
  `.trim();
65
73
 
@@ -73,8 +81,7 @@ function _tfv_auto_switch
73
81
  end
74
82
  end
75
83
 
76
- function cd
77
- builtin cd $argv
84
+ function _tfv_on_pwd --on-variable PWD
78
85
  _tfv_auto_switch
79
86
  end
80
87
 
@@ -119,19 +126,24 @@ const POWERSHELL_HOOK = `
119
126
  # Add to your PowerShell profile ($PROFILE):
120
127
  # Invoke-Expression (tfv shell-init powershell | Out-String)
121
128
 
122
- function global:Set-LocationWithTfv {
123
- param([string]$Path = $PWD)
124
- Set-Location $Path
125
- if ((Test-Path ".terraform-version") -or (Get-ChildItem -Filter "*.tf" -ErrorAction SilentlyContinue)) {
126
- tfv auto-switch --silent 2>$null
129
+ # Hook into directory changes without touching cd
130
+ $global:_TfvLastDir = $PWD.Path
131
+ $global:_TfvUserPrompt = if (Test-Path function:prompt) { $function:prompt } else { $null }
132
+ function global:prompt {
133
+ $currentPath = $PWD.Path
134
+ if ($currentPath -ne $global:_TfvLastDir) {
135
+ $global:_TfvLastDir = $currentPath
136
+ if ((Test-Path ".terraform-version") -or (Get-ChildItem -Filter "*.tf" -ErrorAction SilentlyContinue)) {
137
+ tfv auto-switch --silent 2>$null
138
+ }
127
139
  }
140
+ if ($global:_TfvUserPrompt) { & $global:_TfvUserPrompt } else { "PS $($executionContext.SessionState.Path.CurrentLocation)> " }
128
141
  }
129
142
 
130
- Remove-Item -Path Alias:cd -Force -ErrorAction SilentlyContinue
131
- Set-Alias -Name cd -Value Set-LocationWithTfv -Scope Global -Force
132
-
133
143
  # Run for current directory on shell startup
134
- Set-LocationWithTfv -Path $PWD
144
+ if ((Test-Path ".terraform-version") -or (Get-ChildItem -Filter "*.tf" -ErrorAction SilentlyContinue)) {
145
+ tfv auto-switch --silent 2>$null
146
+ }
135
147
 
136
148
  # ── Tab completions ────────────────────────────────────────────────────────
137
149
  Register-ArgumentCompleter -Native -CommandName tfv -ScriptBlock {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tfv",
3
- "version": "6.1.1",
3
+ "version": "6.1.3",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true