Skip to content

Commit 821b75b

Browse files
committed
fix(terminal): normalize acode open paths so folder name isn’t "."
1 parent 4158d37 commit 821b75b

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

src/components/terminal/terminalManager.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,8 @@ class TerminalManager {
627627

628628
// Convert proot path
629629
const fileUri = this.convertProotPath(path);
630-
// Extract folder/file name from path
631-
const name = path.split("/").filter(Boolean).pop() || "folder";
630+
// Extract folder/file name from normalized path
631+
const name = this.getPathDisplayName(path);
632632

633633
try {
634634
if (type === "folder") {
@@ -904,6 +904,28 @@ class TerminalManager {
904904
return convertedPath;
905905
}
906906

907+
/**
908+
* Get a stable display name from a filesystem path.
909+
* Handles trailing "." and ".." segments (e.g. "/a/b/." -> "b").
910+
* @param {string} path
911+
* @returns {string}
912+
*/
913+
getPathDisplayName(path) {
914+
if (!path) return "folder";
915+
916+
const normalized = [];
917+
for (const segment of String(path).split("/")) {
918+
if (!segment || segment === ".") continue;
919+
if (segment === "..") {
920+
if (normalized.length) normalized.pop();
921+
continue;
922+
}
923+
normalized.push(segment);
924+
}
925+
926+
return normalized.pop() || "folder";
927+
}
928+
907929
shouldConfirmTerminalClose() {
908930
const settings = appSettings?.value?.terminalSettings;
909931
if (settings && settings.confirmTabClose === false) {

src/plugins/terminal/scripts/init-alpine.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,27 @@ usage() {
8787
8888
get_abs_path() {
8989
local path="$1"
90-
local abs_path
91-
abs_path=$(realpath -- "$path" 2>/dev/null)
92-
if [[ $? -ne 0 ]]; then
93-
if [[ "$path" == /* ]]; then
90+
local abs_path=""
91+
92+
if command -v realpath >/dev/null 2>&1; then
93+
abs_path=$(realpath -- "$path" 2>/dev/null)
94+
fi
95+
96+
if [[ -z "$abs_path" ]]; then
97+
if [[ -d "$path" ]]; then
98+
abs_path=$(cd -- "$path" 2>/dev/null && pwd -P)
99+
elif [[ -e "$path" ]]; then
100+
local dir_name file_name
101+
dir_name=$(dirname -- "$path")
102+
file_name=$(basename -- "$path")
103+
abs_path="$(cd -- "$dir_name" 2>/dev/null && pwd -P)/$file_name"
104+
elif [[ "$path" == /* ]]; then
94105
abs_path="$path"
95106
else
96107
abs_path="$PWD/$path"
97108
fi
98109
fi
110+
99111
echo "$abs_path"
100112
}
101113

0 commit comments

Comments
 (0)