Merge pull request #659 from CaptainHayashi/ch-csh-tcsh-alias

Improve `hub alias` support for csh and tcsh.
This commit is contained in:
Mislav Marohnić 2014-10-24 13:26:43 +02:00
Родитель 915f68dd4f 534f2bb0e0
Коммит e80acd844d
2 изменённых файлов: 56 добавлений и 5 удалений

Просмотреть файл

@ -37,7 +37,7 @@ func alias(command *Command, args *Args) {
utils.Check(fmt.Errorf("Unknown shell")) utils.Check(fmt.Errorf("Unknown shell"))
} }
shells := []string{"bash", "zsh", "sh", "ksh", "csh", "fish"} shells := []string{"bash", "zsh", "sh", "ksh", "csh", "tcsh", "fish"}
shell = filepath.Base(shell) shell = filepath.Base(shell)
var validShell bool var validShell bool
for _, s := range shells { for _, s := range shells {
@ -53,7 +53,15 @@ func alias(command *Command, args *Args) {
} }
if flagAliasScript { if flagAliasScript {
fmt.Println("alias git=hub") var alias string
switch shell {
case "csh", "tcsh":
alias = "alias git hub"
default:
alias = "alias git=hub"
}
fmt.Println(alias)
} else { } else {
var profile string var profile string
switch shell { switch shell {
@ -65,6 +73,10 @@ func alias(command *Command, args *Args) {
profile = "~/.profile" profile = "~/.profile"
case "fish": case "fish":
profile = "~/.config/fish/config.fish" profile = "~/.config/fish/config.fish"
case "csh":
profile = "~/.cshrc"
case "tcsh":
profile = "~/.tcshrc"
default: default:
profile = "your profile" profile = "your profile"
} }
@ -73,9 +85,12 @@ func alias(command *Command, args *Args) {
fmt.Println(msg) fmt.Println(msg)
var eval string var eval string
if shell == "fish" { switch shell {
case "fish":
eval = `eval (hub alias -s)` eval = `eval (hub alias -s)`
} else { case "csh", "tcsh":
eval = "eval \"`hub alias -s`\""
default:
eval = `eval "$(hub alias -s)"` eval = `eval "$(hub alias -s)"`
} }
fmt.Println(eval) fmt.Println(eval)

Просмотреть файл

@ -30,6 +30,26 @@ Feature: hub alias
eval "$(hub alias -s)"\n eval "$(hub alias -s)"\n
""" """
Scenario: csh instructions
Given $SHELL is "/bin/csh"
When I successfully run `hub alias`
Then the output should contain exactly:
"""
# Wrap git automatically by adding the following to ~/.cshrc:
eval "`hub alias -s`"\n
"""
Scenario: tcsh instructions
Given $SHELL is "/bin/tcsh"
When I successfully run `hub alias`
Then the output should contain exactly:
"""
# Wrap git automatically by adding the following to ~/.tcshrc:
eval "`hub alias -s`"\n
"""
Scenario: bash code Scenario: bash code
Given $SHELL is "/bin/bash" Given $SHELL is "/bin/bash"
When I successfully run `hub alias -s` When I successfully run `hub alias -s`
@ -54,12 +74,28 @@ Feature: hub alias
alias git=hub\n alias git=hub\n
""" """
Scenario: csh code
Given $SHELL is "/bin/csh"
When I successfully run `hub alias -s`
Then the output should contain exactly:
"""
alias git hub\n
"""
Scenario: tcsh code
Given $SHELL is "/bin/tcsh"
When I successfully run `hub alias -s`
Then the output should contain exactly:
"""
alias git hub\n
"""
Scenario: unsupported shell Scenario: unsupported shell
Given $SHELL is "/bin/zwoosh" Given $SHELL is "/bin/zwoosh"
When I run `hub alias -s` When I run `hub alias -s`
Then the output should contain exactly: Then the output should contain exactly:
""" """
hub alias: unsupported shell hub alias: unsupported shell
supported shells: bash zsh sh ksh csh fish\n supported shells: bash zsh sh ksh csh tcsh fish\n
""" """
And the exit status should be 1 And the exit status should be 1