소스 검색

Shell: Add support for showing current time in prompt with "\{t|T|@}"

Adam Harald Jørgensen 1 년 전
부모
커밋
e40955e9c6
1개의 변경된 파일10개의 추가작업 그리고 0개의 파일을 삭제
  1. 10 0
      Userland/Shell/Shell.cpp

+ 10 - 0
Userland/Shell/Shell.cpp

@@ -19,6 +19,7 @@
 #include <AK/StringBuilder.h>
 #include <AK/TemporaryChange.h>
 #include <AK/URL.h>
+#include <LibCore/DateTime.h>
 #include <LibCore/DirIterator.h>
 #include <LibCore/Event.h>
 #include <LibCore/EventLoop.h>
@@ -129,6 +130,15 @@ DeprecatedString Shell::prompt() const
         } else if (lexer.consume_specific('p')) {
             builder.append(uid == 0 ? '#' : '$');
 
+        } else if (lexer.consume_specific('t')) {
+            builder.append(Core::DateTime::now().to_deprecated_string("%H:%M:%S"sv));
+
+        } else if (lexer.consume_specific('T')) {
+            builder.append(Core::DateTime::now().to_deprecated_string("%I:%M:%S"sv));
+
+        } else if (lexer.consume_specific('@')) {
+            builder.append(Core::DateTime::now().to_deprecated_string("%I:%M %p"sv));
+
         } else if (lexer.consume_specific('j')) {
             builder.appendff("{}", jobs.size());