[gnome-builder/wip/chergert/fix-rust-analyzer-on-host: 2/4] io: add helper for shell command line options




commit 275961f1870013bc494e5037bb6d64962f14ca00
Author: Christian Hergert <chergert redhat com>
Date:   Sun Dec 26 14:25:20 2021 -0800

    io: add helper for shell command line options

 src/libide/io/ide-shell.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 src/libide/io/ide-shell.h | 32 ++++++++++++++++++++++++++++++++
 src/libide/io/libide-io.h |  1 +
 src/libide/io/meson.build |  2 ++
 4 files changed, 82 insertions(+)
---
diff --git a/src/libide/io/ide-shell.c b/src/libide/io/ide-shell.c
new file mode 100644
index 000000000..12f9ecb9a
--- /dev/null
+++ b/src/libide/io/ide-shell.c
@@ -0,0 +1,47 @@
+/* ide-shell.c
+ *
+ * Copyright 2021 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "config.h"
+
+#include "ide-shell.h"
+
+gboolean
+ide_shell_supports_dash_c (const char *shell)
+{
+  if (shell == NULL)
+    return FALSE;
+
+  return strcmp (shell, "bash") == 0 || g_str_has_suffix (shell, "/bash") ||
+         strcmp (shell, "fish") == 0 || g_str_has_suffix (shell, "/fish") ||
+         strcmp (shell, "zsh") == 0 || g_str_has_suffix (shell, "/zsh") ||
+         strcmp (shell, "sh") == 0 || g_str_has_suffix (shell, "/sh");
+}
+
+gboolean
+ide_shell_supports_dash_login (const char *shell)
+{
+  if (shell == NULL)
+    return FALSE;
+
+  return strcmp (shell, "bash") == 0 || g_str_has_suffix (shell, "/bash") ||
+         strcmp (shell, "fish") == 0 || g_str_has_suffix (shell, "/fish") ||
+         strcmp (shell, "zsh") == 0 || g_str_has_suffix (shell, "/zsh") ||
+         strcmp (shell, "sh") == 0 || g_str_has_suffix (shell, "/sh");
+}
diff --git a/src/libide/io/ide-shell.h b/src/libide/io/ide-shell.h
new file mode 100644
index 000000000..ac086bae5
--- /dev/null
+++ b/src/libide/io/ide-shell.h
@@ -0,0 +1,32 @@
+/* ide-shell.h
+ *
+ * Copyright 2016-2019 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-core.h>
+
+G_BEGIN_DECLS
+
+IDE_AVAILABLE_IN_42
+gboolean ide_shell_supports_dash_c     (const char *shell);
+IDE_AVAILABLE_IN_42
+gboolean ide_shell_supports_dash_login (const char *shell);
+
+G_END_DECLS
diff --git a/src/libide/io/libide-io.h b/src/libide/io/libide-io.h
index dce1b643e..c83025e7f 100644
--- a/src/libide/io/libide-io.h
+++ b/src/libide/io/libide-io.h
@@ -36,6 +36,7 @@ G_BEGIN_DECLS
 #include "ide-persistent-map.h"
 #include "ide-pkcon-transfer.h"
 #include "ide-pty-intercept.h"
+#include "ide-shell.h"
 
 #undef IDE_IO_INSIDE
 
diff --git a/src/libide/io/meson.build b/src/libide/io/meson.build
index f48b3bd8d..7fa64065b 100644
--- a/src/libide/io/meson.build
+++ b/src/libide/io/meson.build
@@ -15,6 +15,7 @@ libide_io_public_headers = [
   'ide-persistent-map-builder.h',
   'ide-pkcon-transfer.h',
   'ide-pty-intercept.h',
+  'ide-shell.h',
   'libide-io.h',
 ]
 
@@ -38,6 +39,7 @@ libide_io_public_sources = [
   'ide-persistent-map-builder.c',
   'ide-pkcon-transfer.c',
   'ide-pty-intercept.c',
+  'ide-shell.c',
 ]
 
 libide_io_sources = libide_io_public_sources


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]