mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
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:
1 parent
d755822908
commit
95c4fb71ae
3 files changed
+127
-42
No files matched your search
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user