-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2755 from garrettbslone/master
bash: top level command completions for flux
- Loading branch information
Showing
3 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# | ||
# Copyright 2020 Lawrence Livermore National Security, LLC | ||
# (c.f. AUTHORS, NOTICE.LLNS, COPYING) | ||
# | ||
# This file is part of the Flux resource manager framework. | ||
# For details, see https://github.com/flux-framework. | ||
# | ||
# SPDX-License-Identifier: LGPL-3.0 | ||
# | ||
shopt -s extglob | ||
|
||
_flux_core() | ||
{ | ||
OIFS=$IFS | ||
local cur prev opts | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
|
||
__get_compopts | ||
|
||
IFS=$OIFS | ||
opts=$compopts | ||
|
||
if [[ "${prev##*/}" == "flux" ]]; then | ||
case "${cur}" in | ||
@(-*)) | ||
COMPREPLY=( $(compgen -W "--help" -- "${cur}") ) | ||
;; | ||
*) | ||
COMPREPLY=( $(compgen -W "${opts}" "${cur}") ) | ||
;; | ||
esac | ||
else | ||
case "${prev}" in | ||
!(-h|--help|help)) | ||
COMPREPLY=( $(compgen -W "--help" -- "${cur}") ) | ||
;; | ||
esac | ||
fi | ||
|
||
return 0 | ||
} | ||
|
||
__get_compopts() { | ||
if [ -z $FLUX_EXEC_PATH ]; then | ||
FLUX_EXEC_PATH=`flux env printenv FLUX_EXEC_PATH` | ||
fi | ||
|
||
IFS=":" | ||
for op in $FLUX_EXEC_PATH/*; do | ||
if [[ -x $op && "${op##*/}" == "flux-"* ]]; then | ||
op="${op##*-}" | ||
compopts+="${op%.*} " | ||
fi | ||
done | ||
|
||
for builtin in $FLUX_BUILTINS; do | ||
compopts+="$builtin " | ||
done | ||
} | ||
|
||
complete -F _flux_core flux | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2020 Lawrence Livermore National Security, LLC | ||
# (c.f. AUTHORS, NOTICE.LLNS, COPYING) | ||
# | ||
# This file is part of the Flux resource manager framework. | ||
# For details, see https://github.com/flux-framework. | ||
# | ||
# SPDX-License-Identifier: LGPL-3.0 | ||
# | ||
|
||
get_builtins() { | ||
local FLUX_BUILTINS | ||
|
||
builtin_path=$1 | ||
|
||
for builtin in $builtin_path/*; do | ||
if [[ $builtin == *".c" && \ | ||
$builtin != *"attr"* ]]; then | ||
builtin="${builtin%.*}" | ||
FLUX_BUILTINS+="${builtin##*/}:" | ||
fi | ||
done | ||
|
||
while read line; do | ||
if [[ $line == *"optparse_reg_subcommand"* \ | ||
&& $line == *"attr"* ]]; then | ||
line="${line##*_}" | ||
FLUX_BUILTINS+="${line%,*}:" | ||
fi | ||
done < $builtin_path/attr.c | ||
|
||
echo FLUX_BUILTINS="$FLUX_BUILTINS" | ||
} | ||
|
||
get_builtins $1 |