Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions try.rb
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,6 @@ def generate_clone_directory_name(git_uri, custom_name = nil)
return nil unless parsed

date_prefix = Time.now.strftime("%Y-%m-%d")
host_part = parsed[:host].split('.').first # github.com -> github
"#{date_prefix}-#{parsed[:user]}-#{parsed[:repo]}"
end

Expand All @@ -796,9 +795,9 @@ def is_git_uri?(arg)
arg.match?(%r{^(https?://|git@)}) || arg.include?('github.com') || arg.include?('gitlab.com') || arg.end_with?('.git')
end

command = ARGV.shift

tries_path = extract_option_with_value!(ARGV, '--path') || TrySelector::TRY_PATH

command = ARGV.shift
tries_path = File.expand_path(tries_path)

# Test-only flags (undocumented; aid acceptance tests)
Expand Down Expand Up @@ -873,7 +872,15 @@ def cmd_init!(args, tries_path)
bash_or_zsh_script = <<~SHELL
try() {
script_path='#{script_path}'
cmd=$(/usr/bin/env ruby "$script_path" cd#{path_arg} "$@" 2>/dev/tty)
# Check if first argument is a known command
case "$1" in
clone|worktree|init)
cmd=$(/usr/bin/env ruby "$script_path"#{path_arg} "$@" 2>/dev/tty)
;;
*)
cmd=$(/usr/bin/env ruby "$script_path" cd#{path_arg} "$@" 2>/dev/tty)
;;
esac
rc=$?
if [ $rc -eq 0 ]; then
case "$cmd" in
Expand All @@ -889,7 +896,13 @@ def cmd_init!(args, tries_path)
fish_script = <<~SHELL
function try
set -l script_path "#{script_path}"
set -l cmd (/usr/bin/env ruby "$script_path" cd#{path_arg} $argv 2>/dev/tty | string collect)
# Check if first argument is a known command
switch $argv[1]
case clone worktree init
set -l cmd (/usr/bin/env ruby "$script_path"#{path_arg} $argv 2>/dev/tty | string collect)
case '*'
set -l cmd (/usr/bin/env ruby "$script_path" cd#{path_arg} $argv 2>/dev/tty | string collect)
end
set -l rc $status
if test $rc -eq 0
if string match -r ' && ' -- $cmd
Expand Down