summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormjl <mjl@ueber.net>2012-08-19 16:01:33 +0200
committermjl <mjl@ueber.net>2012-08-19 16:01:33 +0200
commitc0c2ae42f9d1810faacec27fe95546bfddc4ae56 (patch)
tree1dfd833ed3d258a4622596d10e1ce36613d97e63
parent248e02dc0ff17e7b7e8b9b8d7591c30af85d581e (diff)
add cleanname
-rw-r--r--cleanname/cleanname.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/cleanname/cleanname.go b/cleanname/cleanname.go
new file mode 100644
index 0000000..759bdc8
--- /dev/null
+++ b/cleanname/cleanname.go
@@ -0,0 +1,38 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+ "path"
+ "strings"
+)
+
+var dir = flag.String("d", "", "directory to use as working directory")
+
+func usage() {
+ fmt.Fprintf(os.Stderr, "usage: cleanname [-d pwd] name ...\n")
+ os.Exit(2)
+}
+
+func main() {
+ flag.Usage = usage
+ flag.Parse()
+ args := flag.Args()
+ if len(args) == 0 {
+ usage()
+ }
+
+ for _, p := range args {
+ if *dir == "" && strings.HasPrefix(p, "/") {
+ fmt.Print(path.Clean(p), "\n")
+ } else {
+ xdir := *dir
+ if xdir == "" {
+ xdir = "."
+ }
+ fmt.Print(path.Clean(fmt.Sprint(xdir, "/", p)), "\n")
+ }
+ }
+ os.Exit(0)
+}