diff --git a/src/components/terminal/terminalManager.js b/src/components/terminal/terminalManager.js index 1a2e7fa18..87b71d64f 100644 --- a/src/components/terminal/terminalManager.js +++ b/src/components/terminal/terminalManager.js @@ -627,8 +627,8 @@ class TerminalManager { // Convert proot path const fileUri = this.convertProotPath(path); - // Extract folder/file name from path - const name = path.split("/").filter(Boolean).pop() || "folder"; + // Extract folder/file name from normalized path + const name = this.getPathDisplayName(path); try { if (type === "folder") { @@ -904,6 +904,28 @@ class TerminalManager { return convertedPath; } + /** + * Get a stable display name from a filesystem path. + * Handles trailing "." and ".." segments (e.g. "/a/b/." -> "b"). + * @param {string} path + * @returns {string} + */ + getPathDisplayName(path) { + if (!path) return "folder"; + + const normalized = []; + for (const segment of String(path).split("/")) { + if (!segment || segment === ".") continue; + if (segment === "..") { + if (normalized.length) normalized.pop(); + continue; + } + normalized.push(segment); + } + + return normalized.pop() || "folder"; + } + shouldConfirmTerminalClose() { const settings = appSettings?.value?.terminalSettings; if (settings && settings.confirmTabClose === false) { diff --git a/src/plugins/terminal/scripts/init-alpine.sh b/src/plugins/terminal/scripts/init-alpine.sh index 73e01ed21..88c071fd1 100644 --- a/src/plugins/terminal/scripts/init-alpine.sh +++ b/src/plugins/terminal/scripts/init-alpine.sh @@ -87,15 +87,27 @@ usage() { get_abs_path() { local path="$1" - local abs_path - abs_path=$(realpath -- "$path" 2>/dev/null) - if [[ $? -ne 0 ]]; then - if [[ "$path" == /* ]]; then + local abs_path="" + + if command -v realpath >/dev/null 2>&1; then + abs_path=$(realpath -- "$path" 2>/dev/null) + fi + + if [[ -z "$abs_path" ]]; then + if [[ -d "$path" ]]; then + abs_path=$(cd -- "$path" 2>/dev/null && pwd -P) + elif [[ -e "$path" ]]; then + local dir_name file_name + dir_name=$(dirname -- "$path") + file_name=$(basename -- "$path") + abs_path="$(cd -- "$dir_name" 2>/dev/null && pwd -P)/$file_name" + elif [[ "$path" == /* ]]; then abs_path="$path" else abs_path="$PWD/$path" fi fi + echo "$abs_path" }