From 609da065b6a3a9f7d0c86c0f59c5376f903d0ff9 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Thu, 8 Aug 2024 10:34:34 +0300 Subject: [PATCH] chore: cleanups & extract docker cmds --- .zshrc | 2 +- aliases.zsh | 1 + plugins/docker.plugin.zsh | 46 ++++++++++++++++++++++++++++++++++ plugins/functions.plugin.zsh | 48 ------------------------------------ 4 files changed, 48 insertions(+), 49 deletions(-) create mode 100644 plugins/docker.plugin.zsh diff --git a/.zshrc b/.zshrc index d6d3457e..8a9ae217 100644 --- a/.zshrc +++ b/.zshrc @@ -6,7 +6,7 @@ export DOTBIN_META="$HOME/.config/.bin" source "$HOME/.dotfiles/plugins/functions.plugin.zsh" source "$DOTFILES/exports.zsh" -[[ "$1" == "-q" ]] || motd +[[ "$1" == "-q" ]] || run-parts "$DOTFILES/plugins/motd" # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. # Initialization code that may require console input (password prompts, [y/n] diff --git a/aliases.zsh b/aliases.zsh index b42a9a43..f0414610 100755 --- a/aliases.zsh +++ b/aliases.zsh @@ -111,6 +111,7 @@ alias hlog="home git log" alias hiv="hi; vim ." alias hv="pushd \$(wd path df); vi .; popd" alias spider="ssh root@spider.casraf.dev" +alias motd="run-parts \$DOTFILES/plugins/motd" # docker alias de="docker-exec" diff --git a/plugins/docker.plugin.zsh b/plugins/docker.plugin.zsh new file mode 100644 index 00000000..be392f32 --- /dev/null +++ b/plugins/docker.plugin.zsh @@ -0,0 +1,46 @@ +#!/usr/bin/env zsh + +# open docker logs for specified container +docker-log() { + image="$1" + shift + docker logs --follow $@ "$image" +} + +# docker exec command for specified container +docker-exec() { + image="$1" + executable="$2" + shift 2 + rest=$@ + docker exec -ti $rest "$image" "$executable" +} + +# open docker bash shell for specified container +docker-bash() { + image="$1" + shift + docker-exec "$image" /bin/bash $@ +} + +# open docker sh shell for specified container +docker-sh() { + image="$1" + shift + docker-exec "$image" /bin/sh $@ +} + +# get path of docker volume +docker-volume-path() { + image="$1" + shift + docker volume inspect "$image" | jq -r '.[0].Mountpoint' +} + +# cd to docker volume +docker-volume-cd() { + image="$1" + shift + cd $(docker-volume-path "$image") +} + diff --git a/plugins/functions.plugin.zsh b/plugins/functions.plugin.zsh index 19450763..6f6872c7 100755 --- a/plugins/functions.plugin.zsh +++ b/plugins/functions.plugin.zsh @@ -2,10 +2,6 @@ source $DOTFILES/autoload_completions.zsh -motd() { - run-parts $DOTFILES/plugins/motd -} - # Functions # show all man entries under a specific section @@ -201,50 +197,6 @@ prj() { popd } -# open docker logs for specified container -docker-log() { - image="$1" - shift - docker logs --follow $@ "$image" -} - -# docker exec command for specified container -docker-exec() { - image="$1" - executable="$2" - shift 2 - rest=$@ - docker exec -ti $rest "$image" "$executable" -} - -# open docker bash shell for specified container -docker-bash() { - image="$1" - shift - docker-exec "$image" /bin/bash $@ -} - -# open docker sh shell for specified container -docker-sh() { - image="$1" - shift - docker-exec "$image" /bin/sh $@ -} - -# get path of docker volume -docker-volume-path() { - image="$1" - shift - docker volume inspect "$image" | jq -r '.[0].Mountpoint' -} - -# cd to docker volume -docker-volume-cd() { - image="$1" - shift - cd $(docker-volume-path "$image") -} - # reload entire shell reload-zsh() { source $HOME/.zshrc