Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
moukoublen committed Oct 20, 2024
1 parent 490795e commit 8bcebca
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 24 deletions.
40 changes: 31 additions & 9 deletions bin/drh → bin/dr
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env bash

# drh is a shortcut to execute `docker run` command with the current directory binded in the container.
# eg: drh golang:1.18beta1
# dr is a shortcut to execute `docker run` command with --rm --interactive --tty arguments prefilled.
# eg: dr golang:1.23
# All arguments are passed to docker run except:
# -R, --RO which is translated to read-only `:ro` volume bind of the current directory
# --ME which is translated to `--user=$(id -u):$(id -g)`
#
# To enable `docker run` run (or put in ~/.bashrc or ~/.profile e.t.c.):
#
# source <(drh --completion)
# source <(dr --completion)
#

__drh_bash_completion() {
__dr_bash_completion() {
[[ "$(type -t _docker_container_run)" != "function" ]] &&
[[ -f /usr/share/bash-completion/completions/docker ]] &&
source /usr/share/bash-completion/completions/docker
Expand All @@ -22,22 +22,36 @@ __drh_bash_completion() {
}

READ_ONLY=""
MOUNT_PWD=""
USR=""
args=()

args+=('--rm')
args+=('--interactive')
args+=('--tty')

while (($#)); do
case "${1}" in
-R | --RO)
READ_ONLY=":ro"
shift
;;
-H | --HERE)
MOUNT_PWD="1"
shift
;;
--ME)
USR="--user=$(id -u):$(id -g)"
shift
;;
--ROOT)
USR='--user=0:0'
shift
;;
--completion)
declare -f __drh_bash_completion
declare -f __dr_bash_completion
echo ''
echo 'complete -F __drh_bash_completion drh'
echo 'complete -F __dr_bash_completion dr'
exit 0
;;
*)
Expand All @@ -47,8 +61,16 @@ while (($#)); do
esac
done

FOLDER="/v/$(basename "${PWD}")"
if [[ ${MOUNT_PWD} == "1" ]]; then
FOLDER="/v/$(basename "${PWD}")"
# prepend
args=("--volume" "${PWD}:${FOLDER}${READ_ONLY}" --workdir "${FOLDER}" "${args[@]}")
fi

set -x
if [[ -n ${USR} ]]; then
# prepend
args=("${USR}" "${args[@]}")
fi

exec docker run --rm --interactive --tty "${USR}" --volume "${PWD}:${FOLDER}${READ_ONLY}" --workdir "${FOLDER}" "${args[@]}"
set -x
exec docker run "${args[@]}"
3 changes: 2 additions & 1 deletion bin/provides
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ case "$(what-pm)" in
dpkg -S "$@"
;;
*)
echo "this script does not have packages for this release"
echo "this script does not supports this distro"
exit 1
;;
esac
13 changes: 13 additions & 0 deletions bin/what-os
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/usr/bin/env bash

case "$(uname)" in
"Darwin")
sw_vers
exit 0
;;
*) ;;
esac

if [[ -f /etc/os-release ]]; then
(
source /etc/os-release
Expand All @@ -13,5 +21,10 @@ if command -v lsb_release >/dev/null 2>&1; then
exit 0
fi

if command -v lsb_release >/dev/null 2>&1; then
lsb_release -is
exit 0
fi

echo ""
exit 1
29 changes: 17 additions & 12 deletions bin/what-pm
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#!/usr/bin/env bash

case "$(what-os)" in
"Fedora" | "Fedora Linux")
echo "dnf"
;;
"Ubuntu" | "Debian" | "LinuxMint" | "Pop" | "Pop!_OS")
echo "apt"
;;
*)
echo "this script does not have packages for this release"
exit 1
;;
esac
if command -v dnf >/dev/null 2>&1; then
echo "dnf"
exit 0
fi

if command -v apt >/dev/null 2>&1; then
echo "apt"
exit 0
fi

if command -v pkg >/dev/null 2>&1; then
echo "pkg"
exit 0
fi

echo ""
exit 1
4 changes: 2 additions & 2 deletions lib/50-docker.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ docker-clean-all() {( set -x
docker volume prune --force
)}

if command -v drh 1>/dev/null 2>&1; then
source <(drh --completion)
if command -v dr 1>/dev/null 2>&1; then
source <(dr --completion)
fi

################################################################################
Expand Down

0 comments on commit 8bcebca

Please sign in to comment.