From 1a3d05e8e7c7354f5499a68e3e9a35d910888164 Mon Sep 17 00:00:00 2001 From: Douglas Camata Date: Fri, 17 Oct 2014 15:04:10 -0300 Subject: [PATCH 1/7] printExport support for fish-shell (based on boot2docker/boot2docker-cli#260) --- cmds.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmds.go b/cmds.go index 3ea5875..14c60c3 100644 --- a/cmds.go +++ b/cmds.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "os/exec" + "path/filepath" "regexp" "runtime" "strings" @@ -195,9 +196,17 @@ func printExport(socket, certPath string) { for name, value := range exports(socket, certPath) { if os.Getenv(name) != value { if value == "" { - fmt.Printf(" unset %s\n", name) + if filepath.Base(os.Getenv("SHELL")) == "fish" { + fmt.Printf(" set -e %s\n", name) + } else { + fmt.Printf(" unset %s\n", name) + } } else { - fmt.Printf(" export %s=%s\n", name, value) + if filepath.Base(os.Getenv("SHELL")) == "fish" { + fmt.Printf(" set x %s\n", name) + } else { + fmt.Printf(" export %s=%s\n", name, value) + } } } } From 66eb47103445eb26f99690f7d8b778c07172bbc5 Mon Sep 17 00:00:00 2001 From: Douglas Camata Date: Thu, 23 Oct 2014 14:32:35 -0200 Subject: [PATCH 2/7] printExport always showing the export/unset commands --- cmds.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/cmds.go b/cmds.go index 14c60c3..b1d4608 100644 --- a/cmds.go +++ b/cmds.go @@ -193,20 +193,21 @@ func checkEnvironment(socket, certPath string) bool { } func printExport(socket, certPath string) { + shell = filepath.Base(os.Getenv("SHELL")) for name, value := range exports(socket, certPath) { - if os.Getenv(name) != value { - if value == "" { - if filepath.Base(os.Getenv("SHELL")) == "fish" { - fmt.Printf(" set -e %s\n", name) - } else { - fmt.Printf(" unset %s\n", name) - } - } else { - if filepath.Base(os.Getenv("SHELL")) == "fish" { - fmt.Printf(" set x %s\n", name) - } else { - fmt.Printf(" export %s=%s\n", name, value) - } + if value = "" { // unsetting vars + switch shell { + case "fish": + fmt.Printf(" set -e %s\n", name) + case "bash": // default command to export variables POSIX shells, like bash, zsh, etc. + fmt.Printf(" unset %s\n", name) + } + } else { // setting vars + switch shell { + case "fish": + fmt.Printf(" set -x %s\n", name) + case "bash": // default command to export variables POSIX shells, like bash, zsh, etc. + fmt.Printf(" export %s=%s\n", name, value) } } } From 7784a0934f69ae221c9fc1e7d18dfdf233c9e364 Mon Sep 17 00:00:00 2001 From: Douglas Camata Date: Thu, 23 Oct 2014 14:33:40 -0200 Subject: [PATCH 3/7] bash's behavior is default in printExport --- cmds.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmds.go b/cmds.go index b1d4608..32f5fb1 100644 --- a/cmds.go +++ b/cmds.go @@ -199,14 +199,14 @@ func printExport(socket, certPath string) { switch shell { case "fish": fmt.Printf(" set -e %s\n", name) - case "bash": // default command to export variables POSIX shells, like bash, zsh, etc. + default: // default command to export variables POSIX shells, like bash, zsh, etc. fmt.Printf(" unset %s\n", name) } } else { // setting vars switch shell { case "fish": fmt.Printf(" set -x %s\n", name) - case "bash": // default command to export variables POSIX shells, like bash, zsh, etc. + default: // default command to export variables POSIX shells, like bash, zsh, etc. fmt.Printf(" export %s=%s\n", name, value) } } From 8287ae83fd7808ebf7ded9a0c67a510e02372c3e Mon Sep 17 00:00:00 2001 From: Douglas Camata Date: Thu, 23 Oct 2014 14:36:37 -0200 Subject: [PATCH 4/7] refactoring printExport again --- cmds.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/cmds.go b/cmds.go index 32f5fb1..df73e55 100644 --- a/cmds.go +++ b/cmds.go @@ -195,20 +195,19 @@ func checkEnvironment(socket, certPath string) bool { func printExport(socket, certPath string) { shell = filepath.Base(os.Getenv("SHELL")) for name, value := range exports(socket, certPath) { - if value = "" { // unsetting vars - switch shell { - case "fish": + switch shell { + case "fish": + if value = "" { fmt.Printf(" set -e %s\n", name) - default: // default command to export variables POSIX shells, like bash, zsh, etc. - fmt.Printf(" unset %s\n", name) - } - } else { // setting vars - switch shell { - case "fish": + } else { fmt.Printf(" set -x %s\n", name) - default: // default command to export variables POSIX shells, like bash, zsh, etc. - fmt.Printf(" export %s=%s\n", name, value) } + default: // default command to export variables POSIX shells, like bash, zsh, etc. + if value = "" { + fmt.Printf(" unset %s\n", name) + } else { + fmt.Printf(" export %s=%s\n", name, value) + } } } } From 5e8d8c9b87f0992aace0069718be707fd8d48c2f Mon Sep 17 00:00:00 2001 From: Douglas Camata Date: Thu, 23 Oct 2014 14:37:36 -0200 Subject: [PATCH 5/7] type fixed in printExport --- cmds.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmds.go b/cmds.go index df73e55..65f1915 100644 --- a/cmds.go +++ b/cmds.go @@ -197,13 +197,13 @@ func printExport(socket, certPath string) { for name, value := range exports(socket, certPath) { switch shell { case "fish": - if value = "" { + if value == "" { fmt.Printf(" set -e %s\n", name) } else { fmt.Printf(" set -x %s\n", name) } default: // default command to export variables POSIX shells, like bash, zsh, etc. - if value = "" { + if value == "" { fmt.Printf(" unset %s\n", name) } else { fmt.Printf(" export %s=%s\n", name, value) From c7e7beb16dd232800e74d1ccd98696c4ed71f799 Mon Sep 17 00:00:00 2001 From: Douglas Camata Date: Thu, 23 Oct 2014 14:38:24 -0200 Subject: [PATCH 6/7] getting rid of unnecessary variable attribution --- cmds.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmds.go b/cmds.go index 65f1915..c6b9dc4 100644 --- a/cmds.go +++ b/cmds.go @@ -193,9 +193,8 @@ func checkEnvironment(socket, certPath string) bool { } func printExport(socket, certPath string) { - shell = filepath.Base(os.Getenv("SHELL")) for name, value := range exports(socket, certPath) { - switch shell { + switch filepath.Base(os.Getenv("SHELL")) { case "fish": if value == "" { fmt.Printf(" set -e %s\n", name) From 8c9238e12b91dbfee6c5c5f45ffe068271727ffe Mon Sep 17 00:00:00 2001 From: Douglas Camata Date: Thu, 23 Oct 2014 14:57:55 -0200 Subject: [PATCH 7/7] forgot to add value in the fish variable export, sorry --- cmds.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds.go b/cmds.go index c6b9dc4..ff508e5 100644 --- a/cmds.go +++ b/cmds.go @@ -199,7 +199,7 @@ func printExport(socket, certPath string) { if value == "" { fmt.Printf(" set -e %s\n", name) } else { - fmt.Printf(" set -x %s\n", name) + fmt.Printf(" set -x %s %s\n", name, value) } default: // default command to export variables POSIX shells, like bash, zsh, etc. if value == "" {