diff --git a/Earthfile b/Earthfile index 5345608..8220a69 100644 --- a/Earthfile +++ b/Earthfile @@ -36,7 +36,7 @@ golang-base: shell-formatting-base: FROM +golang-base RUN go install mvdan.cc/sh/v3/cmd/shfmt@v3.7.0 - DO +COPY_CI_DATA + DO +COPY_SOURCECODE check-shell-formatting: @@ -50,6 +50,7 @@ yaml-formatting-base: COPY ".yamlfmt" ".yamlfmt" DO +COPY_CI_DATA + check-yaml-formatting: FROM +yaml-formatting-base RUN ./ci/check-yaml-formatting.sh @@ -61,9 +62,11 @@ check-formatting: fix-shell-formatting: - FROM +sh-formatting-base + FROM +shell-formatting-base RUN ./ci/fix-shell-formatting.sh SAVE ARTIFACT "./ci" AS LOCAL "./ci" + SAVE ARTIFACT "./src" AS LOCAL "./src" + SAVE ARTIFACT "zsh-simple-abbreviations.zsh" AS LOCAL "zsh-simple-abbreviations.zsh" fix-yaml-formatting: @@ -94,7 +97,8 @@ check-github-actions-workflows-linting: COPY_SOURCECODE: COMMAND - COPY "./zsh-simple-abbreviations.zsh" "./zsh-simple-abbreviations.zsh" + DO +COPY_CI_DATA + COPY "./zsh-simple-abbreviations.zsh" "./zsh-simple-abbreviations.zsh" COPY "./src" "./src" COPY "./end-to-end-tests" "./end-to-end-tests" diff --git a/ci/check-shell-formatting.sh b/ci/check-shell-formatting.sh index 99dd161..1d602ea 100755 --- a/ci/check-shell-formatting.sh +++ b/ci/check-shell-formatting.sh @@ -3,4 +3,4 @@ set -o errexit set -o xtrace -shfmt --simplify --diff ./ci/* +shfmt --simplify --diff ./ci/* ./src/* zsh-simple-abbreviations.zsh diff --git a/ci/fix-shell-formatting.sh b/ci/fix-shell-formatting.sh index a183ba5..d725901 100755 --- a/ci/fix-shell-formatting.sh +++ b/ci/fix-shell-formatting.sh @@ -3,4 +3,4 @@ set -o errexit set -o xtrace -shfmt --simplify --write ./ci/* +shfmt --simplify --write ./ci/* ./src/* zsh-simple-abbreviations.zsh diff --git a/src/__zsh_simple_abbreviations_expand b/src/__zsh_simple_abbreviations_expand index 80e466c..c28a928 100644 --- a/src/__zsh_simple_abbreviations_expand +++ b/src/__zsh_simple_abbreviations_expand @@ -5,6 +5,7 @@ local MATCH # Can't use KEY_REGEX, but should match it. LBUFFER=${LBUFFER%%(#m)[[:alnum:]]#} # If matches set abbreviation add that else just add what we attempted to match on. -LBUFFER+=${${ZSH_SIMPLE_ABBREVIATIONS[$MATCH]}:-$MATCH} +abbreviation="${ZSH_SIMPLE_ABBREVIATIONS[$MATCH]}" +LBUFFER+=${abbreviation:-$MATCH} # Causes the syntax highlighting. zle self-insert diff --git a/src/zsh-simple-abbreviations b/src/zsh-simple-abbreviations index 841217a..6cff740 100644 --- a/src/zsh-simple-abbreviations +++ b/src/zsh-simple-abbreviations @@ -3,46 +3,46 @@ KEY_REGEX="^[[:alnum:]]+$" if [[ $# -eq 0 ]]; then - echo "zsh_simple_abbreviations no sub-command or arguments provided." - return 1 + echo "zsh_simple_abbreviations no sub-command or arguments provided." + return 1 fi case $1 in - --set) - if [[ $# -ne 3 ]]; then - echo "zsh_simple_abbreviations set sub-command requires a key and value." - return 1 - fi - - local key=${2} - local value=${3} - - if [[ "${key}" =~ ${KEY_REGEX} ]]; then - ZSH_SIMPLE_ABBREVIATIONS[$key]="${value}" - else - echo "zsh_simple_abbreviations key '${key}' contains non-alphanumeric characters." - return 1 - fi - ;; - - --unset) - if [[ $# -ne 2 ]]; then - echo "zsh_simple_abbreviations unset sub-command requires only a key." - return 1 - fi - - local key=${2} - - if [[ "${key}" =~ ${KEY_REGEX} ]]; then - unset "ZSH_SIMPLE_ABBREVIATIONS[${key}]" - else - echo "zsh_simple_abbreviations key '${key}' contains non-alphanumeric characters." - return 1 - fi - ;; - - *) - echo "zsh_simple_abbreviations unrecognised sub-command." - return 1 - ;; +--set) + if [[ $# -ne 3 ]]; then + echo "zsh_simple_abbreviations set sub-command requires a key and value." + return 1 + fi + + local key=${2} + local value=${3} + + if [[ ${key} =~ ${KEY_REGEX} ]]; then + ZSH_SIMPLE_ABBREVIATIONS[$key]="${value}" + else + echo "zsh_simple_abbreviations key '${key}' contains non-alphanumeric characters." + return 1 + fi + ;; + +--unset) + if [[ $# -ne 2 ]]; then + echo "zsh_simple_abbreviations unset sub-command requires only a key." + return 1 + fi + + local key=${2} + + if [[ ${key} =~ ${KEY_REGEX} ]]; then + unset "ZSH_SIMPLE_ABBREVIATIONS[${key}]" + else + echo "zsh_simple_abbreviations key '${key}' contains non-alphanumeric characters." + return 1 + fi + ;; + +*) + echo "zsh_simple_abbreviations unrecognised sub-command." + return 1 + ;; esac diff --git a/zsh-simple-abbreviations.zsh b/zsh-simple-abbreviations.zsh index 23bc2a5..8d8281c 100644 --- a/zsh-simple-abbreviations.zsh +++ b/zsh-simple-abbreviations.zsh @@ -1,20 +1,20 @@ #!/usr/bin/env zsh # Only run if executed in Zsh environment. -if [[ -n "${ZSH_VERSION}" ]]; then - # Create new abbreviations map. - typeset -Ag ZSH_SIMPLE_ABBREVIATIONS +if [[ -n ${ZSH_VERSION} ]]; then + # Create new abbreviations map. + typeset -Ag ZSH_SIMPLE_ABBREVIATIONS - fpath+=${0:A:h}/src - autoload -Uz zsh-simple-abbreviations + fpath+=${0:A:h}/src + autoload -Uz zsh-simple-abbreviations - # Create key binding on space to expand into a possible abbreviations. - autoload -Uz __zsh_simple_abbreviations_expand - zle -N __zsh_simple_abbreviations_expand - bindkey " " __zsh_simple_abbreviations_expand + # Create key binding on space to expand into a possible abbreviations. + autoload -Uz __zsh_simple_abbreviations_expand + zle -N __zsh_simple_abbreviations_expand + bindkey " " __zsh_simple_abbreviations_expand - # Create key binding on control + space to insert a space without any possible abbreviations expansion. - autoload -Uz __zsh_simple_abbreviations_insert_space - zle -N __zsh_simple_abbreviations_insert_space - bindkey "^ " __zsh_simple_abbreviations_insert_space + # Create key binding on control + space to insert a space without any possible abbreviations expansion. + autoload -Uz __zsh_simple_abbreviations_insert_space + zle -N __zsh_simple_abbreviations_insert_space + bindkey "^ " __zsh_simple_abbreviations_insert_space fi