From 2e2ee0a038fea2c010c9895c77e16e6b0116ea09 Mon Sep 17 00:00:00 2001
From: Jakob Unterwurzacher
Date: Sat, 4 Jun 2016 14:24:48 +0200
Subject: main: print relative path in the init success message

... but only if the relative path does not start with "..".

Makes the message easier to grasp. Example:

  $ gocryptfs -init -scryptn=10 v0.9
  [...]
  The filesystem has been created successfully.

Before:
  You can now mount it using: gocryptfs /home/jakob/src/github.com/rfjakob/gocryptfs/integration_tests/example_filesystems/v0.9 MOUNTPOINT

After:
  You can now mount it using: gocryptfs v0.9 MOUNTPOINT
---
 main.go | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/main.go b/main.go
index 3f89368..6b3b6b6 100644
--- a/main.go
+++ b/main.go
@@ -12,6 +12,7 @@ import (
 	"runtime"
 	"runtime/pprof"
 	"strconv"
+	"strings"
 	"syscall"
 	"time"
 
@@ -56,6 +57,7 @@ var flagSet *flag.FlagSet
 var GitVersion = "[version not set - please compile using ./build.bash]"
 var GitVersionFuse = "[version not set - please compile using ./build.bash]"
 
+// initDir initializes an empty directory for use as a gocryptfs cipherdir.
 func initDir(args *argContainer) {
 	err := checkDirEmpty(args.cipherdir)
 	if err != nil {
@@ -82,8 +84,15 @@ func initDir(args *argContainer) {
 	}
 
 	toggledlog.Info.Printf(colorGreen + "The filesystem has been created successfully." + colorReset)
+	wd, _ := os.Getwd()
+	friendlyPath, _ := filepath.Rel(wd, args.cipherdir)
+	if strings.HasPrefix(friendlyPath, "../") {
+		// A relative path that starts with "../" is pretty unfriendly, just
+		// keep the absolute path.
+		friendlyPath = args.cipherdir
+	}
 	toggledlog.Info.Printf(colorGrey+"You can now mount it using: %s %s MOUNTPOINT"+colorReset,
-		toggledlog.ProgramName, args.cipherdir)
+		toggledlog.ProgramName, friendlyPath)
 	os.Exit(0)
 }
 
-- 
cgit v1.2.3