diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 8cb546e92..3e2023a64 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -21,6 +21,7 @@ Release with new features and bugfixes: * https://github.com/devonfw/IDEasy/issues/637[#637]: Added option to disable updates * https://github.com/devonfw/IDEasy/issues/764[#764]: IDEasy not working properly in CMD * https://github.com/devonfw/IDEasy/issues/81[#81]: Implement Toolcommandlet for Kubernetes +* https://github.com/devonfw/IDEasy/issues/737[#737]: Adds cd command to ide shell * https://github.com/devonfw/IDEasy/issues/758[#758]: Create status commandlet * https://github.com/devonfw/IDEasy/issues/754[#754]: Again messages break processable command output @@ -33,7 +34,8 @@ Release with new features and bugfixes: * https://github.com/devonfw/IDEasy/issues/632[#632]: Add .editorconfig to settings workspaces * https://github.com/devonfw/IDEasy/issues/415[#415]: Added a message that will inform the user for what process he will need to enter his sudo-password * https://github.com/devonfw/IDEasy/issues/708[#708]: Open vscode in workspace path -* https://github.com/devonfw/IDEasy/issues/608[#608]: Enhanced error messages. Now logs missing command output and error messages +* https://github.com/devonfw/IDEasy/issues/608[#608]: Enhanced error messages. +Now logs missing command output and error messages * https://github.com/devonfw/IDEasy/issues/715[#715]: Show "cygwin is not supported" message for cygwin users * https://github.com/devonfw/IDEasy/issues/745[#745]: Maven install fails with NPE diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java index 6d4307297..a86301d52 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java @@ -1,6 +1,8 @@ package com.devonfw.tools.ide.commandlet; import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Iterator; import org.fusesource.jansi.AnsiConsole; @@ -79,13 +81,13 @@ public void run() { // TODO: implement TailTipWidgets, see: https://github.com/devonfw/IDEasy/issues/169 - String prompt = "ide> "; String rightPrompt = null; String line; AnsiConsole.systemInstall(); while (true) { try { + String prompt = context.getCwd() + "$ ide "; line = reader.readLine(prompt, rightPrompt, (MaskingCallback) null, null); line = line.trim(); if (line.equals("exit")) { @@ -129,9 +131,37 @@ private int runCommand(String args) { String[] arguments = args.split(" ", 0); CliArguments cliArgs = new CliArguments(arguments); cliArgs.next(); + + if ("cd".equals(arguments[0])) { + return changeDirectory(cliArgs); + } + return ((AbstractIdeContext) this.context).run(cliArgs); } + private int changeDirectory(CliArguments cliArgs) { + if (!cliArgs.hasNext()) { + Path homeDir = this.context.getUserHome(); + context.setCwd(homeDir, context.getWorkspaceName(), context.getIdeHome()); + return 0; + } + + String targetDir = String.valueOf(cliArgs.next()); + Path path = Paths.get(targetDir); + + // If the given path is relative, resolve it relative to the current directory + if (!path.isAbsolute()) { + path = context.getCwd().resolve(targetDir).normalize(); + } + + if (context.getFileAccess().isExpectedFolder(path)) { + context.setCwd(path, context.getWorkspaceName(), context.getIdeHome()); + return 0; + } else { + return 1; + } + } + /** * @param argument the current {@link CliArgument} (position) to match. * @param commandlet the potential {@link Commandlet} to match.