Skip to content

Commit 5591c62

Browse files
committed
Improve kl helper
1 parent 4bf2659 commit 5591c62

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

.zshrc

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -503,49 +503,44 @@ function k8s_namespace() {
503503
}
504504

505505
function k8s_log() {
506-
local resource="$1"
507-
local follow
506+
local resource
508507

509-
if [[ "$2" == "-f" ]] ; then
510-
follow=true
511-
elif [[ "$1" == "-f" ]] ; then
512-
resource="$2"
513-
follow=true
508+
if [[ $# -ne 0 ]] ; then
509+
if kubectl get pod "$1" &> /dev/null ; then
510+
resource="$1"
511+
shift
512+
fi
514513
fi
515514

516-
if [[ $# -eq 0 ]] ; then
515+
if [[ "${1:0:1}" == "-" || -z "$resource" ]] ; then
517516
if [[ -f "$HOME/.bin/fzf" || -d "$HOME/.fzf" ]] ; then
518517
resource=$(kubectl get pods | fzf --header-lines=1 --height 20% --reverse | awk '{print $1}')
519518

520519
if [[ -z "$resource" ]] ; then
521520
return 1
522521
fi
523-
524-
if [[ $(kubectl get pod "$resource" -o jsonpath='{.status.phase}') == "Running" ]] ; then
525-
follow=1
526-
fi
527522
else
528-
echo "Usage: kl {resource} {-f}"
523+
echo "Usage: kl {resource} {option}…"
529524
return 0
530525
fi
531526
fi
532527

528+
if [[ -z "$resource" && "${1:0:1}" != "-" ]] ; then
529+
resource="$1"
530+
shift
531+
fi
532+
533533
if [[ -f "$HOME/.bin/lj" ]] ; then
534-
if [[ -n "$follow" ]] ; then
535-
kubectl logs "$resource" -f | lj -F
534+
if [[ $@ =~ (-F|--follow) ]] ; then
535+
kubectl logs "$resource" -f | lj $@
536536
return $?
537537
else
538-
kubectl logs "$resource" | lj -P
538+
kubectl logs "$resource" | lj $@
539539
return $?
540540
fi
541541
else
542-
if [[ -n "$follow" ]] ; then
543-
kubectl logs "$resource" -f
544-
return $?
545-
else
546-
kubectl logs "$resource"
547-
return $?
548-
fi
542+
kubectl logs "$resource" $@
543+
return $?
549544
fi
550545
}
551546

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bash <(curl -fsSL https://andy.one/dotfiles/install.sh)
2828
| `k …` | `kubectl` shortcut |
2929
| `kd …` | `kubectl describe` shortcut |
3030
| `kn {namespace}` | Set k8s namespace |
31-
| `kl {resource} {-f|--follow}` | View k8s resource logs |
31+
| `kl {resource} {option}…` | View k8s resource logs |
3232
| `ks {pod}` | Connect to k8s pod |
3333
| `lll …` | List files and directories using [`eza`](https://github.com/eza-community/eza) |
3434
| `llg …` | List files and directories using [`eza`](https://github.com/eza-community/eza) with `git` status |

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -e
77

88
################################################################################
99

10-
VERSION="2.5.3"
10+
VERSION="2.5.4"
1111

1212
################################################################################
1313

0 commit comments

Comments
 (0)