@@ -77,14 +77,40 @@ function icd() {
7777 esac
7878 done
7979 local icd_path=${IDE_ROOT}
80+
81+ # Determine the project to use
8082 if [ " ${icd_project} " != " " ]; then
83+ # Project explicitly specified
8184 icd_path=${icd_path} /${icd_project}
85+ elif [ " ${icd_workspace} " != " " ]; then
86+ # Workspace specified without project - infer project from current directory or IDE_HOME
87+ local current_project=" "
88+ local current_dir=" $( pwd) "
89+ if [[ " ${current_dir} " == " ${IDE_ROOT} " /* ]]; then
90+ # Extract project from current directory
91+ local relative_path=" ${current_dir# ${IDE_ROOT} / } "
92+ current_project=" ${relative_path%%/* } "
93+ elif [ " ${IDE_HOME} " != " " ] && [[ " ${IDE_HOME} " == " ${IDE_ROOT} " /* ]]; then
94+ # Fall back to extracting project from IDE_HOME
95+ local relative_path=" ${IDE_HOME# ${IDE_ROOT} / } "
96+ current_project=" ${relative_path%%/* } "
97+ fi
98+
99+ if [ " ${current_project} " != " " ]; then
100+ icd_path=${IDE_ROOT} /${current_project}
101+ elif [ " ${IDE_HOME} " != " " ]; then
102+ icd_path=${IDE_HOME}
103+ fi
82104 elif [ " ${IDE_HOME} " != " " ]; then
105+ # No project or workspace specified - use IDE_HOME
83106 icd_path=${IDE_HOME}
84107 fi
108+
109+ # Append workspace path if specified
85110 if [ " ${icd_workspace} " != " " ]; then
86111 icd_path=${icd_path} /workspaces/${icd_workspace}
87112 fi
113+
88114 cd " ${icd_path} " || return 1
89115 ide
90116 return
0 commit comments