зеркало из https://github.com/mislav/hub.git
Merge pull request #659 from CaptainHayashi/ch-csh-tcsh-alias
Improve `hub alias` support for csh and tcsh.
This commit is contained in:
Коммит
e80acd844d
|
@ -37,7 +37,7 @@ func alias(command *Command, args *Args) {
|
|||
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)
|
||||
var validShell bool
|
||||
for _, s := range shells {
|
||||
|
@ -53,7 +53,15 @@ func alias(command *Command, args *Args) {
|
|||
}
|
||||
|
||||
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 {
|
||||
var profile string
|
||||
switch shell {
|
||||
|
@ -65,6 +73,10 @@ func alias(command *Command, args *Args) {
|
|||
profile = "~/.profile"
|
||||
case "fish":
|
||||
profile = "~/.config/fish/config.fish"
|
||||
case "csh":
|
||||
profile = "~/.cshrc"
|
||||
case "tcsh":
|
||||
profile = "~/.tcshrc"
|
||||
default:
|
||||
profile = "your profile"
|
||||
}
|
||||
|
@ -73,9 +85,12 @@ func alias(command *Command, args *Args) {
|
|||
fmt.Println(msg)
|
||||
|
||||
var eval string
|
||||
if shell == "fish" {
|
||||
switch shell {
|
||||
case "fish":
|
||||
eval = `eval (hub alias -s)`
|
||||
} else {
|
||||
case "csh", "tcsh":
|
||||
eval = "eval \"`hub alias -s`\""
|
||||
default:
|
||||
eval = `eval "$(hub alias -s)"`
|
||||
}
|
||||
fmt.Println(eval)
|
||||
|
|
|
@ -30,6 +30,26 @@ Feature: hub alias
|
|||
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
|
||||
Given $SHELL is "/bin/bash"
|
||||
When I successfully run `hub alias -s`
|
||||
|
@ -54,12 +74,28 @@ Feature: hub alias
|
|||
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
|
||||
Given $SHELL is "/bin/zwoosh"
|
||||
When I run `hub alias -s`
|
||||
Then the output should contain exactly:
|
||||
"""
|
||||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче