From f609cbde9a9c3e0bd9baf6c3703e4d7af4aa0275 Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Fri, 26 May 2023 17:07:03 -0700 Subject: [PATCH] Update profiles shell functions --- dot_config/profile/env.d/base.env.tmpl | 6 ++++ .../profile.d/{node.sh => alias.sh.tmpl} | 9 ++++-- .../profile.d/{base.sh => functions.sh.tmpl} | 29 ++++++++----------- .../profile/profile.d/hellotech.sh.tmpl | 3 +- dot_config/profile/profile.d/ruby.sh.tmpl | 4 +-- 5 files changed, 27 insertions(+), 24 deletions(-) rename dot_config/profile/profile.d/{node.sh => alias.sh.tmpl} (77%) rename dot_config/profile/profile.d/{base.sh => functions.sh.tmpl} (88%) diff --git a/dot_config/profile/env.d/base.env.tmpl b/dot_config/profile/env.d/base.env.tmpl index 0f1a3e1..785476d 100644 --- a/dot_config/profile/env.d/base.env.tmpl +++ b/dot_config/profile/env.d/base.env.tmpl @@ -6,6 +6,12 @@ HISTSIZE= MAN_DIR=${XDG_DATA_HOME}/man/man1 PATH=${XDG_BIN_HOME}:${PATH} +{{- if lookPath "nvim" }} +EDITOR=nvim +{{- else }} +EDITOR=vim +{{- end }} + {{ if lookPath "bat" -}} BAT_PAGER=never BAT_STYLE=plain diff --git a/dot_config/profile/profile.d/node.sh b/dot_config/profile/profile.d/alias.sh.tmpl similarity index 77% rename from dot_config/profile/profile.d/node.sh rename to dot_config/profile/profile.d/alias.sh.tmpl index 8da35ab..e35eb63 100644 --- a/dot_config/profile/profile.d/node.sh +++ b/dot_config/profile/profile.d/alias.sh.tmpl @@ -1,5 +1,8 @@ -# shellcheck shell=bash -#ft=sh - alias node_lts="curl --silent https://nodejs.org/dist/index.tab | cut -f 1,10 | grep -v '-' | head -n 2 | tail -n 1 | cut -f 1" alias node_current="curl --silent https://nodejs.org/dist/index.tab | cut -f 1,10 | grep '-' | head -n 1 | cut -f 1" + +{{ if lookPath "nvim" -}} +alias vim=nvim +{{- end }} + +# vim: filetype=sh diff --git a/dot_config/profile/profile.d/base.sh b/dot_config/profile/profile.d/functions.sh.tmpl similarity index 88% rename from dot_config/profile/profile.d/base.sh rename to dot_config/profile/profile.d/functions.sh.tmpl index 77288bb..50e44bb 100644 --- a/dot_config/profile/profile.d/base.sh +++ b/dot_config/profile/profile.d/functions.sh.tmpl @@ -1,13 +1,6 @@ -#ft=sh +# vim: filetype=sh #shellcheck shell=sh -if type nvim >/dev/null 2>/dev/null; then - export EDITOR=nvim - alias vim=nvim -else - export EDITOR=vim -fi - source_env_file() { if [ ! -f "${1}" ]; then return @@ -36,15 +29,13 @@ get_bitrate() ( echo "[ERROR] unknown file: $1" exit 1 fi - if ! command -v exiftool >/dev/null; then - echo "[ERROR] exiftool not installed" - exit 1 - fi + command_installed exiftool exiftool -AudioBitrate "$1" | awk '{print $4}' ) json_to_yaml() ( ARG=${1-} + command_installed bat dasel if [ -z "${ARG}" ]; then dasel --read json --write yaml | bat --language yaml elif [ -f "${ARG}" ]; then @@ -56,6 +47,7 @@ json_to_yaml() ( yaml_to_json() ( ARG=${1-} + command_installed bat dasel if [ -z "${ARG}" ]; then dasel --read yaml --write json | bat --language json elif [ -f "${ARG}" ]; then @@ -68,6 +60,7 @@ yaml_to_json() ( github_releases() ( USER=${1} REPO=${2-} + command_installed curl if [ -z "${REPO}" ]; then USER=$(echo "${1}" | sed 's|/| |g' | awk '{print $1}') REPO=$(echo "${1}" | sed 's|/| |g' | awk '{print $2}') @@ -79,6 +72,7 @@ github_releases() ( github_tags() ( USER=${1} REPO=${2-} + command_installed curl jq if [ -z "${REPO}" ]; then USER=$(echo "${1}" | sed 's|/| |g' | awk '{print $1}') REPO=$(echo "${1}" | sed 's|/| |g' | awk '{print $2}') @@ -90,11 +84,12 @@ github_tags() ( command_installed() ( set -ue - cmd=${1} - if ! command -v "${cmd}" 1>&2 >/dev/null; then - echo "${cmd} not installed" 1>&2 - exit 1 - fi + for cmd in "${@}"; do + if ! command -v "${cmd}" 1>&2 >/dev/null; then + echo "${cmd} not installed" 1>&2 + exit 1 + fi + done ) min_jpg() ( diff --git a/dot_config/profile/profile.d/hellotech.sh.tmpl b/dot_config/profile/profile.d/hellotech.sh.tmpl index bac6abe..9e52265 100644 --- a/dot_config/profile/profile.d/hellotech.sh.tmpl +++ b/dot_config/profile/profile.d/hellotech.sh.tmpl @@ -1,5 +1,4 @@ {{ if .hellotech -}} -#!/usr/bin/env bash k8s_last_config () ( dasel --read yaml --write json \ @@ -23,4 +22,6 @@ _add_path "/usr/local/opt/mysql-client/bin" _add_path "${HOME}/google-cloud-sdk/bin" unset _add_path + +# vim: filetype=sh {{- end }} diff --git a/dot_config/profile/profile.d/ruby.sh.tmpl b/dot_config/profile/profile.d/ruby.sh.tmpl index d185167..55e591b 100644 --- a/dot_config/profile/profile.d/ruby.sh.tmpl +++ b/dot_config/profile/profile.d/ruby.sh.tmpl @@ -2,9 +2,7 @@ # shellcheck shell=sh if [ "${RBENV_SHELL}" = "" ]; then - if command -v rbenv >/dev/null 2>&1 ; then - eval "$(rbenv init -)" - fi + eval "$(rbenv init -)" fi {{- end }}