From 726f011bca024e652de2cdf5fbc51373be48457a Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Mon, 23 Oct 2017 09:33:57 -0500 Subject: [PATCH] [meta] Move zmanage to function in init.zsh and delete the meta module altogether. Also refactor `tools/zim_issue` to use `tools/zim_info`, use local variables, and print the output directly without the need of the intermediate `issue_md` array. --- init.zsh | 40 +++++++++++++++++++++++++++++++ modules/meta/README.md | 21 ----------------- modules/meta/functions/zmanage | 40 ------------------------------- templates/zimrc | 2 +- tools/zim_issue | 43 +++++++++++----------------------- 5 files changed, 55 insertions(+), 91 deletions(-) delete mode 100644 modules/meta/README.md delete mode 100644 modules/meta/functions/zmanage diff --git a/init.zsh b/init.zsh index 43f7721..b2eeb42 100755 --- a/init.zsh +++ b/init.zsh @@ -39,3 +39,43 @@ fi fi done } + +zmanage() { + local usage="zmanage [action] +Actions: + update Fetch and merge upstream zim commits if possible + info Print zim and system info + issue Create a template for reporting an issue + clean-cache Clean the zim cache + build-cache Rebuild the zim cache + remove *experimental* Remove zim as best we can + reset Reset zim to the latest commit + debug Invoke the trace-zim script which produces logs + help Print this usage message" + + if (( ${#} != 1 )); then + print ${usage} + return 1 + fi + + case ${1} in + update) zsh ${ZIM_HOME}/tools/zim_update + ;; + info) zsh ${ZIM_HOME}/tools/zim_info + ;; + issue) zsh ${ZIM_HOME}/tools/zim_issue + ;; + clean-cache) source ${ZIM_HOME}/tools/zim_clean_cache && print 'Cache cleaned' + ;; + build-cache) source ${ZIM_HOME}/tools/zim_build_cache && print 'Cache rebuilt' + ;; + remove) zsh ${ZIM_HOME}/tools/zim_remove + ;; + reset) zsh ${ZIM_HOME}/tools/zim_reset + ;; + debug) zsh ${ZIM_HOME}/modules/debug/functions/trace-zim + ;; + *) print ${usage}; return 1 + ;; + esac +} diff --git a/modules/meta/README.md b/modules/meta/README.md deleted file mode 100644 index 32e4675..0000000 --- a/modules/meta/README.md +++ /dev/null @@ -1,21 +0,0 @@ -Meta -==== - -Provides aliases and functions for management of the zim framework, specifically `zmanage` - -Usage ------ - -`zmanage [arg]` - -| Action | Description | -| ----------- | --------------------------------------------------- | -| update | Fetches and merges upstream zim commits if possible | -| info | Prints zim and system info | -| issue | Create a template for reporting an issue | -| clean-cache | Clean the zim cache | -| build-cache | Rebuild the zim cache | -| remove | *experimental* Remove zim as best we can | -| reset | Reset zim to the latest commit | -| help | Print this usage message | -| debug | Invokes the trace-zim script which produces logs | diff --git a/modules/meta/functions/zmanage b/modules/meta/functions/zmanage deleted file mode 100644 index 075950c..0000000 --- a/modules/meta/functions/zmanage +++ /dev/null @@ -1,40 +0,0 @@ -local usage="${0} [action] -Actions: - | update | Fetches and merges upstream zim commits if possible | - | info | Prints zim and system info | - | issue | Create a template for reporting an issue | - | clean-cache | Clean the zim cache | - | build-cache | Rebuild the zim cache | - | remove | *experimental* Remove zim as best we can | - | reset | Reset zim to the latest commit | - | help | Print this usage message | - | debug | Invokes the trace-zim script which produces logs |" - -if (( ${#} != 1 )); then - print ${usage} - return 1 -fi - -local tools -tools="${ZIM_HOME}/tools" - -case ${1} in - update) zsh ${tools}/zim_update - ;; - info) zsh ${tools}/zim_info - ;; - issue) zsh ${tools}/zim_issue - ;; - clean-cache) source ${tools}/zim_clean_cache && print 'Cleaned cache' - ;; - build-cache) source ${tools}/zim_build_cache && print 'Rebuilt cache' - ;; - remove) zsh ${tools}/zim_remove - ;; - reset) zsh ${tools}/zim_reset - ;; - debug) zsh ${ZIM_HOME}/modules/debug/functions/trace-zim - ;; - *) print ${usage} - ;; -esac diff --git a/templates/zimrc b/templates/zimrc index 9aad0e6..203a7a6 100644 --- a/templates/zimrc +++ b/templates/zimrc @@ -11,7 +11,7 @@ # Select what modules you would like enabled. # The second line of modules may depend on options set by modules in the first # line. These dependencies are noted on the respective module's README.md. -zmodules=(directory environment git git-info history input utility meta custom \ +zmodules=(directory environment git git-info history input utility custom \ syntax-highlighting history-substring-search prompt completion) diff --git a/tools/zim_issue b/tools/zim_issue index bff3d6f..722784e 100644 --- a/tools/zim_issue +++ b/tools/zim_issue @@ -27,40 +27,25 @@ fi cd ${ZIM_HOME} # collect sys info -git_dirty=$(command git status --porcelain 2>/dev/null | tail -n1) -git_ref=$(command git rev-parse --short HEAD) -zsh_version=$(zsh --version) -operating_sys=$(uname -a) +local git_dirty=$(command git status --porcelain 2>/dev/null | tail -n1) +local zim_info=$(zsh tools/zim_info) +print "Environment Info +---------------- +${zim_info} +Description +----------- +${user_desc} -# we're going to template and build the issue here (as an array for convenience) +Steps to Reproduce +------------------ +${user_reproduce} -issue_md=("Environment Info" - "----------------" - "- Zim commit ref: ${git_ref}" - "- Zsh version: ${zsh_version}" - "- Operating System Info: ${operating_sys}" - "" - "Description" - "-----------" - "${user_desc}" - "" - "Steps to Reproduce" - "------------------" - "${user_reproduce}" - "" - "Images or other Information" - "---------------------------" - "" - ) - +Images or other Information +--------------------------- +" -# print the output: -# hack: we need to iterate over the elements to capture the blank spaces (to print newlines) -for (( i=0; i < ${#issue_md[@]}; i++ )); do - printf '%s\n' ${issue_md[i]} -done # if we have a dirty git, report it if [[ -n ${git_dirty} ]]; then