From 96c904a51e704a5924c439bf69cfd437c8165fc3 Mon Sep 17 00:00:00 2001 From: Eric Bloch Date: Tue, 3 May 2016 22:20:08 -0700 Subject: [PATCH] Add tcsh support to --shell Fixes #3404 Signed-off-by: Eric Bloch --- commands/commands.go | 2 +- commands/env.go | 11 +++++++++++ commands/env_test.go | 6 ++++++ docs/reference/env.md | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index 2fbb8d152c..632b791881 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -237,7 +237,7 @@ var Commands = []cli.Command{ }, cli.StringFlag{ Name: "shell", - Usage: "Force environment to be configured for a specified shell: [fish, cmd, powershell], default is auto-detect", + Usage: "Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh], default is auto-detect", }, cli.BoolFlag{ Name: "unset, u", diff --git a/commands/env.go b/commands/env.go index d224e334a9..a42033266e 100644 --- a/commands/env.go +++ b/commands/env.go @@ -134,6 +134,10 @@ func shellCfgSet(c CommandLine, api libmachine.API) (*ShellConfig, error) { shellCfg.Prefix = "SET " shellCfg.Suffix = "\n" shellCfg.Delimiter = "=" + case "tcsh": + shellCfg.Prefix = "setenv " + shellCfg.Suffix = "\";\n" + shellCfg.Delimiter = " \"" case "emacs": shellCfg.Prefix = "(setenv \"" shellCfg.Suffix = "\")\n" @@ -182,6 +186,10 @@ func shellCfgUnset(c CommandLine, api libmachine.API) (*ShellConfig, error) { shellCfg.Prefix = "(setenv \"" shellCfg.Suffix = ")\n" shellCfg.Delimiter = "\" nil" + case "tcsh": + shellCfg.Prefix = "unsetenv " + shellCfg.Suffix = ";\n" + shellCfg.Delimiter = "" default: shellCfg.Prefix = "unset " shellCfg.Suffix = "\n" @@ -249,6 +257,9 @@ func (g *EnvUsageHintGenerator) GenerateUsageHint(userShell string, args []strin case "emacs": cmd = fmt.Sprintf("(with-temp-buffer (shell-command \"%s\" (current-buffer)) (eval-buffer))", commandLine) comment = ";;" + case "tcsh": + cmd = fmt.Sprintf("eval `%s`", commandLine) + comment = ":" default: cmd = fmt.Sprintf("eval $(%s)", commandLine) } diff --git a/commands/env_test.go b/commands/env_test.go index efe46af6a9..ae8565cd6b 100644 --- a/commands/env_test.go +++ b/commands/env_test.go @@ -77,6 +77,12 @@ func TestHints(t *testing.T) { {"emacs", []string{"./machine", "env", "--shell=emacs", "--swarm", "default"}, ";; Run this command to configure your shell: \n;; (with-temp-buffer (shell-command \"./machine env --shell=emacs --swarm default\" (current-buffer)) (eval-buffer))\n"}, {"emacs", []string{"./machine", "env", "--shell=emacs", "--no-proxy", "--swarm", "default"}, ";; Run this command to configure your shell: \n;; (with-temp-buffer (shell-command \"./machine env --shell=emacs --no-proxy --swarm default\" (current-buffer)) (eval-buffer))\n"}, {"emacs", []string{"./machine", "env", "--shell=emacs", "--unset"}, ";; Run this command to configure your shell: \n;; (with-temp-buffer (shell-command \"./machine env --shell=emacs --unset\" (current-buffer)) (eval-buffer))\n"}, + + {"tcsh", []string{"./machine", "env", "--shell=tcsh", "default"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh default`\n"}, + {"tcsh", []string{"./machine", "env", "--shell=tcsh", "--no-proxy", "default"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh --no-proxy default`\n"}, + {"tcsh", []string{"./machine", "env", "--shell=tcsh", "--swarm", "default"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh --swarm default`\n"}, + {"tcsh", []string{"./machine", "env", "--shell=tcsh", "--no-proxy", "--swarm", "default"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh --no-proxy --swarm default`\n"}, + {"tcsh", []string{"./machine", "env", "--shell=tcsh", "--unset"}, ": Run this command to configure your shell: \n: eval `./machine env --shell=tcsh --unset`\n"}, } for _, test := range tests { diff --git a/docs/reference/env.md b/docs/reference/env.md index 6d6b10a6e0..5adc2d6add 100644 --- a/docs/reference/env.md +++ b/docs/reference/env.md @@ -25,7 +25,7 @@ a particular machine. Options: --swarm Display the Swarm config instead of the Docker daemon - --shell Force environment to be configured for a specified shell: [fish, cmd, powershell], default is sh/bash + --shell Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh], default is sh/bash --unset, -u Unset variables instead of setting them --no-proxy Add machine IP to NO_PROXY environment variable