added ~ as home processing

This commit is contained in:
JISAUAY committed 2025-06-27 11:23:15 -05:00
1 parent 7062e798a9
commit 9e46cc9105
7 files changed
+79 -6

No files matched your search

+6 -2
View File
@@ -2,13 +2,17 @@ package cmd
import (
"gosh/types"
"gosh/util"
"os"
"github.com/fatih/color"
)
func GoshCat(sh *types.Shell, filename string) types.CmdOutput {
data, err := os.ReadFile(filename)
func GoshCat(sh *types.Shell, file_path string) types.CmdOutput {
file_path = util.ExpandHome(file_path)
data, err := os.ReadFile(file_path)
red := color.New(color.FgRed).SprintFunc()
if err != nil {
return types.CmdOutput{Id: 1, Output: red(err)}
+4
View File
@@ -4,11 +4,15 @@ import (
"os"
"gosh/types"
"gosh/util"
"github.com/fatih/color"
)
func GoshCd(sh *types.Shell, dir string) types.CmdOutput {
dir = util.ExpandHome(dir)
err := os.Chdir(dir)
red := color.New(color.FgRed).SprintFunc()
if err != nil {
+15 -2
View File
@@ -2,14 +2,27 @@ package cmd
import (
"gosh/types"
"gosh/util"
"os"
"strings"
"github.com/fatih/color"
)
func GoshLs(sh *types.Shell) types.CmdOutput {
children, err := os.ReadDir(sh.Cd)
func GoshLs(sh *types.Shell, paths ...string) types.CmdOutput {
var dir string
if len(paths) > 0 && paths[0] != "" {
dir = paths[0]
} else {
dir = sh.Cd
}
dir = util.ExpandHome(dir)
children, err := os.ReadDir(dir)
red := color.New(color.FgRed).SprintFunc()
if err != nil {
return types.CmdOutput{Id: 1, Output: red(err)}
+4
View File
@@ -2,12 +2,16 @@ package cmd
import (
"gosh/types"
"gosh/util"
"path/filepath"
"github.com/fatih/color"
)
func GolshPyapath(sh *types.Shell, path string) types.CmdOutput {
path = util.ExpandHome(path)
abs, err := filepath.Abs(path)
red := color.New(color.FgRed).SprintFunc()