Merge branch 'master' of ssh://git.chaoticlogic.us:2302/daniel/dotfiles-generator
This commit is contained in:
commit
7b2b38d49f
@ -161,10 +161,39 @@ function see() {
|
||||
[ -f "$*" ] && cat "$*" || ls "$*"
|
||||
}
|
||||
|
||||
function docker-env() {
|
||||
function docker-env() {(
|
||||
set -e
|
||||
|
||||
run_command_switches=()
|
||||
workdir="/work_dir"
|
||||
|
||||
function parse_port() {
|
||||
echo -n "$@" | perl -e '
|
||||
my $line = <>;
|
||||
my ($defaultIp, $ip, $hostPort, $contPort) = $line =~ /^(?:([\d.]+) )?(?:(?:([\d.]+):)?(\d+):)?(\d+)$/;
|
||||
if (!$contPort) {
|
||||
print(STDERR "Invalid port format: \"$line\"\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ($ip) {
|
||||
print "$ip:";
|
||||
} else {
|
||||
if ($defaultIp) {
|
||||
print "$defaultIp:";
|
||||
}
|
||||
}
|
||||
|
||||
if ($hostPort) {
|
||||
print "$hostPort:";
|
||||
} else {
|
||||
print "$contPort:";
|
||||
}
|
||||
|
||||
print "$contPort";
|
||||
'
|
||||
}
|
||||
|
||||
while
|
||||
do
|
||||
case "$1" in
|
||||
@ -172,15 +201,40 @@ function docker-env() {
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-[pevhmu])
|
||||
-[evhmu])
|
||||
run_command_switches+=("$1")
|
||||
run_command_switches+=("$2")
|
||||
shift
|
||||
;;
|
||||
-p)
|
||||
run_command_switches+=("-p")
|
||||
run_command_switches+=("$(parse_port "127.0.0.1 $2")")
|
||||
shift
|
||||
;;
|
||||
-P)
|
||||
run_command_switches+=("-p")
|
||||
run_command_switches+=("$(parse_port "$2")")
|
||||
shift
|
||||
;;
|
||||
-E)
|
||||
[ -e "$2" ] || (echo "No such file or directory: $2">&2; exit 1)
|
||||
for arg in $(grep -v '^#' "$2" | xargs)
|
||||
do
|
||||
run_command_switches+=("-e")
|
||||
run_command_switches+=("$arg")
|
||||
done
|
||||
shift
|
||||
;;
|
||||
-U)
|
||||
shift
|
||||
;;
|
||||
-w)
|
||||
workdir="$2"
|
||||
shift
|
||||
;;
|
||||
-r)
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
@ -199,13 +253,17 @@ function docker-env() {
|
||||
Usage: docker-env [OPTIONS] [--] IMAGE [COMMAND] [ARG...]
|
||||
|
||||
Options:
|
||||
-p <port> Publish a container's port(s) to the host
|
||||
-e VAR=value Add environment variable VAR with value
|
||||
-v <volume> Bind mount a volume
|
||||
-w workdir Set working directory (default=/work_dir)
|
||||
-h hostname Container host name
|
||||
-m limit Memory limit
|
||||
-u user Username or UID (format: <name|uid>[:<group|gid>])
|
||||
-p <port> Publish a container's port(s) to the host locally accessible (127.0.0.1)
|
||||
-P <port> Publish a container's port(s) to the host publically accessible
|
||||
-e VAR=value Add environment variable VAR with value
|
||||
-E <varfile> Load environment variables from a file
|
||||
-v <volume> Bind mount a volume
|
||||
-w <workdir> Set working directory (default=/work_dir)
|
||||
-h <hostname> Container hostname
|
||||
-m limit Memory limit
|
||||
-u user Username or UID (format: <name|uid[:<group|gid>])
|
||||
-U user Same as -u, but create user if it does not exist (WIP)
|
||||
-r <raw> Raw argument to pass to \`docker run\` (WIP)
|
||||
EOS
|
||||
return 1
|
||||
fi
|
||||
@ -228,7 +286,7 @@ EOS
|
||||
run_command+="-w \"$workdir\" \"$image\" $cmd"
|
||||
|
||||
eval $run_command
|
||||
}
|
||||
)}
|
||||
|
||||
# Completion for docker-env
|
||||
compdef _docker-env docker-env
|
||||
@ -236,15 +294,17 @@ function _docker-env() {
|
||||
local curcontext="$curcontext" state
|
||||
|
||||
_arguments \
|
||||
"*-p[Publish a containers port(s) to the host]:port:" \
|
||||
"*-e[Set environment variables]:" \
|
||||
"*-p[Publish a container's port(s) to the host locally accessible (127.0.0.1)]:port:" \
|
||||
"*-P[Publish a container's port(s) to the host publically accessible]:port:" \
|
||||
"*-e[Add environment variable VAR with value]:" \
|
||||
"*-E[Load environment variables from a file]:file:_files" \
|
||||
"*-v[Bind mount a volume]:" \
|
||||
"-w[Working directory inside the container]" \
|
||||
"-h[Container host name]" \
|
||||
"-m[Memory limit]" \
|
||||
"-u[Username or UID (format: (<name|uid>|(<name|uid>:<group|gid>)))]" \
|
||||
"(-p -e -v -w -h -m -u)--[Explicitely stop switches and start positional arguments]" \
|
||||
"(-p -e -v -w -h -m -u --)1:Container image:->image" \
|
||||
"(-p -P -e -E -v -w -h -m -u)--[Explicitely stop switches and start positional arguments]" \
|
||||
"(-p -P -e -E -v -w -h -m -u --)1:Container image:->image" \
|
||||
"*:Container CMD:->cmd"
|
||||
|
||||
case $state in
|
||||
|
||||
Loading…
Reference in New Issue
Block a user