From 2bdedefa05256237f40139cee5f0c4a6ec369b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 3 Apr 2020 04:03:53 +0200 Subject: [PATCH] Shell completions --- Makefile | 12 ++++++++++++ cmd/lotus-storage-miner/main.go | 1 + cmd/lotus/main.go | 7 ++++--- scripts/README | 3 --- scripts/bash-completion/lotus | 10 ++++++++++ scripts/bash-completion/lotus-storage-miner | 10 ++++++++++ scripts/make-completions.sh | 9 +++++++++ scripts/zsh-completion/lotus | 12 ++++++++++++ scripts/zsh-completion/lotus-storage-miner | 12 ++++++++++++ 9 files changed, 70 insertions(+), 6 deletions(-) delete mode 100644 scripts/README create mode 100644 scripts/bash-completion/lotus create mode 100644 scripts/bash-completion/lotus-storage-miner create mode 100755 scripts/make-completions.sh create mode 100644 scripts/zsh-completion/lotus create mode 100644 scripts/zsh-completion/lotus-storage-miner diff --git a/Makefile b/Makefile index e7e69589c..dfe0dbc7d 100644 --- a/Makefile +++ b/Makefile @@ -161,6 +161,18 @@ BINS+=health buildall: $(BINS) +completions: + ./scripts/make-completions.sh lotus + ./scripts/make-completions.sh lotus-storage-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-storage-miner /usr/share/bash-completion/completions/lotus-storage-miner + install -C ./scripts/zsh-completion/lotus /usr/local/share/zsh/site-functions/_lotus + install -C ./scripts/zsh-completion/lotus-storage-miner /usr/local/share/zsh/site-functions/_lotus-storage-miner + clean: rm -rf $(CLEAN) $(BINS) -$(MAKE) -C $(FFI_PATH) clean diff --git a/cmd/lotus-storage-miner/main.go b/cmd/lotus-storage-miner/main.go index 2ed147531..a0c2a0fb1 100644 --- a/cmd/lotus-storage-miner/main.go +++ b/cmd/lotus-storage-miner/main.go @@ -57,6 +57,7 @@ func main() { Name: "lotus-storage-miner", Usage: "Filecoin decentralized storage network storage miner", Version: build.UserVersion, + EnableShellCompletion: true, Flags: []cli.Flag{ &cli.StringFlag{ Name: "repo", diff --git a/cmd/lotus/main.go b/cmd/lotus/main.go index f0d4442b4..33ff56ac3 100644 --- a/cmd/lotus/main.go +++ b/cmd/lotus/main.go @@ -50,9 +50,10 @@ func main() { defer span.End() app := &cli.App{ - Name: "lotus", - Usage: "Filecoin decentralized storage network client", - Version: build.UserVersion, + Name: "lotus", + Usage: "Filecoin decentralized storage network client", + Version: build.UserVersion, + EnableShellCompletion: true, Flags: []cli.Flag{ &cli.StringFlag{ Name: "repo", diff --git a/scripts/README b/scripts/README deleted file mode 100644 index 43eedb800..000000000 --- a/scripts/README +++ /dev/null @@ -1,3 +0,0 @@ -From https://github.com/filecoin-project/go-filecoin/tree/master/scripts - -Try to keep in sync \ No newline at end of file diff --git a/scripts/bash-completion/lotus b/scripts/bash-completion/lotus new file mode 100644 index 000000000..20c312b6c --- /dev/null +++ b/scripts/bash-completion/lotus @@ -0,0 +1,10 @@ +#!/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 diff --git a/scripts/bash-completion/lotus-storage-miner b/scripts/bash-completion/lotus-storage-miner new file mode 100644 index 000000000..10ee5b77f --- /dev/null +++ b/scripts/bash-completion/lotus-storage-miner @@ -0,0 +1,10 @@ +#!/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-storage-miner \ No newline at end of file diff --git a/scripts/make-completions.sh b/scripts/make-completions.sh new file mode 100755 index 000000000..1bfd59bf3 --- /dev/null +++ b/scripts/make-completions.sh @@ -0,0 +1,9 @@ +#!/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 new file mode 100644 index 000000000..bbd886ae4 --- /dev/null +++ b/scripts/zsh-completion/lotus @@ -0,0 +1,12 @@ +#!/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 diff --git a/scripts/zsh-completion/lotus-storage-miner b/scripts/zsh-completion/lotus-storage-miner new file mode 100644 index 000000000..1ff14be3a --- /dev/null +++ b/scripts/zsh-completion/lotus-storage-miner @@ -0,0 +1,12 @@ +#!/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-storage-miner \ No newline at end of file