diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..eeaa504 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,25 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Build Go project + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.25.6' + + - name: Build + run: go build -v ./... diff --git a/.gitignore b/.gitignore index 0023a53..fc4f7f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,2 @@ -.DS_Store -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc +.build +dotkeeper diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 21c0262..0000000 --- a/LICENSE +++ /dev/null @@ -1,10 +0,0 @@ -The MIT License (MIT) - -Copyright © 2025 StikyPiston - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..c70f107 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright © 2026 StikyPiston + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the “Software”), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Package.swift b/Package.swift deleted file mode 100644 index a984366..0000000 --- a/Package.swift +++ /dev/null @@ -1,15 +0,0 @@ -// swift-tools-version: 6.2 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -import PackageDescription - -let package = Package( - name: "dotkeeper", - targets: [ - // Targets are the basic building blocks of a package, defining a module or a test suite. - // Targets can depend on other targets in this package and products from dependencies. - .executableTarget( - name: "dotkeeper" - ), - ] -) diff --git a/README.md b/README.md index c846bba..9aff7e8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # dotkeeper +> [!WARNING] +> This is the experimental **go** rewrite of dotkeeper. +> Some functionality may not be implemented + ![A preview of Dotkeeper applying a keep](assets/preview.png) A *keeper* for your *dotfiles*. See what I did there? *(booooooo)* @@ -22,33 +26,21 @@ brew install stikypiston/formulae/dotkeeper ### Method 2: Manual Install +#### Dependencies -#### Dependencies: - -- Swift (can be installed with `brew install swift`, or with `swiftly`) +To build *dotkeeper*, you will need a working installation of **go**. -#### Instructions +You can either: -To install manually, first clone the repository. +1. Install go with your package manager of choice (e.g. `brew`) +2. Use the **Nix Devshell** to build the project. (just run `nix develop`) -```bash -git clone https://github.com/StikyPiston/dotkeeper -``` +#### Building -Then, `cd` into the directory. +To build, simply run: ```bash -cd dotkeeper +go build ``` -Use `swift` to build the project. - -```bash -swift build --configuration release -``` - -And finally, move the executable into a location like `/usr/local/bin/` - -```bash -sudo mv .build/release/dotkeeper /usr/local/bin/ -``` +Move the resulting `dotkeeper` binary to some place like `/usr/local/bin` or `~/.local/bin` diff --git a/Sources/dotkeeper/main.swift b/Sources/dotkeeper/main.swift deleted file mode 100644 index 16d8566..0000000 --- a/Sources/dotkeeper/main.swift +++ /dev/null @@ -1,235 +0,0 @@ -// dotkeeper-swift - -import Foundation - -// MARK: - Data Models - -struct Link: Codable { - let source: String - let target: String -} - -struct State: Codable { - var keep: String? - var links: [Link] -} - -struct Keep: Codable { - let links: [Link] -} - -// MARK: - Paths - -let fileManager = FileManager.default -let homeDir = fileManager.homeDirectoryForCurrentUser -let keepDir = homeDir.appendingPathComponent(".dotkeep") -let stateFile = homeDir.appendingPathComponent(".dotkeeper-state.json") - -// MARK: Hostname -let hostname = ProcessInfo.processInfo.hostName - -// MARK: - State Handling - -func loadState() -> State { - if fileManager.fileExists(atPath: stateFile.path) { - do { - let data = try Data(contentsOf: stateFile) - return try JSONDecoder().decode(State.self, from: data) - } catch { - print(" Failed to load state: \(error)") - } - } - return State(keep: nil, links: []) -} - -func saveState(_ state: State) { - do { - let encoder = JSONEncoder() - encoder.outputFormatting = .prettyPrinted - let data = try encoder.encode(state) - try data.write(to: stateFile) - } catch { - print(" Failed to save state: \(error)") - } -} - -// MARK: - CLI Commands - -func listKeeps() { - do { - let entries = try fileManager.contentsOfDirectory(atPath: keepDir.path) - let visible = entries.filter { !$0.hasPrefix(".") } - let keepPaths = visible.map { keepDir.appendingPathComponent($0) } - let directories = keepPaths.filter { url in - var isDirectory: ObjCBool = false - return fileManager.fileExists(atPath: url.path, isDirectory: &isDirectory) && isDirectory.boolValue - } - - print("󰻉 Available Keeps:") - for dir in directories { - print("- \(dir.lastPathComponent)") - } - } catch { - print(" Failed to read keep directory: \(error)") - } -} - -func showStatus() { - let state = loadState() - if let keep = state.keep { - print(" Active keep: \(keep)") - } else { - print(" No keeps active.") - } -} - -func deactivateCurrentKeep() { - let state = loadState() - for link in state.links { - if let _ = try? FileManager.default.destinationOfSymbolicLink(atPath: link.target) { - do { - try FileManager.default.removeItem(atPath: link.target) - print("\u{001B}[0;31m Removed symlink: \(link.target)\u{001B}[0;0m") - } catch { - print("\u{001B}[0;31m Could not remove symlink \(link.target): \(error)\u{001B}[0;0m") - } - } - } - saveState(State(keep: nil, links: [])) -} - -func activateKeep(keepName: String) { - let keepPath = keepDir.appendingPathComponent(keepName) - let keepFile = keepPath.appendingPathComponent("keep.json") - - - guard fileManager.fileExists(atPath: keepFile.path) else { - print(" No keep.json found in \(keepName)") - return - } - - deactivateCurrentKeep() - - do { - let data = try Data(contentsOf: keepFile) - let keep = try JSONDecoder().decode(Keep.self, from: data) - - var newLinks = keep.links - - let hSpecPath = keepPath.appendingPathComponent("hSpecs").appendingPathComponent("\(hostname).json") - - if fileManager.fileExists(atPath: hSpecPath.path) { - do { - let hSpecData = try Data(contentsOf: hSpecPath) - let hSpec = try JSONDecoder().decode(Keep.self, from: hSpecData) - - print("\u{001B}[0;32m󰌨 Applying hSpec for host: \(hostname)\u{001B}[0;0m") - - newLinks.append(contentsOf: hSpec.links) - } catch { - print("\u{001B}[0;31m Error loading hSpec for \(hostname): \(error)\u{001B}[0;0m") - } - } else { - print("\u{001B}[0;32m󰹎 No hSpec will be applied\u{001B}[0;0m") - } - - for entry in newLinks { - let source = keepPath.appendingPathComponent(entry.source).path - let target = NSString(string: entry.target).expandingTildeInPath - - // Ensure parent directory exists - do { - try fileManager.createDirectory( - atPath: (target as NSString).deletingLastPathComponent, - withIntermediateDirectories: true, - attributes: nil - ) - } catch { - print("\u{001B}[0;31m Failed to create parent directory: \(error)\u{001B}[0;0m") - continue - } - - // Create the symlink - do { - try fileManager.createSymbolicLink(atPath: target, withDestinationPath: source) - print(" Linked: \(target) → \(source)") - } catch { - print("\u{001B}[0;31m Failed to create symlink: \(error)\u{001B}[0;0m") - continue - } - - newLinks.append(Link(source: source, target: target)) - } - - let newState = State(keep: keepName, links: newLinks) - saveState(newState) - print("\u{001B}[0;32m Activated keep: \(keepName)\u{001B}[0;0m") - - } catch { - print("\u{001B}[0;31m Failed to read or parse keep.json: \(error)\u{001B}[0;0m") - } -} - -func fetchKeep(url: String) { - let keepsDir = keepDir - - print("\u{001B}[0;34m Installing keep: \(url)...\u{001B}[0;0m") - - let process = Process() - process.currentDirectoryURL = keepsDir - process.executableURL = URL(fileURLWithPath: "/usr/bin/env") - process.arguments = ["git", "clone", url] - - do { - try process.run() - process.waitUntilExit() - if process.terminationStatus == 0 { - print("\u{001B}[0;32m Successfully installed keep \(url)\u{001B}[0;0m") - } else { - print("\u{001B}[0;31m Failed to install keep \(url), git exited with code \(process.terminationStatus)\u{001B}[0;0m") - } - } catch { - print("\u{001B}[0;31m Error running git: \(error)\u{001B}[0;0m") - } -} - - -// MARK: - CLI Entry Point - -let args = CommandLine.arguments - -if args.count > 1 { - let command = args[1] - - switch command { - case "list": - listKeeps() - case "status": - showStatus() - case "deactivate": - deactivateCurrentKeep() - case "activate": - if args.count < 3 { - print("Usage: dotkeeper activate ") - } else { - let keepName = args[2] - activateKeep(keepName: keepName) - } - case "fetch": - if args.count < 3 { - print("Usage: dotkeeper fetch ") - } else { - let url = args[2] - fetchKeep(url: url) - } - default: - print("Unknown command") - } -} else { - print("Usage: dotkeeper ") - print("> list - Lists available keeps") - print("> status - Shows active keep") - print("> deactivate - Deactivates the current keep") - print("> activate - Activates a keep") - print("> fetch - Fetches a keep into ~/.dotkeep") -} diff --git a/cmd/activate.go b/cmd/activate.go new file mode 100644 index 0000000..56037ca --- /dev/null +++ b/cmd/activate.go @@ -0,0 +1,77 @@ +package cmd + +import ( + "fmt" + "log" + "os" + "path/filepath" + + "github.com/spf13/cobra" + "github.com/fatih/color" +) + +func CreateSymlink(keepName, src, dest string) error { + homeDir, err := os.UserHomeDir() + keepsDir := filepath.Join(homeDir, ".dotkeep", keepName) + expandedSrc, err := ExpandPath(src) + src = filepath.Join(keepsDir, expandedSrc) + dest, err = ExpandPath(dest) + if err != nil { + return err + } + + if err := os.Symlink(src, dest); err != nil { + return fmt.Errorf(" Failed to create symlink %s -> %s: %w", src, dest, err) + } + + return nil +} + +var activateCmd = &cobra.Command{ + Use: "activate", + Short: "Activate a keep", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + keep := args[0] + + home, err := os.UserHomeDir() + if err != nil { + log.Fatal(err) + return + } + + DeactivateKeep() + + keepDir := filepath.Join(home, ".dotkeep", keep) + links, err := LoadKeep(keepDir) + if err != nil { + log.Fatal(err) + return + } + + for _, link := range links { + if err := CreateSymlink(keep, link.Source, link.Target); err != nil { + color.Red(" Error creating symlink: %s -> %s\n", link.Target, link.Source) + } else { + color.Blue(" Symlinked %s -> %s\n", link.Target, link.Source) + } + } + + stateFile := filepath.Join(home, ".dotkeeper-state.json") + + st := State{ + Keep: keep, + Links: links, + } + + if err := SaveState(stateFile, st); err != nil { + log.Fatal(" Failed to write state file: %s", err) + } + + color.Green(" Activated keep: %s\n", keep) + }, +} + +func init() { + rootCmd.AddCommand(activateCmd) +} diff --git a/cmd/deactivate.go b/cmd/deactivate.go new file mode 100644 index 0000000..8bfa362 --- /dev/null +++ b/cmd/deactivate.go @@ -0,0 +1,92 @@ +package cmd + +import ( + "encoding/json" + "fmt" + "os" + "path/filepath" + + "github.com/spf13/cobra" + "github.com/fatih/color" +) + +func LoadState() (State, error) { + var st State + home, err := os.UserHomeDir() + if err != nil { + return st, fmt.Errorf(" Failed to get home directory: %w", err) + } + + statePath := filepath.Join(home, ".dotkeeper-state.json") + + data, err := os.ReadFile(statePath) + if err != nil { + if os.IsNotExist(err) { + // Return empty state if file doesn't exist + return State{}, nil + } + return st, fmt.Errorf(" Failed to read state file: %w", err) + } + + if err := json.Unmarshal(data, &st); err != nil { + return st, fmt.Errorf(" Failed to parse state file: %w", err) + } + + return st, nil +} + +func DeactivateKeep() error { + st, err := LoadState() + if err != nil { + return err + } + + if len(st.Links) == 0 { + color.Green(" No active keep to deactivate.") + return nil + } + + for _, link := range st.Links { + dest, err := ExpandPath(link.Target) + if err != nil { + color.Red(" Cannot expand %s: %v\n", link.Target, err) + continue + } + + if fi, err := os.Lstat(dest); err == nil { + if fi.Mode()&os.ModeSymlink != 0 || fi.Mode().IsRegular() { + if err := os.Remove(dest); err != nil { + color.Red(" Cannot remove %s: %v\n", dest, err) + } else { + color.Red(" Removed: %s\n", dest) + } + } else { + color.Blue("󰒭 Skipping non-symlink: %s\n", dest) + } + } + } + + // Save empty state + home, err := os.UserHomeDir() + statePath := filepath.Join(home, ".dotkeeper-state.json") + + if err := SaveState(statePath, State{}); err != nil { + return fmt.Errorf(" Failed to write empty state: %w", err) + } + + color.Green(" Deactivated keep") + return nil +} + +// deactivateCmd represents the deactivate command +var deactivateCmd = &cobra.Command{ + Use: "deactivate", + Short: "Deactivates the current keep", + Run: func(cmd *cobra.Command, args []string) { + DeactivateKeep() + }, +} + +func init() { + rootCmd.AddCommand(deactivateCmd) +} diff --git a/cmd/expandPath.go b/cmd/expandPath.go new file mode 100644 index 0000000..5d47b8e --- /dev/null +++ b/cmd/expandPath.go @@ -0,0 +1,53 @@ +package cmd + +import ( + "fmt" + "os" + "os/user" + "path/filepath" + "strings" +) + +func ExpandPath(p string) (string, error) { + if p == "" { + return "", nil + } + + p = os.ExpandEnv(p) + + if strings.HasPrefix(p, "~") { + var home string + var rest string + + if p == "~" || strings.HasPrefix(p, "~/") { + u, err := user.Current() + if err != nil { + return "", fmt.Errorf("failed to get current user: %w", err) + } + home = u.HomeDir + rest = strings.TrimPrefix(p, "~") + } else { + slash := strings.IndexRune(p, '/') + var username string + if slash == -1 { + username = p[1:] + rest = "" + } else { + username = p[1:slash] + rest = p[slash:] + } + + u, err := user.Lookup(username) + if err != nil { + return "", fmt.Errorf("failed to lookup user %q: %w", username, err) + } + home = u.HomeDir + } + + p = filepath.Join(home, rest) + } + + p = filepath.Clean(p) + + return p, nil +} diff --git a/cmd/helpers.go b/cmd/helpers.go new file mode 100644 index 0000000..6ca8546 --- /dev/null +++ b/cmd/helpers.go @@ -0,0 +1,61 @@ +package cmd + +import ( + "encoding/json" + "fmt" + "os" + "path/filepath" + "github.com/fatih/color" +) + +func LoadKeep(keepRoot string) ([]Link, error) { + var allLinks []Link + + keepFile := filepath.Join(keepRoot, "keep.json") + data, err := os.ReadFile(keepFile) + if err != nil { + return nil, fmt.Errorf(" Failed to read keep.json: %w", err) + } + + var keep Keep + if err := json.Unmarshal(data, &keep); err != nil { + return nil, fmt.Errorf(" Failed to parse keep.json: %w", err) + } + allLinks = append(allLinks, keep.Links...) + + hostname, err := os.Hostname() + if err != nil { + return nil, fmt.Errorf(" Failed to get hostname: %w", err) + } + + hSpecFile := filepath.Join(keepRoot, "hSpecs", hostname+".json") + if _, err := os.Stat(hSpecFile); err == nil { + hData, err := os.ReadFile(hSpecFile) + if err != nil { + return nil, fmt.Errorf(" Failed to read hSpec: %w", err) + } + + var hSpec Keep + if err := json.Unmarshal(hData, &hSpec); err != nil { + return nil, fmt.Errorf(" Failed to parse hSpec: %w", err) + } + color.Green("󰌨 Applying hSpec for host: " + hostname) + + allLinks = append(allLinks, hSpec.Links...) + } + + return allLinks, nil +} + +func SaveState(path string, st State) error { + data, err := json.MarshalIndent(st, "", " ") + if err != nil { + return fmt.Errorf(" Failed to marshal state: %w", err) + } + + if err := os.WriteFile(path, data, 0644); err != nil { + return fmt.Errorf(" Failed to write state file: %w", err) + } + + return nil +} diff --git a/cmd/list.go b/cmd/list.go new file mode 100644 index 0000000..dd9542f --- /dev/null +++ b/cmd/list.go @@ -0,0 +1,47 @@ +package cmd + +import ( + "fmt" + "log" + "os" + "path/filepath" + + "github.com/spf13/cobra" + "github.com/fatih/color" +) + +// listCmd represents the list command +var listCmd = &cobra.Command{ + Use: "list", + Short: "Lists available keeps", + Run: func(cmd *cobra.Command, args []string) { + homeDir, err := os.UserHomeDir() + if err != nil { + log.Fatal(err) + return + } + + keepDir := filepath.Join(homeDir, ".dotkeep") + + keeps, err := os.ReadDir(keepDir) + if err != nil { + color.Red(" No keeps available") + return + } + + if keeps != nil { + color.Green("󰌨 Available keeps:") + for _, keep := range keeps { + if keep.IsDir() == true { + fmt.Printf(" - %s\n", keep.Name()) + } + } + } else { + color.Red(" No keeps available") + } + }, +} + +func init() { + rootCmd.AddCommand(listCmd) +} diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..55f09f1 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,38 @@ +package cmd + +import ( + "os" + + "github.com/spf13/cobra" +) + + + +// rootCmd represents the base command when called without any subcommands +var rootCmd = &cobra.Command{ + Use: "dotkeeper", + Short: "A simple, flexible symlink farm tool", +} + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the rootCmd. +func Execute() { + err := rootCmd.Execute() + if err != nil { + os.Exit(1) + } +} + +func init() { + // Here you will define your flags and configuration settings. + // Cobra supports persistent flags, which, if defined here, + // will be global for your application. + + // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.dotkeeper.yaml)") + + // Cobra also supports local flags, which will only run + // when this action is called directly. + rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} + + diff --git a/cmd/status.go b/cmd/status.go new file mode 100644 index 0000000..639ecf6 --- /dev/null +++ b/cmd/status.go @@ -0,0 +1,46 @@ +package cmd + +import ( + "encoding/json" + "log" + "os" + "path/filepath" + + "github.com/spf13/cobra" + "github.com/fatih/color" +) + +// statusCmd represents the status command +var statusCmd = &cobra.Command{ + Use: "status", + Short: "See the currently active keep", + Run: func(cmd *cobra.Command, args []string) { + homeDir, err := os.UserHomeDir() + if err != nil { + log.Fatal(err) + return + } + + stateFile := filepath.Join(homeDir, ".dotkeeper-state.json") + + state, err := os.ReadFile(stateFile) + + var data State + + err = json.Unmarshal(state, &data) + if err != nil { + color.Red("󰌩 No active keep") + return + } + + if data.Keep != "" { + color.Green(" Active keep: %s", data.Keep) + } else { + color.Red("󰌩 No active keep") + } + }, +} + +func init() { + rootCmd.AddCommand(statusCmd) +} diff --git a/cmd/types.go b/cmd/types.go new file mode 100644 index 0000000..c5c3606 --- /dev/null +++ b/cmd/types.go @@ -0,0 +1,15 @@ +package cmd + +type State struct { + Keep string `json:"keep"` + Links []Link `json:"links"` +} + +type Keep struct { + Links []Link `json:"links"` +} + +type Link struct { + Source string `json:"source"` + Target string `json:"target"` +} diff --git a/flake.lock b/flake.lock index 5c26949..6bae7c7 100644 --- a/flake.lock +++ b/flake.lock @@ -1,16 +1,34 @@ { "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1769018530, - "narHash": "sha256-MJ27Cy2NtBEV5tsK+YraYr2g851f3Fl1LpNHDzDX15c=", - "owner": "nixos", + "lastModified": 1769461804, + "narHash": "sha256-msG8SU5WsBUfVVa/9RPLaymvi5bI8edTavbIq3vRlhI=", + "owner": "NixOS", "repo": "nixpkgs", - "rev": "88d3861acdd3d2f0e361767018218e51810df8a1", + "rev": "bfc1b8a4574108ceef22f02bafcf6611380c100d", "type": "github" }, "original": { - "owner": "nixos", + "owner": "NixOS", "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" @@ -18,8 +36,24 @@ }, "root": { "inputs": { + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index d09fb9a..a1191b7 100644 --- a/flake.nix +++ b/flake.nix @@ -1,70 +1,25 @@ { - description = "Swift devshell using Podman container"; + description = "dotkeeper (Go rewrite) devshell"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs }: - let - system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; - - # Generate a policy.json - podmanPolicy = pkgs.writeText "podman-policy.json" '' - { - "default": [ - { - "type": "insecureAcceptAnything" - } - ] - } - ''; - in - { - devShells.${system}.default = pkgs.mkShell { - packages = with pkgs; [ - podman - bashInteractive - ]; - - shellHook = '' - echo "Swift Development Shell" - echo "Run 'enter-container' to (set up and) enter the Swift podman container" - - enter-container() { - CONTAINER_NAME=swift-latest - IMAGE=docker.io/library/swift:6.2 - WORKDIR=$(pwd) - - POLICY="${podmanPolicy}" - - if ! podman image exists "$IMAGE"; then - echo "Pulling Swift image..." - podman pull --signature-policy "$POLICY" "$IMAGE" - fi - - if podman container exists "$CONTAINER_NAME"; then - echo "Starting existing container..." - podman start "$CONTAINER_NAME" >/dev/null - else - echo "Creating new container..." - podman run \ - --signature-policy "$POLICY" \ - --interactive \ - --tty \ - --name "$CONTAINER_NAME" \ - --volume "$WORKDIR:/workspace:Z" \ - --workdir /workspace \ - "$IMAGE" \ - /bin/bash - return - fi - - echo "Attaching to container..." - podman attach "$CONTAINER_NAME" - } - ''; - }; - }; + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in { + devShells.default = pkgs.mkShell { + name = "dotkeeper-go-shell"; + + packages = with pkgs; [ + go + gopls + gotools + delve + ]; + }; + }); } diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..dd601ce --- /dev/null +++ b/go.mod @@ -0,0 +1,14 @@ +module github.com/stikypiston/dotkeeper + +go 1.25.6 + +require github.com/spf13/cobra v1.10.2 + +require ( + github.com/fatih/color v1.18.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/spf13/pflag v1.0.9 // indirect + golang.org/x/sys v0.25.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d39b047 --- /dev/null +++ b/go.sum @@ -0,0 +1,21 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= +github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= +github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= +github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/main.go b/main.go new file mode 100644 index 0000000..287694e --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/stikypiston/dotkeeper/cmd" + +func main() { + cmd.Execute() +}