mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-23 04:55:15 +00:00
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.)
This commit is contained in:
parent
012a4eb0b5
commit
fb2be5c404
Notes:
sideshowbarker
2024-07-19 08:02:52 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/fb2be5c4048
1 changed files with 9 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue