Moved dex to seperate file
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
home.file.".zsh/fastfetch.jsonc".source = ./fastfetch/config.jsonc;
|
home.file.".zsh/fastfetch.jsonc".source = ./fastfetch/config.jsonc;
|
||||||
|
home.file.".zsh/functions/dex.zsh".source = ./zsh/functions/dex.zsh;
|
||||||
|
|
||||||
programs.zsh = {
|
programs.zsh = {
|
||||||
enable = true;
|
enable = true;
|
||||||
@@ -15,31 +16,7 @@
|
|||||||
# Use kitty's ssh helper if running inside kitty
|
# Use kitty's ssh helper if running inside kitty
|
||||||
[ "$TERM" = "xterm-kitty" ] && alias ssh="kitty +kitten ssh"
|
[ "$TERM" = "xterm-kitty" ] && alias ssh="kitty +kitten ssh"
|
||||||
|
|
||||||
dex() {
|
source ~/.zsh/functions/dex.zsh
|
||||||
local container
|
|
||||||
|
|
||||||
container=$(
|
|
||||||
docker ps --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}' \
|
|
||||||
| tail -n +2 \
|
|
||||||
| fzf \
|
|
||||||
--header='Select container' \
|
|
||||||
--height=80% \
|
|
||||||
--layout=reverse \
|
|
||||||
--border \
|
|
||||||
--preview 'docker logs -f --tail=30 {1} 2>&1' \
|
|
||||||
--preview-window='right,65%,follow,border-left' \
|
|
||||||
| awk '{print $1}'
|
|
||||||
)
|
|
||||||
|
|
||||||
[ -z "$container" ] && return 0
|
|
||||||
docker exec -it "$container" sh -c '
|
|
||||||
if command -v bash >/dev/null 2>&1; then
|
|
||||||
exec bash
|
|
||||||
else
|
|
||||||
exec sh
|
|
||||||
fi
|
|
||||||
'
|
|
||||||
}
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
59
systems/modules/home/programs/zsh/functions/dex.zsh
Normal file
59
systems/modules/home/programs/zsh/functions/dex.zsh
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
dex() {
|
||||||
|
clear
|
||||||
|
local container
|
||||||
|
|
||||||
|
container=$(
|
||||||
|
docker ps --format '{{.Names}}\t{{.Image}}\t{{.Status}}' |
|
||||||
|
sort |
|
||||||
|
fzf \
|
||||||
|
--delimiter=$'\t' \
|
||||||
|
--with-nth=1,2,3 \
|
||||||
|
--header=$'Ctrl-I: Inspect | Ctrl-L: Logs | Ctrl-R: Refresh | ?: Toggle Preview\n\nNAME\tIMAGE\tSTATUS' \
|
||||||
|
--tabstop=4 \
|
||||||
|
--height=90% \
|
||||||
|
--layout=reverse \
|
||||||
|
--border=rounded \
|
||||||
|
--info=inline-right \
|
||||||
|
--prompt='🐳 Container > ' \
|
||||||
|
--pointer='▶' \
|
||||||
|
--marker='✓' \
|
||||||
|
--preview 'docker logs -f --tail=50 {1} 2>&1' \
|
||||||
|
--preview-label=' Logs ' \
|
||||||
|
--preview-window='right,65%,follow,border-left,wrap' \
|
||||||
|
--bind 'ctrl-r:reload(docker ps --format "{{.Names}}\t{{.Image}}\t{{.Status}}" | sort)' \
|
||||||
|
--bind 'ctrl-u:preview-half-page-up' \
|
||||||
|
--bind 'ctrl-d:preview-half-page-down' \
|
||||||
|
--bind '?:toggle-preview' \
|
||||||
|
--bind 'ctrl-l:change-preview(docker logs -f --tail=50 {1} 2>&1)+change-preview-label(Logs)' \
|
||||||
|
--bind 'ctrl-i:change-preview(
|
||||||
|
docker inspect --format "
|
||||||
|
Name: {{.Name}}
|
||||||
|
Image: {{.Config.Image}}
|
||||||
|
Status: {{.State.Status}}
|
||||||
|
Running: {{.State.Running}}
|
||||||
|
Started: {{.State.StartedAt}}
|
||||||
|
Finished: {{.State.FinishedAt}}
|
||||||
|
PID: {{.State.Pid}}
|
||||||
|
Exit Code: {{.State.ExitCode}}
|
||||||
|
|
||||||
|
Networks:
|
||||||
|
{{range .NetworkSettings.Networks}} • {{.IPAddress}}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
Mounts:
|
||||||
|
{{range .Mounts}} • {{.Source}} -> {{.Destination}}
|
||||||
|
{{end}}
|
||||||
|
" {1}
|
||||||
|
)+change-preview-label(Inspect)' |
|
||||||
|
cut -f1
|
||||||
|
) || return
|
||||||
|
|
||||||
|
docker exec -it "$container" sh -c '
|
||||||
|
for shell in bash ash zsh sh; do
|
||||||
|
command -v "$shell" >/dev/null 2>&1 && exec "$shell"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "No suitable shell found." >&2
|
||||||
|
exit 1
|
||||||
|
'
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user