Merge pull request #1507 from filecoin-project/feat/completions

Shell completions
This commit is contained in:
Łukasz Magiera 2020-04-08 16:29:18 +02:00 committed by GitHub
commit 2b0bf372a7
9 changed files with 73 additions and 9 deletions

View File

@ -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

View File

@ -54,9 +54,10 @@ func main() {
}
app := &cli.App{
Name: "lotus-storage-miner",
Usage: "Filecoin decentralized storage network storage miner",
Version: build.UserVersion,
Name: "lotus-storage-miner",
Usage: "Filecoin decentralized storage network storage miner",
Version: build.UserVersion,
EnableShellCompletion: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "repo",

View File

@ -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",

View File

@ -1,3 +0,0 @@
From https://github.com/filecoin-project/go-filecoin/tree/master/scripts
Try to keep in sync

View File

@ -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

View File

@ -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

9
scripts/make-completions.sh Executable file
View File

@ -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"

View File

@ -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

View File

@ -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