From ab5dd5c11a2628e8f7c74af2a00f9cbb27646d51 Mon Sep 17 00:00:00 2001 From: TheK4n Date: Tue, 4 Apr 2023 20:33:41 +0300 Subject: [PATCH] feat(docker): custom docker cli plugins --- home/user/.config/i3/config | 2 +- home/user/.docker/cli-plugins/docker-ips | 25 ++++++++++++++++++++++ home/user/.docker/cli-plugins/docker-shell | 16 ++++++++++++++ home/user/.subbash/functions | 21 ------------------ home/user/.zprofile | 2 +- install | 7 ++++++ 6 files changed, 50 insertions(+), 23 deletions(-) create mode 100755 home/user/.docker/cli-plugins/docker-ips create mode 100755 home/user/.docker/cli-plugins/docker-shell diff --git a/home/user/.config/i3/config b/home/user/.config/i3/config index 9d50d07..366d82c 100644 --- a/home/user/.config/i3/config +++ b/home/user/.config/i3/config @@ -42,7 +42,7 @@ exec --no-startup-id dex --autostart --environment i3 # xss-lock grabs a logind suspend inhibit lock and will use i3lock to lock the # screen before suspend. Use loginctl lock-session to lock your screen. -exec --no-startup-id xss-lock --transfer-sleep-lock -- i3lock --nofork +exec --no-startup-id xss-lock --transfer-sleep-lock -- i3lock --nofork -c 000000 -e -f # NetworkManager is the most popular way to manage wireless networks on Linux, # and nm-applet is a desktop environment-independent system tray GUI for it. diff --git a/home/user/.docker/cli-plugins/docker-ips b/home/user/.docker/cli-plugins/docker-ips new file mode 100755 index 0000000..2e22388 --- /dev/null +++ b/home/user/.docker/cli-plugins/docker-ips @@ -0,0 +1,25 @@ +#!/bin/bash + +if [[ "$1" == "docker-cli-plugin-metadata" ]]; then +cat << HERE +{ + "SchemaVersion": "0.1.0", + "Vendor": "example.com", + "Version": "v0.1.0", + "ShortDescription": "Bash based Docker cli-plugin" +} +HERE +exit +fi + +result="CONTAINER NAME;IMAGE;IP\n" + +for container in $(docker ps -q | tr '\n' ' ') +do + IP="$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$container" 2>/dev/null)" + container_name="$(docker inspect --format='{{.Name}}' "$container" 2>/dev/null)" + image_name="$(docker inspect --format='{{.Config.Image}}' "$container" 2>/dev/null)" + result+="${container_name#"/"};$image_name;$IP\n" +done + +echo -e $result 2>/dev/null | column -t -s ";" diff --git a/home/user/.docker/cli-plugins/docker-shell b/home/user/.docker/cli-plugins/docker-shell new file mode 100755 index 0000000..f2096da --- /dev/null +++ b/home/user/.docker/cli-plugins/docker-shell @@ -0,0 +1,16 @@ +#!/bin/bash + +if [[ "$1" == "docker-cli-plugin-metadata" ]]; then +cat << HERE +{ + "SchemaVersion": "0.1.0", + "Vendor": "example.com", + "Version": "v0.1.0", + "ShortDescription": "Bash based Docker cli-plugin" +} +HERE +exit +fi + +docker exec -it $2 bash + diff --git a/home/user/.subbash/functions b/home/user/.subbash/functions index 84287c8..18fa6b4 100644 --- a/home/user/.subbash/functions +++ b/home/user/.subbash/functions @@ -152,27 +152,6 @@ mcd () { } -# docker - -# execute bash shell in running container -docker_ex() { - docker exec -it $1 ${2:-bash} -} - -# ips of docker containers -docker_ips() { - local DOC IP OUT NAME PORT - for DOC in $(docker ps -q | tr '\n' ' ') - do - IP="$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$DOC" 2>/dev/null)" - PORT="$(docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}}{{(index $conf 0).HostPort}}{{end}}' "$DOC" 2>/dev/null)" - NAME="$(docker inspect --format='{{.Name}}' "$DOC" 2>/dev/null)" - OUT+="${NAME#"/"}"'\t'"$IP":"$PORT"'\n' - done - echo -e $OUT 2>/dev/null | column -t -} - - # toggle wireguard vpn with interface /etc/wireguard/wg0.conf # to allow sudo user toggle vpn without password: ## sudo groupadd wireguard diff --git a/home/user/.zprofile b/home/user/.zprofile index 027fea9..e8c05ee 100644 --- a/home/user/.zprofile +++ b/home/user/.zprofile @@ -1,4 +1,4 @@ -if systemctl -q is-active graphical.target && [[ $(tty) = "/dev/tty1" ]] && [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]]; then +if systemctl -q is-active graphical.target && [[ $(tty) = "/dev/tty1" ]] && [[ -z $DISPLAY ]] && [[ $XDG_VTNR -eq 1 ]]; then exec startx >> ~/.xlogs 2>&1 fi diff --git a/install b/install index 41b420a..72f18d4 100755 --- a/install +++ b/install @@ -18,6 +18,7 @@ declare -A TARGETS=( ["i3"]=".config/i3 .config/i3status .local/bin/i3status_wrapper .config/picom" ["bat"]=".config/bat" ["psql"]=".psqlrc" + ["docker"]=".docker/cli-plugins" ) _die() { @@ -181,6 +182,11 @@ cmd_psql() { __install_from_sandbox } +cmd_docker() { + _link_files_in_sandbox ${TARGETS["docker"]} + __install_from_sandbox +} + is_target_exists() { test " ${!TARGETS[@]} " =~ " $1 " } @@ -219,6 +225,7 @@ cmd_install() { termux) shift; cmd_termux "$@" ;; arch) shift; cmd_arch "$@" ;; psql) shift; cmd_psql "$@" ;; + docker) shift; cmd_docker "$@" ;; *) shift; cmd_no_target "$@" ;; esac done