Skip to content

Commit 3243603

Browse files
maybeecjan-vcapgeminihohwille
authored
#1601: icd -w infers project from current directory (#1604)
Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com> Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com>
1 parent 1575e9a commit 3243603

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Release with new features and bugfixes:
2121
* https://github.com/devonfw/IDEasy/issues/1560[#1560]: Enable trace logging in IDEasy setup script
2222
* https://github.com/devonfw/IDEasy/issues/1586[#1586]: Use BASH_PATH when set before searching in registry or PATH
2323
* https://github.com/devonfw/IDEasy/issues/1564[#1564]: Print path to git bash to IDEasy log
24+
* https://github.com/devonfw/IDEasy/issues/1601[#1601]: icd command failing with -w
2425
* https://github.com/devonfw/IDEasy/issues/1599[#1599]: NullPointerException if Repository-Config-Variable "active" is not present
2526
* https://github.com/devonfw/IDEasy/issues/1561[#1561]: IDEasy can not handle BASH_PATH variable properly
2627
* https://github.com/devonfw/IDEasy/issues/1608[#1608]: Add git and bash location to status commandlet

cli/src/main/package/functions

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)