diff --git a/Makefile b/Makefile index 67d26a71b..fb10a2b77 100644 --- a/Makefile +++ b/Makefile @@ -303,17 +303,10 @@ clean-services: clean-all-services buildall: $(BINS) -completions: - ./scripts/make-completions.sh lotus - ./scripts/make-completions.sh lotus-miner -.PHONY: completions - install-completions: mkdir -p /usr/share/bash-completion/completions /usr/local/share/zsh/site-functions/ install -C ./scripts/bash-completion/lotus /usr/share/bash-completion/completions/lotus - install -C ./scripts/bash-completion/lotus-miner /usr/share/bash-completion/completions/lotus-miner install -C ./scripts/zsh-completion/lotus /usr/local/share/zsh/site-functions/_lotus - install -C ./scripts/zsh-completion/lotus-miner /usr/local/share/zsh/site-functions/_lotus-miner clean: rm -rf $(CLEAN) $(BINS) diff --git a/cmd/lotus-seal-worker/main.go b/cmd/lotus-seal-worker/main.go index 693b833a5..a206d3371 100644 --- a/cmd/lotus-seal-worker/main.go +++ b/cmd/lotus-seal-worker/main.go @@ -63,9 +63,10 @@ func main() { } app := &cli.App{ - Name: "lotus-worker", - Usage: "Remote miner worker", - Version: build.UserVersion(), + Name: "lotus-worker", + Usage: "Remote miner worker", + Version: build.UserVersion(), + EnableBashCompletion: true, Flags: []cli.Flag{ &cli.StringFlag{ Name: FlagWorkerRepo, diff --git a/scripts/bash-completion/lotus b/scripts/bash-completion/lotus index 20c312b6c..b572ab320 100644 --- a/scripts/bash-completion/lotus +++ b/scripts/bash-completion/lotus @@ -1,10 +1,18 @@ #!/usr/bin/env bash + _cli_bash_autocomplete() { - local cur opts base; - COMPREPLY=(); - cur="${COMP_WORDS[COMP_CWORD]}"; - opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-completion ); - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ); - return 0; -}; -complete -F _cli_bash_autocomplete lotus \ No newline at end of file + if [[ "${COMP_WORDS[0]}" != "source" ]]; then + local cur opts base + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + if [[ "$cur" == "-"* ]]; then + opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion ) + else + opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion ) + fi + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + fi +} + +complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete lotus lotus-miner lotus-worker diff --git a/scripts/bash-completion/lotus-miner b/scripts/bash-completion/lotus-miner deleted file mode 100644 index df5cc01cc..000000000 --- a/scripts/bash-completion/lotus-miner +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -_cli_bash_autocomplete() { - local cur opts base; - COMPREPLY=(); - cur="${COMP_WORDS[COMP_CWORD]}"; - opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-completion ); - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ); - return 0; -}; -complete -F _cli_bash_autocomplete lotus-miner \ No newline at end of file diff --git a/scripts/make-completions.sh b/scripts/make-completions.sh deleted file mode 100755 index 1bfd59bf3..000000000 --- a/scripts/make-completions.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -# scripts/make-completions.sh [progname] - -echo '#!/usr/bin/env bash' > "scripts/bash-completion/$1" -echo '#!/usr/bin/env zsh' > "scripts/zsh-completion/$1" - -$1 --init-completion=bash >> "scripts/bash-completion/$1" -$1 --init-completion=zsh >> "scripts/zsh-completion/$1" diff --git a/scripts/zsh-completion/lotus b/scripts/zsh-completion/lotus index bbd886ae4..8d21370b2 100644 --- a/scripts/zsh-completion/lotus +++ b/scripts/zsh-completion/lotus @@ -1,12 +1,23 @@ -#!/usr/bin/env zsh -autoload -U compinit && compinit; -autoload -U bashcompinit && bashcompinit; -_cli_bash_autocomplete() { - local cur opts base; - COMPREPLY=(); - cur="${COMP_WORDS[COMP_CWORD]}"; - opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-completion ); - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ); - return 0; -}; -complete -F _cli_bash_autocomplete lotus \ No newline at end of file +#compdef lotus lotus-miner lotus-worker + +_cli_zsh_autocomplete() { + + local -a opts + local cur + cur=${words[-1]} + if [[ "$cur" == "-"* ]]; then + opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") + else + opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}") + fi + + if [[ "${opts[1]}" != "" ]]; then + _describe 'values' opts + else + _files + fi + + return +} + +compdef _cli_zsh_autocomplete lotus lotus-miner lotus-worker diff --git a/scripts/zsh-completion/lotus-miner b/scripts/zsh-completion/lotus-miner deleted file mode 100644 index 3e23749e6..000000000 --- a/scripts/zsh-completion/lotus-miner +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env zsh -autoload -U compinit && compinit; -autoload -U bashcompinit && bashcompinit; -_cli_bash_autocomplete() { - local cur opts base; - COMPREPLY=(); - cur="${COMP_WORDS[COMP_CWORD]}"; - opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-completion ); - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ); - return 0; -}; -complete -F _cli_bash_autocomplete lotus-miner \ No newline at end of file