Skip to content

Commit

Permalink
feat: adding remove and list commands
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperC286 committed Dec 29, 2021
1 parent 7eabbee commit 5798d8b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# ZSH Simple Abbreviations
[![pipeline status](https://img.shields.io/badge/Version-0.2.0-blue)](https://gitlab.com/DeveloperC/zsh-simple-abbreviations/commits/main) [![pipeline status](https://gitlab.com/DeveloperC/zsh-simple-abbreviations/badges/main/pipeline.svg)](https://gitlab.com/DeveloperC/zsh-simple-abbreviations/commits/main) [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org) [![License: AGPL v3](https://img.shields.io/badge/License-AGPLv3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
[![pipeline status](https://img.shields.io/badge/Version-0.3.0-blue)](https://gitlab.com/DeveloperC/zsh-simple-abbreviations/commits/main) [![pipeline status](https://gitlab.com/DeveloperC/zsh-simple-abbreviations/badges/main/pipeline.svg)](https://gitlab.com/DeveloperC/zsh-simple-abbreviations/commits/main) [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org) [![License: AGPL v3](https://img.shields.io/badge/License-AGPLv3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
48 changes: 42 additions & 6 deletions src/zsh-simple-abbreviations
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env zsh

VERSION='0.2.0'
VERSION='0.3.0'
KEY_REGEX="-_a-zA-Z0-9"

__zsh_simple_abbreviations::expand() {
Expand All @@ -21,14 +21,14 @@ __zsh_simple_abbreviations::insert_space() {

if [[ $# -eq 0 ]]; then
echo "zsh_simple_abbreviations no sub-command or arguments provided."
return
return 1
fi

case $1 in
--add)
if [[ $# -ne 3 ]]; then
echo "zsh_simple_abbreviations add sub-command requires a key and value."
return
return 1
fi

local key=${2}
Expand All @@ -38,19 +38,55 @@ case $1 in
_zsh_simple_abbreviations[$key]="${value}"
else
echo "zsh_simple_abbreviations add sub-command key does not match the regex '^[${KEY_REGEX}]*$'."
return
return 1
fi
;;

--remove)
if [[ $# -ne 2 ]]; then
echo "zsh_simple_abbreviations remove sub-command requires only a key."
return 1
fi

local key=${2}

if [[ $(echo "${key}" | grep -E "^[${KEY_REGEX}]*$") ]]; then
if [[ -n "${_zsh_simple_abbreviations[$key]}" ]]; then
unset "_zsh_simple_abbreviations[$key]"
else
echo "zsh_simple_abbreviations remove sub-command key does not match any abbreviations."
return 1
fi
else
echo "zsh_simple_abbreviations remove sub-command key does not match the regex '^[${KEY_REGEX}]*$'."
return 1
fi
;;


--list)
if [[ $# -ne 1 ]]; then
echo "zsh_simple_abbreviations list sub-command takes no other arguments."
return 1
fi

for key in ${(ko)_zsh_simple_abbreviations}; do
echo "zsh_simple_abbreviations --add ${key} '${_zsh_simple_abbreviations[$key]}'"
done
;;


--version)
if [[ $# -ne 1 ]]; then
echo "zsh_simple_abbreviations version sub-command takes no other arguments."
return
return 1
fi

echo "${VERSION}"
;;

*)
echo "zsh_simple_abbreviations unrecognised sub-command."
return
return 1
;;
esac

0 comments on commit 5798d8b

Please sign in to comment.