Skip to content

Commit

Permalink
cqfd: add shell command
Browse files Browse the repository at this point in the history
This adds the shell command to run a $SHELL command from within the
container.

It is a convenient frontend to "cqfd run bash", and it the respects the
arguments:

	$ cqfd shell -c 'echo "0=\"$0\"" "*=\"$*\"" "#=\"$#\""' zero one two three
	0="zero" *="one two three" #="3"

Note: The command shell does not run the command= set in the file
.cqfdrc.
  • Loading branch information
gportay committed Nov 29, 2023
1 parent da8e56c commit 09fd35f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
15 changes: 14 additions & 1 deletion bash-completion
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ _cqfd() {

COMPREPLY=( $(compgen -c -W "-c" -- "$cur") )
return
elif [[ "$arg" == shell ]]; then
for (( i=1; i <= cword; i++ )); do
if [[ ${words[i]} == shell ]]; then
((i++))
break
fi
done

COMP_WORDS=("${SHELL:-/bin/sh}" "${COMP_WORDS[@]:$i}" "$cur")
COMP_LINE="${COMP_WORDS[*]}"
COMP_POINT="${#COMP_LINE}"
_command_offset 0
return
fi

local opts="-C -d -f -b -q -V --version -h --help"
Expand All @@ -71,7 +84,7 @@ _cqfd() {
return
fi

local cmds="init flavors run release version help"
local cmds="init flavors run release shell version help"
COMPREPLY=( $(compgen -W "$cmds $opts" -- "$cur") )
} &&
complete -F _cqfd cqfd
11 changes: 11 additions & 0 deletions cqfd
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Commands:
flavors List flavors from config file to stdout.
run [cmdstring] Run argument(s) inside build container.
release [cmdstring] Run argument(s) and release software.
shell [shargs] Run shell command inside build container.
help Show this help text.
By default, the 'run' command is assumed, with the default
Expand Down Expand Up @@ -517,6 +518,16 @@ while [ $# -gt 0 ]; do
build_cmd_alt="$*"
break
;;
shell)
shift
config_load $flavor
command_string="${SHELL:-/bin/sh}"
if [ "$#" -ne 0 ]; then
command_string+=" ${@@Q}"
fi
docker_run "$command_string"
exit
;;
?*)
echo "Unknown command: $1"
usage
Expand Down

0 comments on commit 09fd35f

Please sign in to comment.