From 2208cb1939d79ab7002f082082235c32ccc6ed97 Mon Sep 17 00:00:00 2001 From: Jonas Forsberg Date: Fri, 12 Nov 2021 10:24:56 +0100 Subject: [PATCH] . --- .bashrc | 5 +- .functions.sh | 147 ----------------------------------- .functions/kubernetes.sh | 28 +++++++ .ps1.sh => .functions/ps1.sh | 0 4 files changed, 31 insertions(+), 149 deletions(-) delete mode 100644 .functions.sh create mode 100644 .functions/kubernetes.sh rename .ps1.sh => .functions/ps1.sh (100%) diff --git a/.bashrc b/.bashrc index 3bd7617..d5c70f0 100644 --- a/.bashrc +++ b/.bashrc @@ -24,10 +24,11 @@ fi [[ -x "$(command -v helm)" ]] && source <(helm completion bash) # PS1 Prompt -[[ -f "$HOME/.ps1.sh" ]] && source "$HOME/.ps1.sh" +[[ -f "$HOME/.functions/ps1.sh" ]] && source "$HOME/.functions/ps1.sh" -[[ -f "$HOME/.functions.sh" ]] && source ~/.functions.sh +[[ -d "$HOME/.functions" ]] && for f in ~/.functions/*.sh; do source $f; done + [[ "$(type -t dotf)" == "alias" ]] && [[ "$(type -t __git_complete)" == "function" ]] && __git_complete dotf _git [[ "$(type -t _todo)" == "function" ]] && complete -F _todo t diff --git a/.functions.sh b/.functions.sh deleted file mode 100644 index 5e9b0bf..0000000 --- a/.functions.sh +++ /dev/null @@ -1,147 +0,0 @@ -#!/bin/bash - -function restic(){ - source $HOME/.restic/restic.env - /usr/bin/restic --cacert="$HOME"/.restic/cert.pem "$@" -} - -function kube_gbt(){ - export GBT_CARS='OS, Custom4, Git, Kubectl, Dir, Custom1, Custom2, Custom3, PyVirtEnv, Status, Sign' -} - -function k3sudo(){ - # create a passwordless sudo rule on target - # usage: k3sudo [add, del] - if [[ "$1" == "add" ]];then - ssh -t $2 "hostname --long; echo \"$USER ALL=(ALL) NOPASSWD: ALL\" | sudo tee /etc/sudoers.d/k3sup" - elif [[ "$1" == "del" ]];then - ssh $2 sudo rm /etc/sudoers.d/k3sup - else - echo "Error: usage: k3sudo [add, del] " - fi -} - -function pc(){ - # use pass and copy to clipboard - pass -c1 "$@" -} -complete -o filenames -F _pass pc - - - -function watermark(){ - # Add watermark text to image (ImageMagick depentant) - # $1 = source file - # $2 = watermark text - # $3 = destination file - convert -density 150 -fill "rgba(255,0,0,0.25)" -gravity Center -pointsize 80 -draw "rotate -45 text 0,0 \"$2\"" "$1" "$3" -} - -function reset_evolution() { - # Reset evolution calendar factory - # When it hangs connecting to EWS calendar outlooko365 - EWS_DEBUG=2 /usr/lib/evolution-data-server/evolution-calendar-factory -w -} - -function salt() { - if [[ "$1" == "state.apply" ]]; then - sudo salt-call --local --file-root "$HOME/salt/states" --pillar-root "$HOME/salt/pillars" "$@" pillar="{username: $USER}" - else - sudo salt-call --local --file-root "$HOME/salt/states" --pillar-root "$HOME/salt/pillars" "$@" - fi -} - -function pw(){ - FILE="$1" - - [[ -z "$PWHOME" ]] && printf "\$PWHOME not set\n" && return - - [[ -z "$FILE" ]] && FILE="web.gpg" - - if [[ ! "${FILE: -4}" == ".gpg" ]];then - FILE="${FILE}.gpg" - fi - cd "$PWHOME" - vi "$FILE" - - cd "$OLDPWD" -} - -_pw_completion() -{ - local cur prev suggestions - [[ -z "$PWHOME" ]] && return - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - cd "$PWHOME" - suggestions="$(ls *.gpg)" - cd "$OLDPWD" - if [[ "$prev" != "pw" ]];then - COMPREPLY=() - else - COMPREPLY=( $(compgen -W "${suggestions}" -- ${cur}) ) - fi -} -complete -F _pw_completion pw - -function doh() -{ - local options - options=(start stop restart status) - if [[ ! " ${options[@]} " =~ " ${1} " ]]; then - echo "wrong option, valid: ${options[@]}" - return - fi - if [[ "$1" == "status" ]]; then - systemctl status local-doh-proxy - else - sudo systemctl "$1" local-doh-proxy - fi -} - -function copy_k8s_token(){ - grep "id-token" ~/.kube/config | awk '{print $2}' | xclip -sel clip -} - -function ip_to_hex(){ - IFS=. read oct1 oct2 oct3 oct4 <<< "$1" - printf '0x%02x%02x%02x%02x\n' $oct1 $oct2 $oct3 $oct4 -} - -function salt-call(){ - sudo salt-call --local "$@" -} - - -function ww(){ - local selected_wiki - selected_wiki="$1" - - case $1 in - SUSE|suse|S|s|2) - vim -c "normal 2 ww" - ;; - Private|private|p|3) - vim -c "normal 3 ww" - ;; - *) - vim -c "normal 1 ww" - ;; - esac -} - -function ssh(){ - for arg in "$@" - do - case "$arg" in - -A) - read -t 5 -n 1 -s -r -p "Consider to use -o ProxyJump instead! Press 'y' to continue with -A" answer - printf "\n" - if [[ "${answer,,}" != "y" ]]; then - return 1 - fi - esac - done - /usr/bin/ssh "$@" -} - diff --git a/.functions/kubernetes.sh b/.functions/kubernetes.sh new file mode 100644 index 0000000..c13eef5 --- /dev/null +++ b/.functions/kubernetes.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +function kc(){ + # print all kubernetes contexts + kubectl config get-contexts +} + +function kuc(){ + # use kubernetes context + kubectl config use-context "$1" +} + +function kubernetes_configs(){ + # set KUBECONFIG to default kubeconfig and all *.yaml files in .kube + local KUBE_CONFIG_DEFAULT="$HOME/.kube/config" + local KUBE_CONFIG_DIR="$HOME/.kube" + local KUBE_CONFIG_EXTENTION="*.yaml" + if [[ -f "${KUBE_CONFIG_DEFAULT}" ]];then + export KUBECONFIG="$KUBE_CONFIG_DEFAULT" + fi + [[ -d "${KUBE_CONFIG_DIR}" ]] || mkdir -p "${KUBE_CONFIG_DIR}" + # shellcheck disable=SC2044 + for file in $(find "${KUBE_CONFIG_DIR}" -type f -name "$KUBE_CONFIG_EXTENTION"); do + export KUBECONFIG="$file:$KUBECONFIG" + done +} + +kubernetes_configs diff --git a/.ps1.sh b/.functions/ps1.sh similarity index 100% rename from .ps1.sh rename to .functions/ps1.sh