Skip to content
This repository has been archived by the owner on Feb 27, 2018. It is now read-only.

printExport support for fish-shell #295

Merged
merged 7 commits into from
Oct 23, 2014
14 changes: 11 additions & 3 deletions cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
Expand Down Expand Up @@ -193,12 +194,19 @@ func checkEnvironment(socket, certPath string) bool {

func printExport(socket, certPath string) {
for name, value := range exports(socket, certPath) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing we seem to have lost here is the automatic silencing.

In other words, if a variable is already set correctly, no message was output.

Do we want to preserve that functionality?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this was removed on purpose. 😄

See the discussion at boot2docker/boot2docker#585, especially:

there's no harm in exporting the same value again :)

(although the explicit "unset"s are nice, so keeping those and expanding
them to include all possible vars as either an "export XYZ=..." or an
explicit "unset XYZ" would be superb)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry I missed that. OK, great.
LGTM

if os.Getenv(name) != value {
switch filepath.Base(os.Getenv("SHELL")) {
case "fish":
if value == "" {
fmt.Printf(" unset %s\n", name)
fmt.Printf(" set -e %s\n", name)
} else {
fmt.Printf(" export %s=%s\n", name, value)
fmt.Printf(" set -x %s %s\n", name, value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there still be an = here? (ie, set -x %s=%s)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(don't know Fish scripting at all :D)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tianon no, sir. Fish syntax for set is like: set -x DOCKER_HOST tcp://192.168.59.103:2376

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks for clarifying. 👍

}
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)
}
}
}
}
Expand Down