Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Shell/Commands/CommandLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public static class CommandLoader
public static void RefreshCommands()
{
var paths = Environment.GetEnvironmentVariable("PATH")?.Split(':') ?? Array.Empty<string>();

var newCommands = new HashSet<string>();

foreach (var path in paths)
Expand Down Expand Up @@ -46,9 +45,7 @@ public static void RefreshCommands()
AnsiConsole.MarkupLine($"[[[red]-[/]]] - Error accessing directory {path}: [bold yellow]{ex.Message}[/]");
}
}

HashSet<string> availableCommands = newCommands;
AnsiConsole.MarkupLine($"[[[green]+[/]]] - Refreshed command list. Found {availableCommands.Count} new commands.");
}

}
54 changes: 54 additions & 0 deletions Shell/Config/ShellConfig.cs
Original file line number Diff line number Diff line change
@@ -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<int>() ?? 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;
}
}
2 changes: 1 addition & 1 deletion Shell/History/HistoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
5 changes: 5 additions & 0 deletions Shell/Keyboard/KeyboardHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions Shell/Plugin/PluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class PluginLoader
{
private string PluginFolderPath { get; set; } = $"/home/{Environment.UserName}/.nshell/plugins";
public string[] PluginList { get; set; }

Check warning on line 13 in Shell/Plugin/PluginLoader.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'PluginList' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public int NumberOfPlugins { get; set; }

public static PluginLoader Instance { get; private set; } = null!;
Expand Down Expand Up @@ -51,7 +51,5 @@
Directory.CreateDirectory(PluginFolderPath);
}
}

}

}
5 changes: 0 additions & 5 deletions Shell/Themes/ThemeLoader.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
8 changes: 5 additions & 3 deletions uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading