From 29b71aa353bca9d7767829948fef7cb9b7c5b0bf Mon Sep 17 00:00:00 2001 From: surdeus Date: Fri, 10 Mar 2023 16:13:55 +0300 Subject: [PATCH] Added some shit into paths util. Should delete later. --- app/mk/inc/config | 2 +- app/mk/inc/std/install | 1 + src/tool/paths/main.go | 23 +++++++++++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/mk/inc/config b/app/mk/inc/config index a20b4f4..f16b179 100644 --- a/app/mk/inc/config +++ b/app/mk/inc/config @@ -3,7 +3,7 @@ MKINCDIR = $(MKINCDIR) EXEDIR = $(HOME)/exe -APPDIR = $(HOME)/app +APPDIR = `goblin paths -fr $HOME/app` SHRDIR = $(HOME)/shr INCDIR = $SHRDIR/inc OBJDIR = $SHRDIR/obj diff --git a/app/mk/inc/std/install b/app/mk/inc/std/install index 3c26cea..9069c9d 100644 --- a/app/mk/inc/std/install +++ b/app/mk/inc/std/install @@ -7,6 +7,7 @@ install-sh:VQ: build fi if test -d app ; then echo Installing application files... + echo "'$HOME'" echo "'$APPDIR'" echo `goblin paths app/* $APPDIR/$PKG_NAME/` #goblin mkdir -p `goblin path $APPDIR/$PKG_NAME` && cp -rf `goblin paths app/* $APPDIR/$PKG_NAME/` diff --git a/src/tool/paths/main.go b/src/tool/paths/main.go index 752ceb5..63d8697 100644 --- a/src/tool/paths/main.go +++ b/src/tool/paths/main.go @@ -8,6 +8,7 @@ import ( "log" "os" "path" + "strings" "github.com/surdeus/goblin/src/pathx" ) @@ -19,26 +20,34 @@ var ( "ext": path.Ext, "dir": path.Dir, "all": func(v string) string { return v }, - "fr": func(v string) string { - return pathx.FromReal(v).String() - }, } handler func(string) string r bool + fromReal bool + ec bool noPartErr = errors.New("no such part") ) func handlePath(p string) { + if fromReal { + p = pathx.FromReal(p).String() + } if handler != nil { p = handler(p) } + var toPrint string if r { - pth := pathx.From(p) - fmt.Println(pth.Real()) + toPrint = pathx.From(p).Real() } else { - fmt.Println(p) + toPrint = p } + + if ec { + toPrint = strings.ReplaceAll(toPrint, "\\", "\\\\") + } + + fmt.Println(toPrint) } func Run(args []string) { @@ -47,6 +56,8 @@ func Run(args []string) { flags := flag.NewFlagSet(arg0, flag.ExitOnError) flags.StringVar(&part, "p", "all", "part of path you want to print") flags.BoolVar(&r, "r", false, "print real OS dependent paths") + flags.BoolVar(&fromReal, "fr", false, "take input paths as real ones") + flags.BoolVar(&ec, "ec", false, "escape characters (mostly for '\\' char in Git bash") flags.Parse(args) args = flags.Args()