From 7eeb6839596122b5f4662f7c385d3537124600ed Mon Sep 17 00:00:00 2001 From: onihilist Date: Tue, 6 May 2025 17:10:27 +0200 Subject: [PATCH 1/3] feat in progress: configuration file --- Shell/Config/ShellConfig.cs | 12 ++++++++++++ install.sh | 3 +++ 2 files changed, 15 insertions(+) create mode 100644 Shell/Config/ShellConfig.cs diff --git a/Shell/Config/ShellConfig.cs b/Shell/Config/ShellConfig.cs new file mode 100644 index 0000000..551ba15 --- /dev/null +++ b/Shell/Config/ShellConfig.cs @@ -0,0 +1,12 @@ +namespace NShell.Shell.Config; + +public class ShellConfig +{ + public int HistoryExpirationTime { get; set; } + public int HistoryMaxStorage { get; set; } + + public static void CheckHistoryConfiguration() + { + + } +} \ No newline at end of file diff --git a/install.sh b/install.sh index 003a809..5e264aa 100755 --- a/install.sh +++ b/install.sh @@ -31,17 +31,20 @@ N_SHELL_DIR="$USER_PROFILE/.nshell" HISTORY_FILE="$N_SHELL_DIR/.nhistory" THEMES_DIR="$N_SHELL_DIR/themes" PLUGINS_DIR="$N_SHELL_DIR/plugins" +CONFIG_FILE="$N_SHELL_DIR/nshell.conf.json" echo "[*] - Creating directories/files if they don't exist..." mkdir -p "$THEMES_DIR" mkdir -p "$PLUGINS_DIR" touch "$HISTORY_FILE" +curl -L "https://gist.githubusercontent.com/onihilist/8bf7548dc7478f1b6af2db4bdc0c668d/raw/28f46aa5ebcb27b4f0edb302e2ff4347f49a2f83/nshell.conf.json" -o $CONFIG_FILE echo "[+] - Directories/Files created or already exist: " echo " - $THEMES_DIR" echo " - $PLUGINS_DIR" echo " - $HISTORY_FILE" +echo " - $CONFIG_FILE" echo "[*] - Compiling NShell..." dotnet publish NShell.csproj \ From 4df44ec9a8f9d600a76a3bf2b2d5a31879e4f407 Mon Sep 17 00:00:00 2001 From: onihilist Date: Wed, 7 May 2025 13:55:07 +0200 Subject: [PATCH 2/3] feat: config file & enhanced uninstaller --- Shell/Config/ShellConfig.cs | 46 +++++++++++++++++++++++++++++-- Shell/History/HistoryManager.cs | 2 +- Shell/Keyboard/KeyboardHandler.cs | 5 ++++ Shell/Themes/ThemeLoader.cs | 5 ---- uninstall.sh | 6 ++-- 5 files changed, 54 insertions(+), 10 deletions(-) diff --git a/Shell/Config/ShellConfig.cs b/Shell/Config/ShellConfig.cs index 551ba15..f229107 100644 --- a/Shell/Config/ShellConfig.cs +++ b/Shell/Config/ShellConfig.cs @@ -1,12 +1,54 @@ + +using System.Text.Json.Nodes; + namespace NShell.Shell.Config; public class ShellConfig { public int HistoryExpirationTime { get; set; } public int HistoryMaxStorage { get; set; } + public string SelectedTheme { get; set; } + + public static ShellConfig? LoadConfig() + { + var configFile = Directory.GetFiles($"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/.nshell", "nshell.conf.json"); + + foreach (var filePath in configFile) + { + string json = File.ReadAllText(filePath); + JsonNode? data = JsonNode.Parse(json); + JsonNode? historyNode = data?["configuration"]?["nshell"]?["history"]?[0]; + JsonNode? themeNode = data?["configuration"]?["nshell"]?["theme"]?[0]; + + if (historyNode != null && themeNode != null) + { + string expiration = historyNode["expiration_time"]?.ToString() ?? "0d"; + int days = ParseExpirationTime(expiration); + + return new ShellConfig + { + HistoryExpirationTime = days, + HistoryMaxStorage = historyNode["max_storage"]?.GetValue() ?? 0, + SelectedTheme = themeNode["selected_theme"]?.ToString() ?? "default" + }; + } + } + + return null; + } - public static void CheckHistoryConfiguration() + private static int ParseExpirationTime(string expiration) { - + if (expiration.EndsWith("w") && int.TryParse(expiration[..^1], out int weeks)) + { + return weeks*168; + } if (expiration.EndsWith("d") && int.TryParse(expiration[..^1], out int days)) + { + return days*24; + } if (expiration.EndsWith("h") && int.TryParse(expiration[..^1], out int hours)) + { + return hours; + } + return 0; } } \ No newline at end of file diff --git a/Shell/History/HistoryManager.cs b/Shell/History/HistoryManager.cs index 67de3a0..171aabd 100644 --- a/Shell/History/HistoryManager.cs +++ b/Shell/History/HistoryManager.cs @@ -18,7 +18,7 @@ public class HistoryManager public HistoryManager(string? path = null) { - _historyPath = path ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nshell/.history"); + _historyPath = path ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nshell/.nhistory"); Load(); } diff --git a/Shell/Keyboard/KeyboardHandler.cs b/Shell/Keyboard/KeyboardHandler.cs index 9f5c269..d491b3a 100644 --- a/Shell/Keyboard/KeyboardHandler.cs +++ b/Shell/Keyboard/KeyboardHandler.cs @@ -28,6 +28,11 @@ public static void Handler(HistoryManager history, ShellContext context, Command if (key.Key == ConsoleKey.Enter) { + if (inputBuffer.Trim() != "") + { + history.Add(inputBuffer); + history.Save(); + } Console.WriteLine(); break; } diff --git a/Shell/Themes/ThemeLoader.cs b/Shell/Themes/ThemeLoader.cs index 4e89d84..3662a2f 100644 --- a/Shell/Themes/ThemeLoader.cs +++ b/Shell/Themes/ThemeLoader.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text.Json; using System.Text.Json.Nodes; namespace NShell.Shell.Themes diff --git a/uninstall.sh b/uninstall.sh index 836ccc1..c00fe6c 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -10,11 +10,13 @@ chsh -s /bin/bash || { exit 1 } +USER_PROFILE=$(eval echo ~$USER) +N_SHELL_DIR="$USER_PROFILE/.nshell" BIN_PATH="/usr/local/bin/nshell" if [ -f "$BIN_PATH" ]; then - echo "[*] - Removing $BIN_PATH..." - sudo rm "$BIN_PATH" + echo "[*] - Removing $BIN_PATH & related folders/files..." + sudo rm -rf "$BIN_PATH" "$N_SHELL_DIR" else echo "[-] - No executable found at $BIN_PATH" fi From eb3db38449b5b14e7da702bb8010fec0688d731a Mon Sep 17 00:00:00 2001 From: onihilist Date: Fri, 19 Sep 2025 13:26:17 +0200 Subject: [PATCH 3/3] feat: config file in progress --- Shell/Commands/CommandLoader.cs | 3 --- Shell/Config/ShellConfig.cs | 2 +- Shell/Plugin/PluginLoader.cs | 2 -- uninstall.sh | 2 +- 4 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Shell/Commands/CommandLoader.cs b/Shell/Commands/CommandLoader.cs index 3d57e91..be3bf50 100644 --- a/Shell/Commands/CommandLoader.cs +++ b/Shell/Commands/CommandLoader.cs @@ -16,7 +16,6 @@ public static class CommandLoader public static void RefreshCommands() { var paths = Environment.GetEnvironmentVariable("PATH")?.Split(':') ?? Array.Empty(); - var newCommands = new HashSet(); foreach (var path in paths) @@ -46,9 +45,7 @@ public static void RefreshCommands() AnsiConsole.MarkupLine($"[[[red]-[/]]] - Error accessing directory {path}: [bold yellow]{ex.Message}[/]"); } } - HashSet availableCommands = newCommands; AnsiConsole.MarkupLine($"[[[green]+[/]]] - Refreshed command list. Found {availableCommands.Count} new commands."); } - } diff --git a/Shell/Config/ShellConfig.cs b/Shell/Config/ShellConfig.cs index f229107..4723b16 100644 --- a/Shell/Config/ShellConfig.cs +++ b/Shell/Config/ShellConfig.cs @@ -7,7 +7,7 @@ public class ShellConfig { public int HistoryExpirationTime { get; set; } public int HistoryMaxStorage { get; set; } - public string SelectedTheme { get; set; } + public required string SelectedTheme { get; set; } public static ShellConfig? LoadConfig() { diff --git a/Shell/Plugin/PluginLoader.cs b/Shell/Plugin/PluginLoader.cs index 4ae2d3d..013ef46 100644 --- a/Shell/Plugin/PluginLoader.cs +++ b/Shell/Plugin/PluginLoader.cs @@ -51,7 +51,5 @@ public void LoadPlugins() Directory.CreateDirectory(PluginFolderPath); } } - } - } diff --git a/uninstall.sh b/uninstall.sh index c00fe6c..5d6a2aa 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -18,7 +18,7 @@ if [ -f "$BIN_PATH" ]; then echo "[*] - Removing $BIN_PATH & related folders/files..." sudo rm -rf "$BIN_PATH" "$N_SHELL_DIR" else - echo "[-] - No executable found at $BIN_PATH" + echo "[-] - No executable found at $BIN_PATH"discord fi if grep -Fxq "$BIN_PATH" /etc/shells; then