Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/components/terminal/terminalManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 16 additions & 4 deletions src/plugins/terminal/scripts/init-alpine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down