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 new file mode 100644 index 0000000..4723b16 --- /dev/null +++ b/Shell/Config/ShellConfig.cs @@ -0,0 +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 required 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; + } + + 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/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/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/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 \ diff --git a/uninstall.sh b/uninstall.sh index 836ccc1..5d6a2aa 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -10,13 +10,15 @@ 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" + echo "[-] - No executable found at $BIN_PATH"discord fi if grep -Fxq "$BIN_PATH" /etc/shells; then