From 22847db5299ef743f02c03bf2f6f9ca781b05ba7 Mon Sep 17 00:00:00 2001 From: NaeiKinDus Date: Sun, 23 Feb 2025 00:00:00 +0000 Subject: [PATCH] feat(common): fixed ydig zsh function; updated some other zsh related customizations --- .../roles/common/templates/home/.zsh_aliases | 8 +++-- .../common/templates/home/.zsh_completions | 7 ++-- .../roles/common/templates/home/.zsh_exports | 11 ++++--- .../common/templates/home/.zsh_functions | 33 ++++++++++++++++++- .../roles/common/templates/home/.zshrc | 25 ++++++++++++-- 5 files changed, 72 insertions(+), 12 deletions(-) diff --git a/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_aliases b/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_aliases index 2cf61c8..a1bd4fa 100644 --- a/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_aliases +++ b/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_aliases @@ -4,13 +4,15 @@ alias e="emacs" alias grep="egrep --color" alias cpr="rsync -rlptgoDAXhP --info=all0,progress2" alias rcp="cpr" -alias ll="eza -lahv --color" +alias ll="eza -lah --color" alias l="eza -l -g --icons --all --all" alias ls="eza" alias xclip="xclip -sel clipboard" alias git='GIT_COMMITTER_DATE="$(date +%Y-%m-%d) 00:00:00+0000" GIT_AUTHOR_DATE="$(date +%Y-%m-%d) 00:00:00+0000" git' -alias cat=bat -alias less=bat +alias cat=batcat +alias less=batcat +alias bat=batcat +alias emacs='emacsclient --create-frame --alternate-editor=""' # Dev alias dcl="docker container ls -a --format='{{ .ID }}\t{{ .Names }}\t{{ index (split .Status \" \") 0 }}' | sort -k3r -k2 | column -t -N ID,Name,State" diff --git a/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_completions b/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_completions index 507d54f..1405273 100644 --- a/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_completions +++ b/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_completions @@ -1,5 +1,6 @@ # https://github.com/zsh-users/zsh-completions fpath+=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions/src +fpath+=/usr/lib/x86_64-linux-gnu/rubygems-integration/3.1.0/gems/vagrant-2.3.8.dev/contrib/zsh # shellcheck disable=SC1090 if command -v ansible &> /dev/null; then @@ -14,9 +15,11 @@ if command -v ansible &> /dev/null; then source <(register-python-argcomplete ansible-vault) fi -autoload -U compinit && compinit - command -v boundary &> /dev/null && complete -o nospace -C /usr/bin/boundary boundary || true command -v molecule &> /dev/null && source <(_MOLECULE_COMPLETE=zsh_source molecule) || true command -v helm &> /dev/null && source <(helm completion zsh) || true command -v noseyparker &> /dev/null && source <(noseyparker shell-completions --shell zsh) || true + +[ -s "$NVM_DIR/bash_completion" ] && source "$NVM_DIR/bash_completion" + +autoload -U compinit && compinit diff --git a/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_exports b/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_exports index b90f2c1..5e7f6ed 100644 --- a/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_exports +++ b/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_exports @@ -3,7 +3,7 @@ export RUBY_VERSION="3.1" # Settings export DEFAULT_USER=$(id -un) -export EDITOR=emacs +export EDITOR="emacsclient -t" export TERM=xterm-256color export LESS='-R' export LESSOPEN='|~/.lessfilter %s' @@ -12,11 +12,13 @@ export SSH_KEY_PATH="${HOME}/.ssh/id_ed25519" export PAGER=less export GPG_TTY="${TTY}" +export PINENTRY_USER_DATA="connect/greeter" +{ [ -n "${SSH_CLIENT}" ] || [ -n "${SSH_CONNECTION}" ] || [ -n "${SSH_TTY}" ]; } && export PINENTRY_USER_DATA="connect/ssh" + # Dev -[ -d "$HOME/.nvm" ] && export NVM_DIR="$HOME/.nvm" -[ -d "$HOME/.nvm" ] && export NVM_SYMLINK_CURRENT=true -# shellcheck disable=SC1090 +export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh" # This loads nvm +# shellcheck disable=SC1090 [ -d "${HOME}/.local/share/gems/ruby/${RUBY_VERSION}" ] && export GEM_DIR="${HOME}/.local/share/gems/ruby/${RUBY_VERSION}" [ -d "${HOME}/.cargo/env" ] && source "${HOME}/.cargo/env" @@ -27,3 +29,4 @@ export PATH="${PATH}:${HOME}/.local/bin" [ -d "/usr/local/go/bin" ] && export PATH="${PATH}:/usr/local/go/bin" [ -d "$HOME/.cargo/bin" ] && export PATH="${PATH}:$HOME/.cargo/bin" [ -d "$HOME/.local/share/JetBrains/Toolbox/scripts" ] && export PATH="${PATH}:$HOME/.local/share/JetBrains/Toolbox/scripts" +[ -d "${HOME}/.config/emacs/bin" ] && export PATH="${PATH}:${HOME}/.config/emacs/bin" diff --git a/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_functions b/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_functions index 05b868d..2d9f3e9 100644 --- a/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_functions +++ b/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_functions @@ -1,5 +1,36 @@ function ydig() { - \dig +yaml "${@}" | yq '.[].message.response_message_data|{"answer": .ANSWER_SECTION, status}' + \dig +yaml "${@}" | yq '.[].message.response_message_data|{"answer": .ANSWER_SECTION, "status": .status}' +} + +function sshfs-target() { + local targetHost="${1}" + local remoteDir="${2}" + local mountPoint=${3} + + sshfs "${DEFAULT_USER:=$(id -un)}"@"${targetHost}":"${remoteDir}" "${mountPoint}" +} + +# Ex: ssh-forward 0.0.0.0:3306 bastion.host protected-sql-server.remote:3306 +function ssh-forward() { + local localIp="${1}" + shift + local jumpHost="${1}" + shift + local targetHost="${1}" + shift + + ssh -qN -L "${localIp}":"${targetHost}" "${jumpHost}" "${@}" +} + +function composerX() { + local composerBinary + local phpBinary + local phpVersion="${1}" + shift + composerBinary=$(command -v composer) + phpBinary=$(command -v php"${phpVersion}") + + ${phpBinary} "${composerBinary}" "${@}" } function kubeshell() { diff --git a/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zshrc b/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zshrc index ea8747d..43cd9d1 100644 --- a/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zshrc +++ b/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zshrc @@ -42,13 +42,34 @@ CASE_SENSITIVE="true" HIST_STAMPS="yyyy.mm.dd" -plugins=(autopep8 aws branch colored-man-pages colorize composer docker docker-compose git kubectl kube-ps1 npm nvm pass pep8 pip redis-cli rsync rust terraform) +plugins=( + autopep8 + aws + branch + colored-man-pages + colorize + composer + docker + docker-compose + git + kubectl + kube-ps1 + npm + nvm + pass + pep8 + pip + redis-cli + rsync + rust + terraform +) source $ZSH/oh-my-zsh.sh +[ -f ~/.env ] && source ~/.env [ -f ~/.zsh_exports ] && source ~/.zsh_exports [ -f ~/.p10k.zsh ] && source ~/.p10k.zsh [ -f ~/.zsh_functions ] && source ~/.zsh_functions [ -f ~/.zsh_aliases ] && source ~/.zsh_aliases -[ -f ~/.env ] && source ~/.env [ -f ~/.zsh_completions ] && source ~/.zsh_completions