2025-09-24 08:30:00 +01:00
|
|
|
package lib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2025-09-24 19:35:56 +01:00
|
|
|
func EditFile(filePath string) {
|
|
|
|
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
|
|
|
fmt.Printf("Error: The file for path '%s' was not found\n", filePath)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
editor := os.Getenv("EDITOR")
|
|
|
|
|
|
|
|
err := Exec(editor, filePath)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-09-24 08:30:00 +01:00
|
|
|
func ViewFile(filePath string) string {
|
|
|
|
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
|
|
|
fmt.Printf("Error: The file for path '%s' was not found\n", filePath)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
content, err := os.ReadFile(filePath)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error opening the file:", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(content)
|
|
|
|
}
|