diff --git a/cmd/Drn/main.go b/cmd/Drn/main.go index 7582301..428d9e2 100644 --- a/cmd/Drn/main.go +++ b/cmd/Drn/main.go @@ -16,8 +16,6 @@ import ( "9fans.net/go/plan9/client" ) -var denoteDir = os.Getenv("HOME") + "/doc" - func main() { // Check if running in service mode (called by OnRename callback) if len(os.Args) > 1 && strings.HasPrefix(os.Args[1], "--id=") { @@ -117,6 +115,12 @@ func parseRenameArgs(args []string) (title, signature string, tags []string, err // This replicates the logic from HandleRenameEvent func serviceMode(identifier string) error { return p9client.With9P(func(f *client.Fsys) error { + // Get current denote directory from 9P server + currentDir, err := p9client.ReadFile(f, "dir") + if err != nil { + return fmt.Errorf("failed to read current directory: %w", err) + } + // Get new path from 9P server newPath, err := p9client.ReadFile(f, "n/"+identifier+"/path") if err != nil { @@ -129,7 +133,7 @@ func serviceMode(identifier string) error { } // Find old file on disk (matches with or without signature) - pattern := filepath.Join(denoteDir, identifier+"*") + pattern := filepath.Join(currentDir, identifier+"*") matches, err := filepath.Glob(pattern) if err != nil { return fmt.Errorf("failed to find file: %w", err) @@ -148,7 +152,7 @@ func serviceMode(identifier string) error { if err != nil { return fmt.Errorf("failed to resolve new path: %w", err) } - absBase, err := filepath.Abs(denoteDir) + absBase, err := filepath.Abs(currentDir) if err != nil { return fmt.Errorf("failed to resolve base directory: %w", err) } @@ -183,22 +187,40 @@ func interactiveMode(identifier string, args []string) error { return err } - // Find file by identifier - pattern := filepath.Join(denoteDir, identifier+"*") - matches, err := filepath.Glob(pattern) + var currentDir string + var filePath string + + // Get current directory and find file + err = p9client.With9P(func(f *client.Fsys) error { + // Get current denote directory from 9P server + dir, err := p9client.ReadFile(f, "dir") + if err != nil { + return fmt.Errorf("failed to read current directory: %w", err) + } + currentDir = dir + + // Find file by identifier + pattern := filepath.Join(currentDir, identifier+"*") + matches, err := filepath.Glob(pattern) + if err != nil { + return fmt.Errorf("failed to find file: %w", err) + } + + if len(matches) == 0 { + return fmt.Errorf("no file found with identifier: %s", identifier) + } + + if len(matches) > 1 { + return fmt.Errorf("multiple files match identifier %s", identifier) + } + + filePath = matches[0] + return nil + }) if err != nil { - return fmt.Errorf("failed to find file: %w", err) + return err } - if len(matches) == 0 { - return fmt.Errorf("no file found with identifier: %s", identifier) - } - - if len(matches) > 1 { - return fmt.Errorf("multiple files match identifier %s", identifier) - } - - filePath := matches[0] ext := strings.ToLower(filepath.Ext(filePath)) supportsFrontmatter := ext == ".org" || ext == ".md" || ext == ".txt" diff --git a/scripts/Dbkp b/scripts/Dbkp index c2d957a..2eb741f 100755 --- a/scripts/Dbkp +++ b/scripts/Dbkp @@ -1,4 +1,4 @@ -#!/usr/local/plan9/bin/rc +#!/usr/bin/env rc # Dbkp - Backup and restore denote directory # Usage: Dbkp (create backup) diff --git a/scripts/Djournal b/scripts/Djournal index c998a95..5a0c416 100755 --- a/scripts/Djournal +++ b/scripts/Djournal @@ -1,4 +1,4 @@ -#!/usr/local/plan9/bin/rc +#!/usr/bin/env rc # Journal interval: daily, weekly, monthly, yearly interval=daily diff --git a/scripts/Dmerge b/scripts/Dmerge index e5730b1..265c1f9 100755 --- a/scripts/Dmerge +++ b/scripts/Dmerge @@ -1,4 +1,4 @@ -#!/usr/local/plan9/bin/rc +#!/usr/bin/env rc # Merge - Merge notes or regions # Usage: Dmerge (file merge) diff --git a/scripts/Dsilo b/scripts/Dsilo index d5ca566..788f96a 100755 --- a/scripts/Dsilo +++ b/scripts/Dsilo @@ -1,4 +1,4 @@ -#!/usr/local/plan9/bin/rc +#!/usr/bin/env rc # Dsilo - Switch denote directory (silo) # Usage: Dsilo