From fb2be5c404889ced14cbce5dc327d5dc277f3b4c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 30 Mar 2020 18:08:47 +0200 Subject: [PATCH] Shell: Shorten $HOME to '~' in shell prompts The "\w" substitution in shell prompts now uses '~' to represent the user's home directory (technically, whatever $HOME contains.) --- Shell/main.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Shell/main.cpp b/Shell/main.cpp index c6b201c99c..bc8ef48dc9 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -88,9 +88,16 @@ static String prompt() case 'h': builder.append(g.hostname); break; - case 'w': - builder.append(g.cwd); + case 'w': { + String home_path = getenv("HOME"); + if (g.cwd.starts_with(home_path)) { + builder.append('~'); + builder.append(g.cwd.substring_view(home_path.length(), g.cwd.length() - home_path.length())); + } else { + builder.append(g.cwd); + } break; + } case 'p': builder.append(g.uid == 0 ? '#' : '$'); break;