try-cli 1.9.2 → 1.9.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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/try.rb +135 -27
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 07dc2d2cbbb24c4c934bffceead77e583ef973e1c7f7a08361863c340a373783
|
|
4
|
+
data.tar.gz: 8c110d86811dbecdd9b7a0778605f76d3564f6f9eec697a05da809a98f39b5dd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c93e4020653e00136115a24cd831e409e00b3e1e9ae48013794b794115f37eae3df599af93c01bd4e571ca45933188c460a4e808e4ad6a78eef5b2384c814ff6
|
|
7
|
+
data.tar.gz: 5487462b36084f6f4b5b7ebe553724d9ac1bddd42246a5d9bea5a53f2702a1be311cfbae448686c68fe73a8134ab73af1bda5d2403ed0d19f5bc62589f33b09c
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.9.
|
|
1
|
+
1.9.3
|
data/try.rb
CHANGED
|
@@ -955,7 +955,7 @@ end
|
|
|
955
955
|
# Main execution with OptionParser subcommands
|
|
956
956
|
if __FILE__ == $0
|
|
957
957
|
|
|
958
|
-
VERSION = "1.9.
|
|
958
|
+
VERSION = "1.9.3"
|
|
959
959
|
|
|
960
960
|
def print_global_help
|
|
961
961
|
text = <<~HELP
|
|
@@ -1176,37 +1176,142 @@ if __FILE__ == $0
|
|
|
1176
1176
|
File.expand_path(args.shift)
|
|
1177
1177
|
end
|
|
1178
1178
|
|
|
1179
|
-
# Priority: explicit init argument > $TRY_PATH (runtime) > default
|
|
1180
1179
|
default_path = tries_path || File.expand_path("~/src/tries")
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1180
|
+
shell = fish? ? 'fish' : 'bash'
|
|
1181
|
+
puts init_snippet(shell, script_path, explicit_path, default_path)
|
|
1182
|
+
exit 0
|
|
1183
|
+
end
|
|
1184
|
+
|
|
1185
|
+
def cmd_install!(args, tries_path)
|
|
1186
|
+
script_path = File.expand_path($0)
|
|
1187
|
+
|
|
1188
|
+
explicit_path = if args[0] && args[0].start_with?('/')
|
|
1189
|
+
File.expand_path(args.shift)
|
|
1190
|
+
end
|
|
1191
|
+
|
|
1192
|
+
default_path = tries_path || File.expand_path("~/src/tries")
|
|
1193
|
+
|
|
1194
|
+
shell = detect_shell
|
|
1195
|
+
rc_file = shell_rc_file(shell)
|
|
1196
|
+
snippet = init_snippet(shell, script_path, explicit_path, default_path)
|
|
1197
|
+
|
|
1198
|
+
unless rc_file
|
|
1199
|
+
STDERR.puts "Error: could not determine shell config file"
|
|
1200
|
+
STDERR.puts "Your shell was detected as: #{shell || 'unknown'}"
|
|
1201
|
+
STDERR.puts "Run 'try init' and manually add the output to your shell config."
|
|
1202
|
+
exit 1
|
|
1203
|
+
end
|
|
1204
|
+
|
|
1205
|
+
rc_path = File.expand_path(rc_file)
|
|
1206
|
+
|
|
1207
|
+
# Check if already installed
|
|
1208
|
+
if File.exist?(rc_path) && File.read(rc_path).include?("# try shell integration")
|
|
1209
|
+
STDERR.puts "try is already installed in #{rc_path}"
|
|
1210
|
+
STDERR.puts "To reinstall, remove the '# try shell integration' block first."
|
|
1211
|
+
exit 0
|
|
1212
|
+
end
|
|
1213
|
+
|
|
1214
|
+
block = "\n# try shell integration\n#{snippet}"
|
|
1205
1215
|
|
|
1206
|
-
|
|
1216
|
+
if File.exist?(rc_path) && !File.writable?(rc_path)
|
|
1217
|
+
STDERR.puts "Warning: #{rc_path} is read-only, skipping."
|
|
1218
|
+
STDERR.puts "Run 'try init' and manually add the output to your shell config."
|
|
1219
|
+
exit 1
|
|
1220
|
+
end
|
|
1221
|
+
|
|
1222
|
+
FileUtils.mkdir_p(File.dirname(rc_path))
|
|
1223
|
+
File.open(rc_path, 'a') { |f| f.write(block) }
|
|
1224
|
+
STDERR.puts "Added try shell integration to #{rc_path}"
|
|
1225
|
+
STDERR.puts "Restart your shell or run: source #{rc_path}" unless shell == 'pwsh'
|
|
1226
|
+
STDERR.puts "Restart your shell or run: . $PROFILE" if shell == 'pwsh'
|
|
1207
1227
|
exit 0
|
|
1208
1228
|
end
|
|
1209
1229
|
|
|
1230
|
+
def detect_shell
|
|
1231
|
+
# Check SHELL env (Unix), then parent process, then PSModulePath for PowerShell
|
|
1232
|
+
shell_env = ENV["SHELL"].to_s
|
|
1233
|
+
return 'fish' if shell_env.include?('fish')
|
|
1234
|
+
return 'zsh' if shell_env.include?('zsh')
|
|
1235
|
+
return 'bash' if shell_env.include?('bash')
|
|
1236
|
+
|
|
1237
|
+
# PowerShell detection: PSModulePath is set in pwsh sessions
|
|
1238
|
+
return 'pwsh' if ENV["PSModulePath"] && !ENV["PSModulePath"].empty?
|
|
1239
|
+
|
|
1240
|
+
# Fallback: check parent process name
|
|
1241
|
+
parent = (`ps c -p #{Process.ppid} -o 'ucomm='`.strip rescue nil)
|
|
1242
|
+
return 'fish' if parent&.include?('fish')
|
|
1243
|
+
return 'zsh' if parent&.include?('zsh')
|
|
1244
|
+
return 'bash' if parent&.include?('bash')
|
|
1245
|
+
return 'pwsh' if parent&.match?(/pwsh|powershell/i)
|
|
1246
|
+
|
|
1247
|
+
nil
|
|
1248
|
+
end
|
|
1249
|
+
|
|
1250
|
+
def shell_rc_file(shell)
|
|
1251
|
+
case shell
|
|
1252
|
+
when 'fish' then '~/.config/fish/config.fish'
|
|
1253
|
+
when 'zsh' then '~/.zshrc'
|
|
1254
|
+
when 'bash'
|
|
1255
|
+
# Prefer .bashrc, fall back to .bash_profile on macOS
|
|
1256
|
+
File.exist?(File.expand_path('~/.bashrc')) ? '~/.bashrc' : '~/.bash_profile'
|
|
1257
|
+
when 'pwsh'
|
|
1258
|
+
# PowerShell profile path from $PROFILE, or the standard location
|
|
1259
|
+
ENV["PROFILE"] || (Gem.win_platform? ?
|
|
1260
|
+
File.join(ENV["USERPROFILE"] || Dir.home, "Documents", "PowerShell", "Microsoft.PowerShell_profile.ps1") :
|
|
1261
|
+
File.join(Dir.home, ".config", "powershell", "Microsoft.PowerShell_profile.ps1"))
|
|
1262
|
+
end
|
|
1263
|
+
end
|
|
1264
|
+
|
|
1265
|
+
def init_snippet(shell, script_path, explicit_path, default_path)
|
|
1266
|
+
case shell
|
|
1267
|
+
when 'fish'
|
|
1268
|
+
fish_path_arg = explicit_path ? " --path '#{explicit_path}'" : " --path (if set -q TRY_PATH; echo \"$TRY_PATH\"; else; echo '#{default_path}'; end)"
|
|
1269
|
+
<<~FISH
|
|
1270
|
+
function try
|
|
1271
|
+
set -l out (/usr/bin/env ruby '#{script_path}' exec#{fish_path_arg} $argv 2>/dev/tty | string collect)
|
|
1272
|
+
if test $pipestatus[1] -eq 0
|
|
1273
|
+
eval $out
|
|
1274
|
+
else
|
|
1275
|
+
echo $out
|
|
1276
|
+
end
|
|
1277
|
+
end
|
|
1278
|
+
FISH
|
|
1279
|
+
when 'pwsh'
|
|
1280
|
+
ps_path_expr = if explicit_path
|
|
1281
|
+
"'#{explicit_path}'"
|
|
1282
|
+
else
|
|
1283
|
+
"$(if ($env:TRY_PATH) { $env:TRY_PATH } else { '#{default_path}' })"
|
|
1284
|
+
end
|
|
1285
|
+
<<~PWSH
|
|
1286
|
+
function try {
|
|
1287
|
+
$tryPath = #{ps_path_expr}
|
|
1288
|
+
$tempErr = [System.IO.Path]::GetTempFileName()
|
|
1289
|
+
$out = & ruby '#{script_path}' exec --path $tryPath @args 2>$tempErr
|
|
1290
|
+
if ($LASTEXITCODE -eq 0) {
|
|
1291
|
+
$out | Invoke-Expression
|
|
1292
|
+
} else {
|
|
1293
|
+
Get-Content $tempErr | Write-Host
|
|
1294
|
+
$out | Write-Output
|
|
1295
|
+
}
|
|
1296
|
+
Remove-Item $tempErr -ErrorAction SilentlyContinue
|
|
1297
|
+
}
|
|
1298
|
+
PWSH
|
|
1299
|
+
else # bash, zsh
|
|
1300
|
+
path_arg = explicit_path ? " --path '#{explicit_path}'" : " --path \"${TRY_PATH:-#{default_path}}\""
|
|
1301
|
+
<<~SH
|
|
1302
|
+
try() {
|
|
1303
|
+
local out
|
|
1304
|
+
out=$(/usr/bin/env ruby '#{script_path}' exec#{path_arg} "$@" 2>/dev/tty)
|
|
1305
|
+
if [ $? -eq 0 ]; then
|
|
1306
|
+
eval "$out"
|
|
1307
|
+
else
|
|
1308
|
+
echo "$out"
|
|
1309
|
+
fi
|
|
1310
|
+
}
|
|
1311
|
+
SH
|
|
1312
|
+
end
|
|
1313
|
+
end
|
|
1314
|
+
|
|
1210
1315
|
def cmd_cd!(args, tries_path, and_type, and_exit, and_keys, and_confirm)
|
|
1211
1316
|
if args.first == "clone"
|
|
1212
1317
|
return cmd_clone!(args[1..-1] || [], tries_path)
|
|
@@ -1427,6 +1532,9 @@ if __FILE__ == $0
|
|
|
1427
1532
|
when 'init'
|
|
1428
1533
|
cmd_init!(ARGV, tries_path)
|
|
1429
1534
|
exit 0
|
|
1535
|
+
when 'install'
|
|
1536
|
+
cmd_install!(ARGV, tries_path)
|
|
1537
|
+
exit 0
|
|
1430
1538
|
when 'exec'
|
|
1431
1539
|
sub = ARGV.first
|
|
1432
1540
|
case sub
|