feat: handle command hooks

feat: handle copy

feat: handle remove

feat: handle move and home ~ path

refactor: improve error handling in cmd-hook

feat: handlePwd
This commit is contained in:
Justin Lin committed 2025-05-05 19:55:40 +08:00
1 parent d755822908
commit 95c4fb71ae
3 files changed
+127 -42

No files matched your search

+15 -5
View File
@@ -3,6 +3,7 @@ package main
import (
"os"
"path/filepath"
"strings"
)
type FileType string
@@ -16,6 +17,10 @@ func resolvePath(path string) string {
if filepath.IsAbs(path) {
return path
}
if strings.HasPrefix(path, "~") {
homeDir := os.Getenv("HOME")
return filepath.Join(homeDir, path[1:])
}
return filepath.Join(os.Getenv("PWD"), path)
}
@@ -30,10 +35,15 @@ func fileExists(path string) (FileType, error) {
return FileTypeFile, nil
}
func isDir(path string) bool {
info, err := os.Stat(path)
if err != nil {
return false
func getFilePathList(cmd string) []string {
parts := strings.Fields(cmd)[1:]
results := make([]string, 0, len(parts))
for _, part := range parts {
if strings.HasPrefix(part, "-") {
continue
}
absPath := resolvePath(part)
results = append(results, absPath)
}
return info.IsDir()
return results
}