summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c10
-rw-r--r--src/shell.c42
-rw-r--r--src/shell.h6
3 files changed, 57 insertions, 1 deletions
diff --git a/main.c b/main.c
index 896ab88..25e7b0f 100644
--- a/main.c
+++ b/main.c
@@ -15,6 +15,7 @@
#include "src/packages.h"
#include "src/resolution.h"
#include "src/wm.h"
+#include "src/shell.h"
#include "src/cpu.h"
#include "src/gpu.h"
#include "src/memory.h"
@@ -200,6 +201,14 @@ int main(int argc, char *argv[]) {
lc++;
}
+ const char *shell = display_shell();
+ if (shell) {
+ printf("%s ", LOGO[lc]);
+ printf("%sShell%s: %s\n", color, reset, shell);
+ free((void *)shell);
+ lc++;
+ }
+
const char *cpu = display_cpu();
if (cpu) {
printf("%s ", LOGO[lc]);
@@ -228,7 +237,6 @@ int main(int argc, char *argv[]) {
// TODO:
// * libc
- // * シェル
// * 端末
// * ストレージ
diff --git a/src/shell.c b/src/shell.c
new file mode 100644
index 0000000..783ed98
--- /dev/null
+++ b/src/shell.c
@@ -0,0 +1,42 @@
+#include "shell.h"
+#include "common.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+const char *display_shell() {
+ char *shell = (char *)malloc(64 * sizeof(char));
+ if (shell == NULL) {
+ return NULL;
+ }
+
+ const char *ver;
+ const char *name = run_command_s("echo ${SHELL##*/}");
+
+ if (strncmp(name, "bash", strlen("bash")) == 0) {
+ ver = run_command_s("echo $BASH_VERSION");
+ } else if (strncmp(name, "ksh", strlen("ksh")) == 0) {
+ ver = run_command_s("echo $KSH_VERSION | sed 's/^.*v//' | sed 's/ .*$//'");
+ } else if (strncmp(name, "zsh", strlen("zsh")) == 0) {
+ ver = run_command_s("zsh --version | sed 's/ (.*$//' | sed 's/zsh //'");
+ } else if (strncmp(name, "yash", strlen("yash")) == 0) {
+ ver = run_command_s("LC_ALL=C yash --version | head -1 | "
+ "sed 's/Yet another shell, version //'");
+ } else if (strncmp(name, "tsch", strlen("tsch")) == 0) {
+ ver = run_command_s("tcsh --version | sed 's/tcsh //' | sed 's/ .*$//'");
+ } else {
+ ver = NULL;
+ }
+
+ if (ver != NULL) {
+ snprintf(shell, sizeof(shell), "%s %s", name, ver);
+ } else {
+ snprintf(shell, sizeof(shell), "%s", name);
+ }
+
+ free((void *)name);
+ if (ver != NULL) free((void *)ver);
+
+ return shell;
+}
diff --git a/src/shell.h b/src/shell.h
new file mode 100644
index 0000000..c52e9fe
--- /dev/null
+++ b/src/shell.h
@@ -0,0 +1,6 @@
+#ifndef SHELL_H
+#define SHELL_H
+
+const char *display_shell();
+
+#endif