Add header for fzf and print only running tasks

This commit is contained in:
Daniel Berteaud 2023-10-01 22:26:32 +02:00
parent 093779a1a3
commit 2c38dc8531
1 changed files with 8 additions and 10 deletions

18
ctctl
View File

@ -49,8 +49,7 @@ ctctl_switch_env(){
TARGET_NAMESPACE=$2
if [ -z "${TARGET_DOM}" ]; then
echo "Select the container install you want to work on"
TARGET_DOM=$(ctctl_ls_env | fzf)
TARGET_DOM=$(ctctl_ls_env | fzf --header "Select the container install you want to work on")
fi
if [ ! -e ~/.ctctl/${TARGET_DOM}/ctctl.conf ]; then
@ -84,8 +83,7 @@ ctctl_switch_env(){
if [ $(ctctl_ls_namespace | wc -w) -eq 1 ]; then
TARGET_NAMESPACE=$(ctctl_ls_namespace)
else
echo "Select the namespace you are working in"
TARGET_NAMESPACE=$(ctctl_ls_namespace | fzf)
TARGET_NAMESPACE=$(ctctl_ls_namespace | fzf --header "Select the namespace you are working in")
fi
fi
export CTCTL_ENV=${TARGET_NAMESPACE}
@ -395,7 +393,7 @@ ctctl_build_required_images(){
# Build selected images
ctctl_build_selected_images(){
local NO_CACHE=$1
for DOCKER_IMAGE in $(ctctl_ls_build_docker_images | fzf -m); do
for DOCKER_IMAGE in $(ctctl_ls_build_docker_images | fzf -m --header "Select images to build (space to select, then enter)"); do
build_image "${DOCKER_IMAGE}" ${NO_CACHE}
done
}
@ -780,7 +778,7 @@ ctctl_ls_alloc_of_job(){
ctctl_ls_tasks_of_alloc(){
local ALLOC=$1
local IFS=$'\n'
for TASK in $(nomad alloc status -json "${ALLOC}" | jq -r '.TaskResources | keys[]'); do
for TASK in $(nomad alloc status -json "${ALLOC}" | jq -r '.TaskStates | to_entries[] | select(.value.State=="running") | .key'); do
echo "${TASK}"
done
unset TASK ALLOC
@ -795,7 +793,7 @@ ctctl_exec_ct(){
if [ $(echo "${ALLOCS}" | wc -l) -eq 1 ]; then
ALLOC="${ALLOCS}"
else
ALLOC=$(echo "${ALLOCS}" | fzf)
ALLOC=$(echo "${ALLOCS}" | fzf --header "Select desired allocation")
fi
ALLOC=$(echo ${ALLOC} | sed -E 's/^([^ \(]+).*/\1/')
# Only Keep the UUID of the target alloc
@ -804,7 +802,7 @@ ctctl_exec_ct(){
if [ $(echo "${TASKS}" | wc -l) -eq 1 ]; then
TASK=${TASKS}
else
TASK=$(echo "${TASKS}" | fzf -m)
TASK=$(echo "${TASKS}" | fzf --header "Select desired task")
fi
echo "Running nomad alloc exec -task ${TASK} ${ALLOC} ${CMD}"
nomad alloc exec -task ${TASK} ${ALLOC} ${CMD}
@ -824,14 +822,14 @@ ctctl_alloc_logs(){
if [ $(echo "${ALLOCS}" | wc -l) -eq 1 ]; then
ALLOC="${ALLOCS}"
else
ALLOC=$(echo "${ALLOCS}" | fzf)
ALLOC=$(echo "${ALLOCS}" | fzf --header "Select desired allocation")
fi
ALLOC=$(echo ${ALLOC} | sed -E 's/^([^ \(]+).*/\1/')
TASKS=$(ctctl_ls_tasks_of_alloc ${ALLOC})
if [ $(echo "${TASKS}" | wc -l) -eq 1 ]; then
TASK=${TASKS}
else
TASK=$(echo "${TASKS}" | fzf -m)
TASK=$(echo "${TASKS}" | fzf --header "Select desired task")
fi
echo "Running nomad alloc logs -f -tail -n 50 ${ALLOC} ${TASK}"
nomad alloc logs -f -tail -n 50 ${ALLOC} ${TASK}