Skip to content

Commit 05d506b

Browse files
author
Jonathan D.A. Jewell
committed
nushell brings headaches
1 parent fb8ef90 commit 05d506b

7 files changed

Lines changed: 161 additions & 143 deletions

File tree

scripts/install-hooks.nu

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def main [] {
2+
let hook_dir = ".git/hooks"
3+
let target_hook = ($hook_dir | path join "post-checkout")
4+
print "Ensuring .git/hooks directory exists..."
5+
^mkdir -p $hook_dir
6+
print "Creating universal post-checkout launcher in .git/hooks..."
7+
let bash_hook_content = "#!/bin/bash\n# Universal launcher for post-checkout hook (safer-perms)\n\nif command -v nu >/dev/null 2>&1; then\n HOOK_SCRIPT=\"scripts/safer-perms.nu\"\n if [ -f \"$HOOK_SCRIPT\" ]; then\n echo \"Executing Nushell-based post-checkout hook (safer-perms)...\"\n nu --file \"$HOOK_SCRIPT\"\n fi\nelse\n echo \"Info: Nushell (\'nu\') not found. Skipping dynamic permission setting.\"\nfi\n\nexit 0"
8+
$bash_hook_content | save $target_hook --force
9+
print "Making hook executable..."
10+
^chmod +x $target_hook
11+
print "---"
12+
print "SUCCESS: Post-checkout hook installed. The hook will run after 'git checkout' or 'git clone'."
13+
}
14+
main

scripts/safer-perms.nu

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env nu
2+
3+
# Define standard permissions for source/text files (read/write by owner)
4+
let rw_perms = "u+rw,go-w"
5+
# Define executable permissions (read/write/execute by owner)
6+
let rwx_perms = "u+rwx,go-w,go+r"
7+
8+
print "Setting default read/write permissions and removing execute flags..."
9+
# ... (Your full Nushell logic for chmod goes here) ...
10+
# Ensure the final script is executable itself
11+
^chmod +x scripts/safer-perms.nu
12+
13+
print "Permissions dynamic enforcement complete."

src/config_store/config_store.adb

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,58 @@
1-
-- src/config_store/config_store.adb
2-
with Ada.Text_IO;
3-
use Ada.Text_IO;
1+
with Ada.Environment_Variables;
2+
with Ada.Strings.Unbounded;
3+
with Ada.Directories;
4+
with Ada.Text_IO;
45

56
package body Config_Store is
6-
-- NOTE: This body requires GNAT FFI bindings to the LMDB C library.
7-
-- For v0.0, it contains stubs to demonstrate the required structure.
7+
8+
use Ada.Environment_Variables;
9+
use Ada.Strings.Unbounded;
10+
11+
ENV_VAR_NAME : constant String := "MODSHELLS_CONFIG_PATH";
812

9-
procedure Initialize_Store is
10-
begin
11-
Put_Line("LMDB: Initializing transactional configuration store.");
12-
-- Actual LMDB environment setup goes here.
13-
end Initialize_Store;
13+
function Get_Home_Directory return String is
14+
begin
15+
declare
16+
Home_Path_Ptr : constant String_Access := Value("HOME");
17+
begin
18+
if Home_Path_Ptr /= null then
19+
return Home_Path_Ptr.all;
20+
else
21+
return Ada.Directories.Current_Directory;
22+
end if;
23+
exception
24+
when Name_Error =>
25+
return Ada.Directories.Current_Directory;
26+
when others =>
27+
raise;
28+
end;
29+
end Get_Home_Directory;
1430

15-
procedure Store_Backup(
16-
Shell_Name : in Shell_Manager.Shell_Type;
17-
File_Path : in String;
18-
Content : in String)
19-
is
20-
begin
21-
Put_Line("LMDB: Storing backup of " & File_Path & " (" & Integer'Image(Content'Length) & " bytes).");
22-
-- Actual LMDB transaction and key-value write goes here.
23-
end Store_Backup;
31+
DEFAULT_ROOT_PATH : constant String :=
32+
Get_Home_Directory & Ada.Directories.Separator & ".config/nushell/modshells";
2433

25-
function Retrieve_Backup(Shell_Name : Shell_Manager.Shell_Type) return String is
26-
begin
27-
return "LMDB Backup Content (Placeholder)";
28-
end Retrieve_Backup;
34+
function Get_Modshell_Root_Path return String is
35+
Path_Value : String := "";
36+
Env_Value_Ptr : String_Access;
37+
begin
38+
-- 1. Check for the environment variable (Accessibility & Interoperability)
39+
Env_Value_Ptr := Value(ENV_VAR_NAME);
2940

30-
procedure Rollback_To_Last_State(Shell_Name : Shell_Manager.Shell_Type) is
31-
begin
32-
Put_Line("LMDB: Executing Rollback for " & Shell_Manager.To_String(Shell_Name));
33-
-- Retrieve backup content and overwrite the live file.
34-
end Rollback_To_Last_State;
41+
if Env_Value_Ptr /= null then
42+
Path_Value := Env_Value_Ptr.all;
43+
else
44+
-- 2. Fall back to the calculated default path (Dependability)
45+
Path_Value := DEFAULT_ROOT_PATH;
46+
end if;
47+
48+
return Path_Value;
49+
50+
exception
51+
when others =>
52+
Ada.Text_IO.Put_Line("Error retrieving config path. Raising exception.");
53+
raise;
54+
end Get_Modshell_Root_Path;
55+
56+
-- ... Placeholder for other functions in Config_Store package body ...
3557

36-
end Config_Store;
58+
end Config_Store;

src/config_store/config_store.ads

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
-- src/config_store/config_store.ads
2-
-- Handles LMDB interaction for transactional backup and state logging.
32
package Config_Store is
4-
5-
-- Initializes the LMDB environment and opens the configuration map.
6-
procedure Initialize_Store;
7-
8-
-- Stores a full configuration file backup transactionally.
9-
procedure Store_Backup(
10-
Shell_Name : in Shell_Manager.Shell_Type;
11-
File_Path : in String;
12-
Content : in String);
13-
14-
-- Retrieves the last stored backup content for a shell.
15-
function Retrieve_Backup(Shell_Name : Shell_Manager.Shell_Type) return String;
16-
17-
-- Rollback procedure (Future TUI/CLI command)
18-
procedure Rollback_To_Last_State(Shell_Name : Shell_Manager.Shell_Type);
19-
20-
end Config_Store;
3+
-- ... other config definitions ...
4+
5+
function Get_Modshell_Root_Path return String;
6+
7+
end Config_Store;

src/main/modshells.adb

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1-
-- src/main/modular_shells.adb
2-
with Ada.Text_IO;
31
with Shell_Manager;
4-
use Ada.Text_IO;
5-
use Shell_Manager;
2+
with Config_Store;
3+
with Ada.Text_IO;
64

75
procedure Modshells is
8-
-- Placeholders for the main execution loop (v0.0)
9-
Shells : Shell_List := Detect_Shells;
6+
7+
Config_Path : constant String := Config_Store.Get_Modshell_Root_Path;
8+
109
begin
11-
Put_Line("Modshells Utility (v0.0) - Safety First.");
12-
Put_Line("Detected Shells:");
10+
Ada.Text_IO.Put_Line("Starting modshells initialisation...");
11+
Ada.Text_IO.Put_Line("Configuration path: " & Config_Path);
12+
13+
-- Idempotent creation of directories (core, tools, misc, os, ui)
14+
Shell_Manager.Create_Modshell_Directories(
15+
Root_Path => Config_Path
16+
);
1317

14-
for I in Shells'Range loop
15-
Put_Line(" - " & To_String(Shells(I).Name) & " (" & Shell_Status'Image(Shells(I).Status) & ")");
16-
end loop;
18+
Ada.Text_IO.Put_Line("Modular directories created idempotently.");
1719

18-
-- NOTE: Full installation and modularisation logic will be implemented here in v0.1
19-
-- The system currently only lists and confirms the safety framework.
20-
21-
end Modshells;
20+
-- [Continue with application logic, such as shell detection, etc.]
21+
22+
exception
23+
when others =>
24+
declare
25+
Error_Msg : constant String :=
26+
"FATAL ERROR: Modshells failed during initial setup.";
27+
begin
28+
Ada.Text_IO.Put_Line(Error_Msg);
29+
raise;
30+
end;
31+
end Modshells;
Lines changed: 24 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,29 @@
1-
-- src/shell_manager/shell_manager.adb
2-
with GNAT.OS_Lib;
3-
with Ada.Text_IO;
4-
with Config_Store; -- Required for LMDB calls
5-
use Ada.Text_IO;
1+
-- File: modshells/src/main/modshells.adb
62

7-
package body Shell_Manager is
3+
with Shell_Manager; -- 1. Import the package
4+
-- ... other necessary packages (e.g., Ada.Strings.Unbounded) ...
85

9-
function Detect_Shells return Shell_List is
10-
-- Simplification for v0.0: Return a known list.
11-
Shell_List_Data : constant Shell_List := (
12-
1 => (Name => Bash, Status => Installed),
13-
2 => (Name => Zsh, Status => Installed),
14-
3 => (Name => Nushell, Status => Installed),
15-
4 => (Name => Fish, Status => Can_Be_Installed),
16-
5 => (Name => Pwsh, Status => Not_Installed)
17-
);
18-
begin
19-
return Shell_List_Data;
20-
end Detect_Shells;
21-
22-
function To_String(Shell : Shell_Type) return String is
23-
begin
24-
-- Strips the leading parenthesis from the Enum's image ('(Bash)' -> 'Bash')
25-
return Shell_Type'Image(Shell)(2..Shell_Type'Image(Shell)'Last - 1);
26-
end To_String;
6+
procedure Modshells is
7+
8+
-- NOTE: This path would ideally be derived from environment variables
9+
-- or configuration settings managed by your config_store package.
10+
-- For this example, we use a placeholder path:
11+
Modshell_Root_Path : constant String :=
12+
"~/.config/nushell/modshells";
2713

28-
function Is_Modularized (Shell : Shell_Type) return Boolean is
29-
-- v0.0 Implementation: Check for a placeholder string in the config file.
30-
Config_File_Path : constant String :=
31-
GNAT.OS_Lib.Get_Environment_Variable("HOME") & "/." & To_String(Shell) & "rc";
32-
33-
-- This is the unique source string we will inject into the main config file.
34-
Source_Check_String : constant String := "### MODULAR_SHELLS_ROOT_SOURCE ###";
35-
36-
-- NOTE: The full implementation requires reading the file content and checking for Source_Check_String.
37-
begin
38-
Put_Line("Safety Check: Checking if " & Config_File_Path & " is already modularised...");
39-
-- In v0.0, we always return false to test the modularisation logic.
40-
return False;
41-
end Is_Modularized;
14+
begin
15+
-- [Application Initialisation Logic]
4216

43-
procedure Modularise_Config(Shell : Shell_Type) is
44-
use Config_Store; -- Use the LMDB package
45-
begin
46-
if Is_Modularized(Shell) then
47-
Put_Line("Config for " & To_String(Shell) & " already modularised. Exiting idempotently.");
48-
return;
49-
end if;
50-
51-
-- 1. Show Config Plan (User confirmation needed)
52-
-- Show_Config_Plan(Shell, ...); -- Implemented in v0.1
53-
54-
-- 2. Backup using LMDB (LMDB/Config_Store procedure call)
55-
-- Backup_File(Shell);
56-
57-
-- 3. Create directories (idempotent creation logic)
58-
59-
-- 4. Inject source commands (idempotent injection logic)
60-
61-
Put_Line("Modularisation stub complete for " & To_String(Shell) & ". (LMDB calls skipped in v0.0)");
62-
63-
end Modularise_Config;
17+
-- 2. Call the new idempotent directory creation function.
18+
Shell_Manager.Create_Modshell_Directories(
19+
Root_Path => Modshell_Root_Path
20+
);
21+
22+
-- [Rest of the application logic]
6423

65-
end Shell_Manager;
24+
exception
25+
when others =>
26+
-- Implement robust error handling (Dependability priority)
27+
-- perhaps using your config_store or logging utilities here.
28+
raise;
29+
end Modshells;
Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
-- src/shell_manager/shell_manager.ads
22
-- Handles shell detection, idempotency checking, and high-level configuration logic.
33
package Shell_Manager is
4-
5-
type Shell_Type is (Bash, Dash, Fish, Ion, Nushell, Tcsh, Zsh, Oils, Pwsh, Ksh);
6-
type Shell_Status is (Installed, Not_Installed, Can_Be_Installed);
7-
8-
type Shell_Info is record
9-
Name : Shell_Type;
10-
Status : Shell_Status;
11-
end record;
12-
13-
type Shell_List is array (Positive range <>) of Shell_Info;
14-
15-
function Detect_Shells return Shell_List;
16-
-- Stub: Returns a fixed list for v0.0.
4+
5+
type Shell_Type is (Bash, Dash, Fish, Ion, Nushell, Tcsh, Zsh, Oils, Pwsh, Ksh);
6+
type Shell_Status is (Installed, Not_Installed, Can_Be_Installed);
7+
8+
type Shell_Info is record
9+
Name : Shell_Type;
10+
Status : Shell_Status;
11+
end record;
12+
13+
type Shell_List is array (Positive range <>) of Shell_Info;
14+
15+
function Detect_Shells return Shell_List;
16+
-- Stub: Returns a fixed list for v0.0.
1717

18-
function To_String(Shell : Shell_Type) return String;
19-
20-
-- Idempotency Check (Rhodium Standard requirement)
21-
function Is_Modularized (Shell : Shell_Type) return Boolean;
22-
-- Checks if the shell's config file (.bashrc, etc.) already sources the modular directories.
23-
24-
procedure Modularise_Config(Shell : Shell_Type);
25-
-- Safe procedure that performs backup, directory creation, and source injection.
18+
function To_String(Shell : Shell_Type) return String;
19+
20+
------------------------------------------------------------------------
21+
-- Configuration and Idempotency
22+
------------------------------------------------------------------------
23+
24+
-- **NEW PROCEDURE FOR DIRECTORY CREATION**
25+
procedure Create_Modshell_Directories (Root_Path : in String);
26+
-- Idempotently creates the required modular shell directories (core, tools, misc, os, ui).
27+
28+
-- Idempotency Check (Rhodium Standard requirement)
29+
function Is_Modularized (Shell : Shell_Type) return Boolean;
30+
-- Checks if the shell's config file (.bashrc, etc.) already sources the modular directories.
31+
32+
procedure Modularise_Config(Shell : Shell_Type);
33+
-- Safe procedure that performs backup, directory creation, and source injection.
2634

2735
end Shell_Manager;

0 commit comments

Comments
 (0)