From 4fc0c472349e86133ae8ca17b998515c2a5d7335 Mon Sep 17 00:00:00 2001 From: Adam Veldhousen Date: Tue, 30 Nov 2021 18:15:22 -0600 Subject: [PATCH 1/3] chore: some tweaks from work lappy --- plugins/kubectl/kubectl.sh | 6 ++++-- plugins/starship/defaults.d/starship.toml | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/kubectl/kubectl.sh b/plugins/kubectl/kubectl.sh index 63ba991..69f1410 100644 --- a/plugins/kubectl/kubectl.sh +++ b/plugins/kubectl/kubectl.sh @@ -7,8 +7,10 @@ if ! [[ -f "$(which kubectl 2>&1)" ]] && [[ -d "${HOME}/.asdf" ]]; then asdf install kubectl ${KUBECTL_VERSION}; fi -if [[ -f "$(which kubectl 2>&1)" ]] && [[ -d "${BASH_COMPLETION_DIR}" ]]; then - [[ -f "${BASH_COMPLETION_DIR}/kubectl" ]] || kubectl completion bash > "${BASH_COMPLETION_DIR}/kubectl"; +if [[ -f "$(which kubectl 2>&1)" ]]; then + if [[ -d "/etc/bash_completion.d" ]]; then + [[ -f "/etc/bash_completion.d/kubectl" ]] || kubectl completion bash > /etc/bash_completion.d/kubectl; + fi fi # This command is used a LOT both below and in daily life diff --git a/plugins/starship/defaults.d/starship.toml b/plugins/starship/defaults.d/starship.toml index 41f7fad..ae61fea 100644 --- a/plugins/starship/defaults.d/starship.toml +++ b/plugins/starship/defaults.d/starship.toml @@ -1,6 +1,6 @@ add_newline = true -scan_timeout = 50 +scan_timeout = 500 format = "$all" From 21636b68cb2952ef1c6a8ade8a25ce2054f9d31a Mon Sep 17 00:00:00 2001 From: Adam Veldhousen Date: Mon, 6 Mar 2023 15:06:50 -0600 Subject: [PATCH 2/3] misc updates from work --- plugins/brew/brew.sh | 5 +- plugins/extras/defaults.d/000-base.sh | 9 ++- plugins/helm/helm.sh | 6 ++ plugins/kubectl/kubectl.sh | 11 ++-- plugins/sops/sops-mergetool.sh | 78 +++++++++++++++++++++++ plugins/starship/defaults.d/starship.toml | 11 +++- plugins/starship/starship.sh | 6 ++ plugins/vim/config.d/.vimrc | 1 - 8 files changed, 112 insertions(+), 15 deletions(-) create mode 100755 plugins/sops/sops-mergetool.sh diff --git a/plugins/brew/brew.sh b/plugins/brew/brew.sh index 3bb1f83..0263dd0 100644 --- a/plugins/brew/brew.sh +++ b/plugins/brew/brew.sh @@ -14,6 +14,5 @@ fi [[ -f "${LINUX_BREW_PATH}/bin/brew" ]] && eval "$(${LINUX_BREW_PATH}/bin/brew shellenv)"; [[ -f "${MAC_BREW_PATH}/bin/brew" ]] && eval "$(${MAC_BREW_PATH}/bin/brew shellenv)"; -[[ -f "$(brew --prefix bash-completion)/etc/bash_completion" ]] || brew install bash-completion - -source "$(brew --prefix bash-completion)/etc/bash_completion"; +[[ -d "$(brew --prefix)/etc/bash_completion.d" ]] || brew install bash-completion@2 +[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh" diff --git a/plugins/extras/defaults.d/000-base.sh b/plugins/extras/defaults.d/000-base.sh index 1c1a7c4..f742610 100644 --- a/plugins/extras/defaults.d/000-base.sh +++ b/plugins/extras/defaults.d/000-base.sh @@ -17,12 +17,15 @@ esac # History # https://www.digitalocean.com/community/tutorials/how-to-use-bash-history-commands-and-expansions-on-a-linux-vps -shopt -s histappend; # Append to the history file, not overwrite +shopt -s histappend; # Append to the history file, not overwrite export HISTCONTROL="ignoreboth:erasedups"; # No duplicate commands in history export HISTSIZE=25000; export HISTFILESIZE=10000; -export HISTIGNORE="[ ]*:&:bg:fg:exit:clear"; # Don't save these commands in the history -export HISTORY_COMMAND="history -a; history -c; history -r;"; # flush each command to history immediately +export HISTIGNORE="[ ]*:&:bg:fg:exit:clear:ls:history:gs:code:git:reset:cd:echo:cat"; # Don't save these commands in the history +export HISTORY_COMMAND="history -a;"; # flush each command to history immediately +# update +export PROMPT_COMMAND="$PROMPT_COMMAND $HISTORY_COMMAND"; + stty -ixon; # see environ manfile - just setting up my shell environment diff --git a/plugins/helm/helm.sh b/plugins/helm/helm.sh index 325c80e..76328dd 100644 --- a/plugins/helm/helm.sh +++ b/plugins/helm/helm.sh @@ -10,3 +10,9 @@ fi if [[ -f "$(which helm 2>&1)" ]]; then source <(helm completion bash) fi + + +helm-setup-plugins() { + helm plugin install https://github.com/databus23/helm-diff + helm plugin install https://github.com/jkroepke/helm-secrets --version v3.12.0 +} diff --git a/plugins/kubectl/kubectl.sh b/plugins/kubectl/kubectl.sh index 69f1410..6541c55 100644 --- a/plugins/kubectl/kubectl.sh +++ b/plugins/kubectl/kubectl.sh @@ -7,15 +7,16 @@ if ! [[ -f "$(which kubectl 2>&1)" ]] && [[ -d "${HOME}/.asdf" ]]; then asdf install kubectl ${KUBECTL_VERSION}; fi -if [[ -f "$(which kubectl 2>&1)" ]]; then - if [[ -d "/etc/bash_completion.d" ]]; then - [[ -f "/etc/bash_completion.d/kubectl" ]] || kubectl completion bash > /etc/bash_completion.d/kubectl; - fi -fi # This command is used a LOT both below and in daily life alias k=kubectl +if [[ -f "$(which kubectl 2>&1)" ]]; then + source <(kubectl completion bash); + complete -F __start_kubectl k; +fi + + # Execute a kubectl command against all namespaces alias kca='_kca(){ kubectl "$@" --all-namespaces; unset -f _kca; }; _kca' diff --git a/plugins/sops/sops-mergetool.sh b/plugins/sops/sops-mergetool.sh new file mode 100755 index 0000000..166c1fb --- /dev/null +++ b/plugins/sops/sops-mergetool.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +# Exit on first error and verify variables have been set/passed via CLI +set -eu + +# Rename our variables to friendlier equivalents +# https://git-scm.com/docs/gitattributes#_defining_a_custom_merge_driver +base="$1"; local_="$2"; remote="$3"; merged="$4" + +# Resolve our default mergetool +# https://github.com/git/git/blob/v2.8.2/git-mergetool--lib.sh#L3 +mergetool="$(git config --get merge.tool)" +GIT_DIR="$(git --exec-path)" +if test "$mergetool" = ""; then + echo "No default \`merge.tool\` was set for \`git\`. Please set one via \`git config --set merge.tool \`" 1>&2 + exit 1 +fi + +# Create file names for our decrypted contents +# example_LOCAL_2823.yaml -> example_LOCAL_2823.decrypted.yaml +extension=".${base##*.}" +base_decrypted="${base/$extension/.decrypted$extension}" +local_decrypted="${local_/$extension/.decrypted$extension}" +remote_decrypted="${remote/$extension/.decrypted$extension}" +merged_decrypted="${base_decrypted/_BASE_/_MERGED_}" +backup_decrypted="${base_decrypted/_BASE_/_BACKUP_}" + +# If anything goes wrong, then delete our decrypted files +handle_trap_exit () { + rm $base_decrypted || true + rm $local_decrypted || true + rm $remote_decrypted || true + rm $merged_decrypted || true + rm $backup_decrypted || true +} +trap handle_trap_exit EXIT + +# Decrypt our file contents +sops --decrypt --show_master_keys "$base" > "$base_decrypted" +sops --decrypt --show_master_keys "$local_" > "$local_decrypted" +sops --decrypt --show_master_keys "$remote" > "$remote_decrypted" + +# Create a merge-diff to compare against +set +e +git merge-file -p "$local_decrypted" "$base_decrypted" "$remote_decrypted" > "$merged_decrypted" +set -e +cp "$merged_decrypted" "$backup_decrypted" + +# Set up variables for our mergetool +# https://github.com/git/git/blob/v2.8.2/mergetools/meld +# https://github.com/git/git/blob/v2.8.2/git-mergetool--lib.sh#L95-L111 +export LOCAL="$local_decrypted" +export BASE="$base_decrypted" +export REMOTE="$remote_decrypted" +export MERGED="$merged_decrypted" +export BACKUP="$backup_decrypted" + +# Load our mergetool scripts +source "$GIT_DIR/git-mergetool--lib" +source "$GIT_DIR/mergetools/$mergetool" + +# Override `check_unchanged` with a custom script +check_unchanged () { + # If the contents haven't changed, then fail + if test "$MERGED" -nt "$BACKUP"; then + return 0 + else + exit 1 + fi +} + +# Run our mergetool +set +eu +export merge_tool_path="$(get_merge_tool_path "$mergetool")" +merge_cmd +set -eu + +# Re-encrypt content +sops --encrypt "$merged_decrypted" > "$merged" diff --git a/plugins/starship/defaults.d/starship.toml b/plugins/starship/defaults.d/starship.toml index ae61fea..0b2bf07 100644 --- a/plugins/starship/defaults.d/starship.toml +++ b/plugins/starship/defaults.d/starship.toml @@ -1,6 +1,7 @@ add_newline = true scan_timeout = 500 +command_timeout = 60 format = "$all" @@ -11,8 +12,12 @@ success_symbol = "[➜](bold green)" disabled = true [kubernetes] -format = '[⛵ $context](dimmed green) ' +format = '[⛵ $context](green) ' disabled = false -[git_metrics] -disabled = false +[kubernetes.context_aliases] +"cluster.prd.ax.int" = "⚠️ cluster.prd.ax.int ⚠️ " + +[[battery.display]] +threshold = 25 +style = "bold red" diff --git a/plugins/starship/starship.sh b/plugins/starship/starship.sh index cc8f51d..331cc21 100644 --- a/plugins/starship/starship.sh +++ b/plugins/starship/starship.sh @@ -31,6 +31,12 @@ if [[ -f "$(which starship 2>&1)" ]]; then fi } + starship_set_window_title(){ + echo -ne "\033]0; $(basename "$PWD") \007" + } + + starship_precmd_user_func="starship_set_window_title" + [[ -f "${HOME}/.bashrc" ]] && starship_install "${HOME}/.bashrc"; [[ -f "${HOME}/.bash_profile" ]] && starship_install "${HOME}/.bash_profile"; [[ -f "${HOME}/.profile" ]] && starship_install "${HOME}/.profile"; diff --git a/plugins/vim/config.d/.vimrc b/plugins/vim/config.d/.vimrc index f2b5ea5..a22f147 100644 --- a/plugins/vim/config.d/.vimrc +++ b/plugins/vim/config.d/.vimrc @@ -385,4 +385,3 @@ if has("autocmd") au GUIEnter * set vb t_vb= endif - From 1dc2b427298a96c850da6f0835da1ef5f0941d8f Mon Sep 17 00:00:00 2001 From: Adam Veldhousen Date: Mon, 27 Mar 2023 16:09:03 -0500 Subject: [PATCH 3/3] fixup vim and other plugins --- plugins/asdf/asdf.sh | 18 ++++++++++++++++++ plugins/git-extras/defaults.d/.gitconfig | 4 ++-- plugins/starship/defaults.d/starship.toml | 3 +++ plugins/vim/vim.sh | 16 +++++++--------- 4 files changed, 30 insertions(+), 11 deletions(-) mode change 100644 => 100755 plugins/vim/vim.sh diff --git a/plugins/asdf/asdf.sh b/plugins/asdf/asdf.sh index e42189e..01a5d87 100644 --- a/plugins/asdf/asdf.sh +++ b/plugins/asdf/asdf.sh @@ -33,3 +33,21 @@ asdf_use() { asdf install ${plugin} ${version}; asdf local ${plugin} ${version}; } + +asdf_local_use() { + local TOOL_VERSIONS_PATH='.tool-versions'; + if [ -z "${1}" ]; then + TOOL_VERSIONS_PATH="${1}"; + fi + + cat ${TOOL_VERSIONS_PATH} | xargs -I {} asdf local {}; +} + +asdf_add_plugins() { + local TOOL_VERSIONS_PATH='.tool-versions'; + if [ -z "${1}" ]; then + TOOL_VERSIONS_PATH="${1}"; + fi + + awk '{print $1}' ${TOOL_VERSIONS_PATH} | xargs -I {} asdf plugin add {}; +} diff --git a/plugins/git-extras/defaults.d/.gitconfig b/plugins/git-extras/defaults.d/.gitconfig index 3bb7bf3..57e7f4d 100644 --- a/plugins/git-extras/defaults.d/.gitconfig +++ b/plugins/git-extras/defaults.d/.gitconfig @@ -1,6 +1,6 @@ [alias] # View abbreviated SHA, description, and history graph - ls = log --pretty=format:'%Cblue%h -%d %Cgreen%an %Creset%s - %Cred%GS' --abbrev-commit --date=relative --branches --graph -n 45 + ls = log --pretty=format:'%Cblue%h -%d %Cgreen%an %Creset%s - %Cred%GS' --abbrev-commit --date=relative --branches --graph -n 45 # View the current working tree status using the short format s = status -s @@ -148,7 +148,7 @@ [pull] default = current - ff = only + ff = only [user] email = adamveld12@gmail.com diff --git a/plugins/starship/defaults.d/starship.toml b/plugins/starship/defaults.d/starship.toml index 0b2bf07..227001e 100644 --- a/plugins/starship/defaults.d/starship.toml +++ b/plugins/starship/defaults.d/starship.toml @@ -11,6 +11,9 @@ success_symbol = "[➜](bold green)" [package] disabled = true +[python] +disabled = true + [kubernetes] format = '[⛵ $context](green) ' disabled = false diff --git a/plugins/vim/vim.sh b/plugins/vim/vim.sh old mode 100644 new mode 100755 index 0bca3c5..65ea639 --- a/plugins/vim/vim.sh +++ b/plugins/vim/vim.sh @@ -10,31 +10,29 @@ if [[ -d "${FILES_USER_CONFIG}/vim" ]]; then local PATHOGEN_TMP="${VIM_SOURCE}/vim-pathogen"; if ! [[ -f "${VIMRUNTIME}/autoload/pathogen.vim" ]]; then - files_debug_log "[vim_install_plugins] installing pathogen.vim"; - if ! [[ -d "${PATHOGEN_TMP}" ]]; then - git clone git://github.com/tpope/vim-pathogen.git ${PATHOGEN_TMP}; - fi + # if ! [[ -d "${PATHOGEN_TMP}" ]]; then + # git clone git://github.com/tpope/vim-pathogen.git ${PATHOGEN_TMP}; + # fi + curl -LSso ${VIMRUNTIME}/autoload/pathogen.vim https://tpo.pe/pathogen.vim mkdir -p ${VIMRUNTIME}/autoload/; cp -r ${PATHOGEN_TMP}/autoload/* ${VIMRUNTIME}/autoload/; fi - if ! [[ -d ${VIM_BUNDLE} ]]; then + if ! [[ -d "${VIM_BUNDLE}" ]]; then files_debug_log "[vim_install_plugins] installing vim plugins..."; mkdir -p ${VIM_BUNDLE}; - pushd ${VIM_BUNDLE}; local PLUGINS=$(cat ${VIM}/plugins.txt); for plugin in ${PLUGINS}; do - if [[ "${plugin:0:3}" = "git" ]]; then + if [[ "${plugin:0:5}" = "https" ]]; then echo "Installing $plugin..."; - git clone -q $plugin > /dev/null & + git clone -q $plugin 2>&1 /dev/null & fi done - time wait; popd; fi