diff --git a/.gitmodules b/.gitmodules index fb4399d..c749e62 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,21 @@ [submodule "fonts"] path = include.d-libs/fonts - url = https://github.com/powerline/fonts.git + url = https://github.com/robfrawley/fonts-powerline.git [submodule "bright"] path = include.d-libs/bright url = https://github.com/src-run/bright-library.git +[submodule "include.d-libs/oh-my-zsh"] + path = include.d-libs/oh-my-zsh + url = https://github.com/robbyrussell/oh-my-zsh.git +[submodule "include.d-omzc/zsh-autosuggestions"] + path = include.d-libs/oh-my-zsh-plugins/auto-suggestions + url = https://github.com/zsh-users/zsh-autosuggestions.git +[submodule "include.d-omzc/zsh-syntax-highlighting"] + path = include.d-libs/oh-my-zsh-plugins/syntax-highlighting + url = https://github.com/zsh-users/zsh-syntax-highlighting.git +[submodule "include.d-libs/oh-my-zsh-plugins/wakatime"] + path = include.d-libs/oh-my-zsh-plugins/wakatime + url = https://github.com/sobolevn/wakatime-zsh-plugin.git +[submodule "include.d-libs/oh-my-zsh-plugins/history-substring-search"] + path = include.d-libs/oh-my-zsh-plugins/history-substring-search + url = https://github.com/zsh-users/zsh-history-substring-search.git diff --git a/dot-zsh.json b/dot-zsh.json index d6d222a..e90ee26 100644 --- a/dot-zsh.json +++ b/dot-zsh.json @@ -44,7 +44,8 @@ { "verbose": false, "quiet": true, - "debug": false + "debug": false, + "trace": false }, "show": { @@ -56,6 +57,7 @@ { "_enabled": true, "language": "en_US.UTF-8", + "def_user": "${USER}", "display": { "prompt_theme": "agnoster", @@ -80,41 +82,551 @@ "auto_check": true, "every_days": 7 }, - "plugins": [ - "git", - "git-auto-fetch", - "git-extras", - "gitignore", - "github", - "sudo", - "colored-man-pages", - "colorize", - "composer", - "bower", - "command-not-found", - "composer", - "docker", - "ruby", - "bundler", - "gem", - "chruby", - "gulp", - "grunt", - "node", - "npm", - "rake", - "rsync", - "screen", - "sublime", - "symfony", - "systemd", - "zsh-syntax-highlighting", - "history-substring-search" - ] + "customs": "{%%}", + "plugins": { + "adb": {}, + "bgnotify": { + "threshold": 4, + "formating": { + "[0]": { + "heading": "", + "message": "" + }, + "[^0]": "" + } + }, + "nvm": {}, + "git": {}, + "git-auto-fetch": {}, + "git-extras": {}, + "gitignore": {}, + "github": {}, + "sudo": {}, + "colored-man-pages": {}, + "colorize": {}, + "composer": {}, + "bower": {}, + "command-not-found": {}, + "composer": {}, + "docker": {}, + "ruby": {}, + "bundler": {}, + "gem": {}, + "chruby": {}, + "gulp": {}, + "grunt": {}, + "node": {}, + "npm": {}, + "rake": {}, + "rsync": {}, + "screen": {}, + "sublime": {}, + "symfony": {}, + "systemd": {}, + "wakatime": {}, + "zsh-syntax-highlighting": { + "main": { + "_enabled": true, + "contexts": [ + { + "token": "default", + "style": { + "foreground": "none", + "background": "none" + } + }, + { + "token": "unknown-token", + "style": { + "foreground": "red,bold" + } + }, + { + "token": "reserved-word", + "style": { + "foreground": "yellow" + } + }, + { + "token": "alias", + "style": { + "foreground": "green,underline" + } + }, + { + "token": "suffix-alias", + "style": { + "foreground": "green,underline" + } + }, + { + "token": "builtin", + "style": { + "foreground": "black", + "background": "green" + } + }, + { + "token": "function", + "style": { + "foreground": "green,bold" + } + }, + { + "token": "command", + "style": { + "foreground": "green" + } + }, + { + "token": "precommand", + "style": { + "foreground": "green,underline" + } + }, + { + "token": "commandseparator", + "style": { + "foreground": "black", + "background": "white,bold" + } + }, + { + "token": "path", + "style": { + "foreground": "white,underline" + } + }, + { + "token": "path_pathseparator", + "style": { + "foreground": "black,underline,bold" + } + }, + { + "token": "globbing", + "style": { + "foreground": "blue" + } + }, + { + "token": "history-expansion", + "style": { + "foreground": "blue" + } + }, + { + "token": "command-substitution", + "style": { + "foreground": "none", + "background": "none" + } + }, + { + "token": "command-substitution-delimiter", + "style": { + "foreground": "magenta" + } + }, + { + "token": "process-substitution", + "style": { + "foreground": "none", + "background": "none" + } + }, + { + "token": "process-substitution-delimiter", + "style": { + "foreground": "magenta" + } + }, + { + "token": "single-hyphen-option", + "style": { + "foreground": "none", + "background": "none" + } + }, + { + "token": "double-hyphen-option", + "style": { + "foreground": "none", + "background": "none" + } + }, + { + "token": "back-quoted-argument", + "style": { + "foreground": "none", + "background": "none" + } + }, + { + "token": "back-quoted-argument-delimiter", + "style": { + "foreground": "magenta" + } + }, + { + "token": "single-quoted-argument", + "style": { + "foreground": "yellow" + } + }, + { + "token": "double-quoted-argument", + "style": { + "foreground": "yellow" + } + }, + { + "token": "dollar-quoted-argument", + "style": { + "foreground": "yellow" + } + }, + { + "token": "rc-quote", + "style": { + "foreground": "cyan" + } + }, + { + "token": "dollar-double-quoted-argument", + "style": { + "foreground": "cyan" + } + }, + { + "token": "back-double-quoted-argument", + "style": { + "foreground": "cyan" + } + }, + { + "token": "back-dollar-quoted-argument", + "style": { + "foreground": "cyan" + } + }, + { + "token": "assign", + "style": { + "foreground": "none", + "background": "none" + } + }, + { + "token": "redirection", + "style": { + "foreground": "none", + "background": "none" + } + }, + { + "token": "comment", + "style": { + "foreground": "black,bold" + } + }, + { + "token": "arg0", + "style": { + "foreground": "green" + } + } + ] + }, + "brackets": { + "_enabled": true, + "contexts": [ + { + "token": "bracket-level-1", + "style": { + "foreground": "fg=blue,bold" + } + }, + { + "token": "bracket-level-2", + "style": { + "foreground": "fg=red,bold" + } + }, + { + "token": "bracket-level-3", + "style": { + "foreground": "fg=yellow,bold" + } + }, + { + "token": "bracket-level-4", + "style": { + "foreground": "fg=magenta,bold" + } + } + ] + }, + "cursor": { + "_enabled": true, + "contexts": [ + { + "token": "cursor", + "style": { + "background": "blue" + } + } + ] + }, + "pattern": { + "_enabled": false, + "contexts": [] + }, + "line": { + "_enabled": false, + "contexts": [ + { + "token": "line", + "style": { + "foreground": "bold", + "background": "bold" + } + } + ] + }, + "regexp": { + "_enabled": true, + "contexts": [ + { + "regex": "rm -rf *", + "style": { + "foreground": "white,bold", + "background": "red" + } + }, + { + "regex": "sudo", + "style": { + "foreground": "white", + "background": "red" + } + } + ] + }, + "root": { + "_enabled": false, + "contexts": [ + { + "token": "root", + "style": { + "foreground": "red,bold" + } + } + ] + } + }, + "history-substring-search": {} + } } }, "configs": { + "zsh": + { + "_enabled": true, + "internal_shell_opts": { + "aliases": null, + "all_export": null, + "always_last_prompt": null, + "always_to_end": null, + "append_history": null, + "auto_cd": null, + "auto_continue": null, + "auto_list": null, + "auto_menu": null, + "auto_name_dirs": null, + "auto_param_keys": null, + "auto_param_slash": null, + "auto_pushd": null, + "auto_remove_slash": null, + "auto_resume": null, + "bad_pattern": null, + "bang_hist": null, + "bare_glob_qual": null, + "bash_auto_list": null, + "bash_rematch": null, + "beep": null, + "bg_nice": null, + "brace_ccl": null, + "brace_expand": null, + "bsd_echo": null, + "c_bases": null, + "c_precedences": null, + "case_glob": null, + "case_match": null, + "cdable_vars": null, + "chase_dots": null, + "chase_links": null, + "check_jobs": null, + "clobber": null, + "combining_chars": null, + "complete_aliases": null, + "complete_in_word": null, + "correct": null, + "correct_all": null, + "csh_junkie_history": null, + "csh_junkie_loops": null, + "csh_junkie_quotes": null, + "csh_null_cmd": null, + "csh_null_glob": null, + "debug_before_cmd": null, + "dot_glob": null, + "dvorak": null, + "emacs": null, + "equals": null, + "err_exit": null, + "err_return": null, + "eval_lineno": null, + "exec": null, + "extended_glob": null, + "extended_history": null, + "flow_control": null, + "function_arg_zero": null, + "glob": null, + "glob_assign": null, + "glob_complete": null, + "glob_dots": null, + "glob_subst": null, + "global_export": null, + "global_rcs": null, + "hash_all": null, + "hash_cmds": null, + "hash_dirs": null, + "hash_list_all": null, + "hist_allow_clobber": null, + "hist_append": null, + "hist_beep": null, + "hist_expand": null, + "hist_expire_dups_first": null, + "hist_fcntl_lock": null, + "hist_find_no_dups": null, + "hist_ignore_all_dups": null, + "hist_ignore_dups": null, + "hist_ignore_space": null, + "hist_no_functions": null, + "hist_no_store": null, + "hist_reduce_blanks": null, + "hist_save_by_copy": null, + "hist_save_no_dups": null, + "hist_subst_pattern": null, + "hist_verify": null, + "hup": null, + "ignore_braces": null, + "ignore_eof": null, + "inc_append_history": null, + "interactive": null, + "interactive_comments": null, + "ksh_arrays": null, + "ksh_autoload": null, + "ksh_glob": null, + "ksh_option_print": null, + "ksh_typeset": null, + "ksh_zero_subscript": null, + "list_ambiguous": null, + "list_beep": null, + "list_packed": null, + "list_rows_first": null, + "list_types": null, + "local_options": null, + "local_traps": null, + "log": null, + "login": null, + "long_list_jobs": null, + "magic_equal_subst": null, + "mail_warn": null, + "mail_warning": null, + "mark_dirs": null, + "menu_complete": null, + "monitor": null, + "multi_func_def": null, + "multibyte": null, + "multios": null, + "no_bad_pattern": null, + "no_bang_hist": null, + "no_beep": null, + "no_clobber": null, + "no_exec": null, + "no_glob": null, + "no_hist_no_functions": null, + "no_ignore_braces": null, + "no_match": null, + "no_nomatch": null, + "no_prompt_cr": null, + "no_rcs": null, + "no_unset": null, + "notify": null, + "null_glob": null, + "numeric_glob_sort": null, + "octal_zeroes": null, + "one_cmd": null, + "overstrike": null, + "path_dirs": null, + "physical": null, + "posix_aliases": null, + "posix_builtins": null, + "posix_identifiers": null, + "print_eight_bit": null, + "print_exit_value": null, + "privileged": null, + "prompt_bang": null, + "prompt_cr": null, + "prompt_percent": null, + "prompt_sp": null, + "prompt_subst": null, + "prompt_vars": null, + "pushd_ignore_dups": null, + "pushd_minus": null, + "pushd_silent": null, + "pushd_to_home": null, + "rc_expand_param": null, + "rc_quotes": null, + "rcs": null, + "rec_exact": null, + "rematch_pcre": null, + "restricted": null, + "rm_star_silent": null, + "rm_star_wait": null, + "sh_file_expansion": null, + "sh_glob": null, + "sh_null_cmd": null, + "sh_option_letters": null, + "sh_word_split": null, + "share_history": null, + "shin_stdin": null, + "short_loops": null, + "single_command": null, + "single_line_zle": null, + "stdin": null, + "sun_keyboard_hack": null, + "track_all": null, + "transient_rprompt": null, + "traps_async": null, + "typeset_silent": null, + "unset": null, + "verbose": null, + "vi": null, + "warn_create_global": null, + "xtrace": null, + "zle": null + } + }, + "setups": + { + "_enabled": true, + "internal_variables": { + "NVM_DIR": "${NVM_DIR:-/opt/nvm}" + } + }, "editor": { "internal_session": "subl", @@ -128,13 +640,22 @@ "aliases": { "_enabled": true, - "set_simple_cmds": + "new_simple_commands": true, + "set_simple_commands": { - "ccat": "$(which pygmentize) -g", - "vcat": "$(which pygmentize) -g -O style=colorful,linenos=1", - "gpg": "$(which gpg2)" + "ccat": "pygmentize -g", + "vcat": "pygmentize -g -O style=colorful,linenos=1", + "grep": "grep --color=auto", + "fgrep": "fgrep --color=auto", + "egrep": "egrep --color=auto", + "ls": "ls --color=auto -I.gvfs", + "la": "ls --color=auto -I.gvfs -AlFhB", + "ll": "ls --color=auto -I.gvfs -Al", + "lf": "ls --color=auto -I.gvfs -AF", + "lc": "ls --color=auto -I.gvfs -FC" }, - "ssh_connections": + "new_ssh_connections": true, + "set_ssh_connections": { "obes": { @@ -156,6 +677,12 @@ { "user": "rmf", "host": "silverpapillon.com" + }, + "pi": + { + "user": "rmf", + "host": "10.0.0.150", + "port": 22555 } } }, @@ -163,6 +690,8 @@ { "_enabled": true, "paths": [ + "/opt/nginx-lint/bin", + "/opt/bin-collection/bin", "/opt/scripts/bin", "${HOME}/bin", "${HOME}/scripts", @@ -188,20 +717,27 @@ "completions": { "_enabled": true, + "bash_root_path": "/etc/bash_completion.d", "paths": [ - "${_DZ_PATH}/resources/completions" + "${_DZ_PATH}/resources/completions", + "{{bash_root_path}}/apport_completion", + "{{bash_root_path}}/dkms", + "{{bash_root_path}}/grub" ] }, "exports": { "_enabled": true, - "variables": [ - "ZSH", - "PATH", - "LANG", - "EDITOR", - "SSH_KEY_PATH" - ] + "first": { + "COMPOSER_HOME": "/opt/composer" + }, + "final": { + "ZSH": null, + "PATH": null, + "LANG": null, + "EDITOR": null, + "SSH_KEY_PATH": null + } } }, "plugins": @@ -210,7 +746,7 @@ "android_sdk": { "_enabled": true, - "mortal_root_path": "${HOME}/Android/Sdk", + "mortal_root_path": "/opt/android-sdk", "executable_paths": [ "{{mortal_root_path}}/platform-tools" ] @@ -226,7 +762,7 @@ { "_enabled": true, "system_root_path": "/usr/local/share/chruby", - "auto_set_version": "2.4.4", + "auto_set_version": "2.4.5", "env_source_files": [ "{{system_root_path}}/chruby.sh", "{{system_root_path}}/auto.sh" @@ -254,9 +790,9 @@ "golang": { "_enabled": true, - "system_root_path": "/usr/lib/go-1.10", + "system_root_path": "/usr/lib/go-1.11", "system_exec_path": "{{system_root_path}}/bin", - "mortal_root_path": "${HOME}/golang/1.10", + "mortal_root_path": "${HOME}/golang/1.11", "mortal_exec_path": "{{mortal_root_path}}/bin" }, "google_cloud_sdk": @@ -280,6 +816,55 @@ "{{mortal_root_path}}/bin" ] }, + "nvm": + { + "_enabled": true, + "mortal_root_path": "${NVM_DIR:-/opt/nvm}", + "assign_v_release": "default", + "completion_files": [ + "/usr/share/zsh/functions/Completion/Debian/_apt-fast" + ], + "remove_v_aliases": false, + "define_v_aliases": { + "lts-4": "4", + "lts-6": "6", + "lts-8": "8", + "lts-10": "10", + "latest": "11", + "default": "6" + }, + "define_v_install": [{ + "install_vers_nvm": "4", + "install_opts_use": "", + "install_with_npm": true, + "install_reqs_lts": true, + "removes_existing": false + }, { + "install_vers_nvm": "6", + "install_opts_use": "", + "install_with_npm": true, + "install_reqs_lts": true, + "removes_existing": false + }, { + "install_vers_nvm": "8", + "install_opts_use": "", + "install_with_npm": true, + "install_reqs_lts": true, + "removes_existing": false + }, { + "install_vers_nvm": "10", + "install_opts_use": "", + "install_with_npm": true, + "install_reqs_lts": true, + "removes_existing": false + }, { + "install_vers_nvm": "11", + "install_opts_use": "", + "install_with_npm": true, + "install_reqs_lts": false, + "removes_existing": false + }] + }, "phpenv": { "_enabled": true, @@ -305,6 +890,12 @@ "{{mortal_root_path}}/shell-config.rc" ] }, + "python_pip": { + "_enabled": true, + "initialize_evals": [ + "pip completion --zsh" + ] + }, "travis": { "_enabled": true, diff --git a/include.d-conf/10-000-env-define-debug.zsh b/include.d-conf/10-000-env-define-debug.zsh index 4c75a2a..5af6db8 100644 --- a/include.d-conf/10-000-env-define-debug.zsh +++ b/include.d-conf/10-000-env-define-debug.zsh @@ -15,14 +15,15 @@ # to true or 1. # -_cfg_ret_bool 'systems.dot_zsh.outs.quiet' 'true' && \ - _DZ_IO_VERBOSITY=-5 && \ +if _cfg_ret_bool 'systems.dot_zsh.outs.quiet' 'true'; then + _DZ_IO_VERBOSITY=-5 _log_buffer 2 "--- Setting verbosity to '-05: ...... quiet' due to config" +fi if [[ ${QUIET} -eq 1 ]] || [[ ${QUIET} == "true" ]]; then - _DZ_IO_VERBOSITY=-5 && \ - _log_buffer 2 \ - "--- Setting verbosity to '-05: ...... quiet' due to env var" + _DZ_IO_VERBOSITY=-5 + _log_buffer 2 \ + "--- Setting verbosity to '-05: ...... quiet' due to env var" fi @@ -31,14 +32,15 @@ fi # var is set to true or 1 (overwriting VERBOSE settings). # -_cfg_ret_bool 'systems.dot_zsh.outs.verbose' && \ - _DZ_IO_VERBOSITY=4 && \ +if _cfg_ret_bool 'systems.dot_zsh.outs.verbose'; then + _DZ_IO_VERBOSITY=4 _log_buffer 2 "--- Setting verbosity to '+04: very verbose' due to config" +fi if [[ ${VERY_VERBOSE} -eq 1 ]] || [[ ${VERY_VERBOSE} == "true" ]]; then - _DZ_IO_VERBOSITY=4 && \ - _log_buffer 2 \ - "--- Setting verbosity to '+04: very verbose' due to env var" + _DZ_IO_VERBOSITY=4 + _log_buffer 2 \ + "--- Setting verbosity to '+04: very verbose' due to env var" fi @@ -47,14 +49,15 @@ fi # to true or 1 (overwriting VERY_VERBOSE settings). # -_cfg_ret_bool 'systems.dot_zsh.outs.debug' && \ - _DZ_IO_VERBOSITY=10 && \ +if _cfg_ret_bool 'systems.dot_zsh.outs.debug'; then + _DZ_IO_VERBOSITY=10 _log_buffer 2 "--- Setting verbosity to '+10: ..... debug' due to config" +fi if [[ ${DEBUG} -eq 1 ]] || [[ ${DEBUG} == "true" ]]; then - _DZ_IO_VERBOSITY=10 && \ - _log_buffer 2 \ - "--- Setting verbosity to '+10: ..... debug' due to env var" + _DZ_IO_VERBOSITY=10 + _log_buffer 2 \ + "--- Setting verbosity to '+10: ..... debug' due to env var" fi @@ -62,6 +65,8 @@ fi # Set verbosity to "-5" (quiet) if it hasn't been set via config or env var. # -[[ ! ${_DZ_IO_VERBOSITY+x} ]] && _DZ_IO_VERBOSITY=-5 && \ +if [[ ! ${_DZ_IO_VERBOSITY+x} ]]; then + _DZ_IO_VERBOSITY=-5 _log_buffer 2 \ "--- Setting verbosity to '-05: ...... quiet' due default assignment" +fi diff --git a/include.d-conf/10-003-env-define-ssh.zsh b/include.d-conf/10-003-env-define-ssh.zsh index 68deef0..e2a4f34 100644 --- a/include.d-conf/10-003-env-define-ssh.zsh +++ b/include.d-conf/10-003-env-define-ssh.zsh @@ -10,6 +10,9 @@ # +# +# Assign ssh key path +# SSH_KEY_PATH=$(_cfg_get_string 'configs.ssh.cert_file' "${HOME}/.ssh/id_rsa") \ && _log_buffer 2 "--- Setting ssh key path to '${SSH_KEY_PATH}'" diff --git a/include.d-conf/50-000-env-define-zsh-history-substring-search.zsh b/include.d-conf/50-000-env-define-zsh-history-substring-search.zsh index d99a060..b3fff5d 100644 --- a/include.d-conf/50-000-env-define-zsh-history-substring-search.zsh +++ b/include.d-conf/50-000-env-define-zsh-history-substring-search.zsh @@ -14,20 +14,17 @@ # Remove all duplicate entries from history result set. # -#setopt HIST_IGNORE_ALL_DUPS +setopt HIST_IGNORE_ALL_DUPS # # Bind "up" and "down" arrow keys to history-substring-search plug-in. # -#zmodload zsh/terminfo +zmodload zsh/terminfo -#for n in ${_DZ_PLUG_HIST_SUB_SRCH_KEY_COMMANDS}; do -# printf "NAME[%s] TERM[%s]\n" "configs.key_bindings.${n}" "$( -# _cfg_get_string "configs.key_bindings.${n}" -# )" -# bindkey "${terminfo[$( -# _cfg_get_string "configs.key_bindings.${n}" -# )]}" "${n}" -#done +for n in ${_DZ_PLUG_HIST_SUB_SRCH_KEY_COMMANDS}; do + bindkey "${terminfo[$( + _cfg_get_string "configs.key_bindings.${n}" + )]}" "${n}" +done diff --git a/include.d-core/env-define-functions-bootstrap.zsh b/include.d-core/env-define-functions-bootstrap.zsh index 1def13c..b81b717 100644 --- a/include.d-core/env-define-functions-bootstrap.zsh +++ b/include.d-core/env-define-functions-bootstrap.zsh @@ -13,6 +13,7 @@ # # Date function # + function _get_date { local date @@ -33,6 +34,7 @@ function _get_date { # # Define function to return microsecond aware unix time. # + function _get_microtime { echo -n $(_get_date '%s.%N') } @@ -42,6 +44,7 @@ function _get_microtime { # String padding routine. # + function _out_indent { for i in `seq 1 ${1:-2}`; do echo -n " " @@ -52,6 +55,7 @@ function _out_indent { # # Format log output buffer # + function _format_buffer { printf '[%s:%s] %s%s' \ "${USER}/dot-zsh" \ @@ -64,6 +68,7 @@ function _format_buffer { # # Add to output buffer # + function _log_buffer { local indent="${1}"; shift local string diff --git a/include.d-core/env-define-functions-internal.zsh b/include.d-core/env-define-functions-internal.zsh index 34f8628..10ca033 100644 --- a/include.d-core/env-define-functions-internal.zsh +++ b/include.d-core/env-define-functions-internal.zsh @@ -18,6 +18,7 @@ function _o_nl { echo -en "\n" } + # # format and output text # @@ -69,13 +70,46 @@ function _get_unix_time_diff { local time_start="${1}" local time_ended="${2}" - _o_text '%.5f' $((${time_ended} - ${time_start})) + _o_text '%.4f' $((${time_ended} - ${time_start})) +} + +# +# get the width of terminal (number of columns) +# + +function _terminal_info_cols { + _o_text '%s' "$(tput cols 2> /dev/null)" +} + +# +# alias for _terminal_info_cols +# + +function _terminal_dims_w { + _terminal_info_cols +} + +# +# get the height of terminal (number of rows/lines) +# + +function _terminal_info_rows { + _o_text '%s' "$(tput lines 2> /dev/null)" +} + +# +# alias for _terminal_info_rows +# + +function _terminal_dims_h { + _terminal_info_rows } # # create ANSI color sequence with optional style # + function _ansi_color { local color="${1}" local style="${2:-}" @@ -91,7 +125,8 @@ function _ansi_color { # # disable (clear) all console formatting attributes # -function _ansi_clear { + +function _o_ansi_clear { echo -n "\e[0m" } @@ -99,31 +134,32 @@ function _ansi_clear { # # enable styling attributes: bold, dim, underline, blink, invert, and hide # -function _style_bold { + +function _o_style_bold { echo -n "\e[1m" } -function _style_dim { +function _o_style_dim { echo -n "\e[2m" } -function _style_underline { +function _o_style_underline { echo -n "\e[4m" } -function _style_blink { +function _o_style_blink { echo -n "\e[5m" } -function _style_invert { +function _o_style_invert { echo -n "\e[7m" } -function _style_hide { +function _o_style_hide { echo -n "\e[8m" } -function _style_strikeout { +function _o_style_strikeout { echo -n "\e[9m" } @@ -131,71 +167,72 @@ function _style_strikeout { # # output foreground ANSI color sequence # -function _fg_default { + +function _o_fg_default { echo -n $(_ansi_color 39 "${1}") } -function _fg_black { +function _o_fg_black { echo -n $(_ansi_color 30 "${1}") } -function _fg_red { +function _o_fg_red { echo -n $(_ansi_color 31 "${1}") } -function _fg_green { +function _o_fg_green { echo -n $(_ansi_color 32 "${1}") } -function _fg_yellow { +function _o_fg_yellow { echo -n $(_ansi_color 33 "${1}") } -function _fg_blue { +function _o_fg_blue { echo -n $(_ansi_color 34 "${1}") } -function _fg_magenta { +function _o_fg_magenta { echo -n $(_ansi_color 35 "${1}") } -function _fg_cyan { +function _o_fg_cyan { echo -n $(_ansi_color 36 "${1}") } -function _fg_light_gray { +function _o_fg_light_gray { echo -n $(_ansi_color 37 "${1}") } -function _fg_dark_gray { +function _o_fg_dark_gray { echo -n $(_ansi_color 90 "${1}") } -function _fg_light_red { +function _o_fg_light_red { echo -n $(_ansi_color 91 "${1}") } -function _fg_light_green { +function _o_fg_light_green { echo -n $(_ansi_color 92 "${1}") } -function _fg_light_yellow { +function _o_fg_light_yellow { echo -n $(_ansi_color 93 "${1}") } -function _fg_light_blue { +function _o_fg_light_blue { echo -n $(_ansi_color 94 "${1}") } -function _fg_light_magenta { +function _o_fg_light_magenta { echo -n $(_ansi_color 95 "${1}") } -function _fg_light_cyan { +function _o_fg_light_cyan { echo -n $(_ansi_color 96 "${1}") } -function _fg_white { +function _o_fg_white { echo -n $(_ansi_color 97 "${1}") } @@ -203,71 +240,72 @@ function _fg_white { # # output background ANSI color sequence # -function _bg_default { + +function _o_bg_default { echo -n $(_ansi_color 49 "${1}") } -function _bg_black { +function _o_bg_black { echo -n $(_ansi_color 40 "${1}") } -function _bg_red { +function _o_bg_red { echo -n $(_ansi_color 41 "${1}") } -function _bg_green { +function _o_bg_green { echo -n $(_ansi_color 42 "${1}") } -function _bg_yellow { +function _o_bg_yellow { echo -n $(_ansi_color 43 "${1}") } -function _bg_blue { +function _o_bg_blue { echo -n $(_ansi_color 44 "${1}") } -function _bg_magenta { +function _o_bg_magenta { echo -n $(_ansi_color 45 "${1}") } -function _bg_cyan { +function _o_bg_cyan { echo -n $(_ansi_color 46 "${1}") } -function _bg_light_gray { +function _o_bg_light_gray { echo -n $(_ansi_color 47 "${1}") } -function _bg_dark_gray { +function _o_bg_dark_gray { echo -n $(_ansi_color 100 "${1}") } -function _bg_light_red { +function _o_bg_light_red { echo -n $(_ansi_color 101 "${1}") } -function _bg_light_green { +function _o_bg_light_green { echo -n $(_ansi_color 102 "${1}") } -function _bg_light_yellow { +function _o_bg_light_yellow { echo -n $(_ansi_color 103 "${1}") } -function _bg_light_blue { +function _o_bg_light_blue { echo -n $(_ansi_color 104 "${1}") } -function _bg_light_magenta { +function _o_bg_light_magenta { echo -n $(_ansi_color 105 "${1}") } -function _bg_light_cyan { +function _o_bg_light_cyan { echo -n $(_ansi_color 106 "${1}") } -function _bg_white { +function _o_bg_white { echo -n $(_ansi_color 107 "${1}") } @@ -275,8 +313,155 @@ function _bg_white { # # remove all ANSI SGR and EL escape sequences # -function _ansi_rm_sgr_el { - echo "${1}" | sed -r "s/\x1b\[([0-9]{1,2}(;[0-9]{1,2})*)?m//g" + +function _o_ansi_al_sequence_remove { + _o_text '%s' "$(sed -r "s/\x1b\[([0-9]{1,2}(;[0-9]{1,2})*)?m//g" <<< "${1:-}")" +} + + +# +# calculate size of string +# + +function _str_length { + local text="${1}" + local ansi="${2:-false}" + + if [[ ${ansi} == "false" ]]; then + text="$(_o_ansi_al_sequence_remove "${text}")" + fi + + printf "${text}" 2> /dev/null | wc --chars 2> /dev/null +} + + +# +# remove both leading and trailing whitespace +# + +function _str_regexp_escape_chars { + local text="${1}" + + _o_text '%s' "$( + sed 's/[^^]/[&]/g; s/\^/\\^/g' 2> /dev/null <<< "${text}" + )" +} + + +# +# trim edge of string from passed items +# + +function _str_trim_edge { + local text="${1:-}" + local what="${2:- \\t\\n}" + + _o_text '%s' "$( + sed -E '{ N; s/^['${what}']*//;s/['${what}']*$//g }' 2> /dev/null <<< "${text}" + )" +} + + +# +# trim right of string from passed items +# + +function _str_trim_right_chars { + local text="${1:-}" + local char="${2:- }" + + _o_text '%s' "$(sed 's/[${char}]*$//g' <<< "${text}")" + return + local text="${1:-}" + local char="${2:- }" + local regx='s/[%s]*$//g' + + _o_text '%s' "$( + sed "$( + _o_text "${regx}" "$( + _str_regexp_escape_chars "${char[0]}" + )" + )" 2> /dev/null <<< "${text}" + )" +} + + +# +# trim left of string from passed items +# + +function _str_same_from_start { + local string="${1}" + local search="${2}" + + if [[ -n ${search} ]]; then + if [[ ${string:0:${#search}} != ${search} ]]; then + return 1 + fi + fi +} + + +# +# to-do: figure out what this does +# + +function _str_same_from_right { + local string="${1}" + local search="${2}" + + if [[ -n ${search} ]]; then + if [[ ${string:$((${#string} - ${#search}))} != ${search} ]]; then + return 1 + fi + fi +} + +function _str_tr_one_group { + local opt="${1:--d}" + local set="${2}" + local val="${@:3}" + + _str_same_from_start "${set}" '[' \ + || set="[${set}" + _str_same_from_right "${set}" ']' \ + || set+=']' + _str_same_from_start "${set}" '[:' \ + || set="[:${set:1}" + _str_same_from_right "${set}" ':]' \ + || set="${set:0:$((${#set} - 1))}:]" + + tr ${opt} "${set}" 2> /dev/null <<< "$( + _o_text "${val}" + )" +} + +function _str_drop_space_chars { + local text="${1}" + + sed 's/ //' 2> /dev/null <<< "$( + _o_text "${1}" + )" +} + +function _str_only_graphed_chars { + _str_tr_one_group '-cd' 'graph' "${@}" +} + +function _str_only_printed_chars { + _str_tr_one_group '-cd' 'print' "${@}" +} + +function _str_drop_control_chars { + _str_tr_one_group '-d' 'cntrl' "${@}" +} + +function _str_find_matches_only { + local search="${1}" + local string="${2}" + local option="${3:--P}" + + grep -o ${option} "${search}" 2> /dev/null <<< "${string}" } @@ -336,7 +521,7 @@ function _cfg_get_key { _cfg_get_json_contents \ | ${jq_bin} -e -r "$(_cfg_nor_key "${jq_key}") | keys" \ - | grep -o -E '[a-Z_]+' + | grep -o -E '[a-zA-Z0-9_-]+' return $? } @@ -418,6 +603,126 @@ function _cfg_req_array_values { _cfg_get_val "${1}[] | @text" } +function _cfg_val_sequence_interpret { + local inputs="${@}" + local result + + if ! result="$(eval "echo -ne "${inputs}"" 2> /dev/null)"; then + if ! result="$(echo -ne "${inputs}" 2> /dev/null)"; then + return 1 + fi + fi + + if [[ -n "${result}" ]]; then + _o_text "${result}" + else + _o_text "${inputs}" + fi +} + +function _cfg_resolve_anchor_replacement { + local anchor_tag_init="${1}" + local anchor_tag_term="${2}" + local anchor_val_text="${3}" + local anchor_ret_text + local anchor_key_pref="${4}" + local anchor_key_find="${anchor_val_text}" + local value_provided="${@:4}" + local value_answered + + if [[ -n ${anchor_key_pref} ]]; then + anchor_key_find="${anchor_key_pref}.${anchor_val_text}" + fi + + anchor_ret_text="$( + _cfg_req_string "$( + _cfg_nor_key "${anchor_key_find}" + )" 2> /dev/null + )" + + if [[ $? -ne 0 ]] || [[ -z ${anchor_ret_text} ]]; then + return 1 + fi + + value_answered="$( + _cfg_val_sequence_interpret \ + "${value_provided/\{\{$anchor_val_text\}\}/$anchor_ret_text}" + )" + + [[ $? -ne 0 ]] && return 1 || return 0 +} + +function _cfg_val_intern_anchor_matches { + local anchor_init="${1}" + local anchor_term="${2}" + local search_text="${3}" + local anchor_regx + local anchor_item + + anchor_init="$( + _str_only_graphed_chars "${anchor_init}" + )" + anchor_term="$( + _str_only_graphed_chars "${anchor_term}" + )" + anchor_regx="$( + printf '%s((?!%s|%s).)+%s' \ + "$(_str_regexp_escape_chars "${anchor_init}")" \ + "${anchor_init}" \ + "${anchor_term}" \ + "$(_str_regexp_escape_chars "${anchor_term}")" + )" + + _ifs_newlines + + for match in $(_str_find_matches_only "${anchor_regx}" "${search_text}" | _str_drop_space_chars); do + [[ -z "${match}" ]] && continue + + if tmp="$(_cfg_resolve_anchor_replacement '{{' '}}' "${matched}" "${key}" "${val}")"; then + val="${tmp}" && continue + fi + + if tmp="$(_cfg_resolve_anchor_replacement '{{' '}}' "${matched}" '' "${val}")"; then + val="${tmp}" && continue + fi + done + + _ifs_reset +} + + + +# +# Replace inner paths from JSON string +# + +function _cfg_val_intern_anchor_ref_resolver { + local key="${1%.*}"; shift + local val="${@}" + local tmp + local matched + local product + + _ifs_newlines + + for matched in $(grep -o -E '\{\{[^{]+\}\}' <<< "${val}" | grep -o -E '[^{}]+'); do + if [[ -z "${matched}" ]]; then + continue + fi + + if tmp="$(_cfg_resolve_anchor_replacement '{{' '}}' "${matched}" "${key}" "${val}")"; then + val="${tmp}" && continue + fi + + if tmp="$(_cfg_resolve_anchor_replacement '{{' '}}' "${matched}" '' "${val}")"; then + val="${tmp}" && continue + fi + done + + _ifs_reset + _o_text "${val}" +} + # # Replace inner paths from JSON string @@ -477,31 +782,52 @@ function _cfg_resolve_array { # function _cfg_nor_type { - case "${1:-}" in + local type="${1:-}" + + case "${type}" in s|str|string) - _o_text 'string' + _o_text 'string' \ + && return ;; n|num|number) - _o_text 'number' + _o_text 'number' \ + && return ;; b|bool|boolean) - _o_text 'boolean' + _o_text 'boolean' \ + && return ;; l|list) - _o_text 'list' + _o_text 'list' \ + && return ;; a|array) - _o_text 'array' + _o_text 'array' \ + && return ;; o|obj|object) - _o_text 'object' + _o_text 'object' \ + && return + ;; + e|empty|null) + _o_text 'null' \ + && return + ;; + d|def|default) + _o_text 'default' \ + && return ;; *) - _o_text 'unresolvable' - return 1 + _o_text "${type}" \ + && return 1 esac } + +# +# Checks if provided configuration index is of an expected type +# + function _cfg_is_type { local expected="${1:-}" local conf_key="${2:-}" @@ -534,6 +860,85 @@ function _cfg_is_type { } +# +# Checks if the provided configuration index is a null type +# + +function _cfg_is_null { + local conf_key="${1:-}" + + if ! _cfg_is_type null "${conf_key}" &> /dev/null; then + return 1 + fi +} + + +# +# Checks if the provided configuration index is any empty type +# + +function _cfg_is_bool_false_like { + local conf_key="${1:-}" + local exact_on="${1:-0}" + local conf_ilk + local conf_val + + conf_key="$( + _cfg_nor_key "${conf_key}" + )" + + conf_ilk="$( + _cfg_nor_type "$( + _cfg_get_type "${conf_key}" + )" + )" + + conf_val="$( + _cfg_get_val "$( + _cfg_nor_key "${conf_key}" + )" + )" + + [[ -z ${conf_val} ]] \ + && return + + case "${type_val}" in + s|str|string) + [[ ${conf_val} == '""' ]] \ + && return + ;; + n|num|number) + [[ ${conf_val} -gt 0 ]] \ + && return + ;; + b|bool|boolean) + _cast_bool_to_ret "${conf_val}" \ + && return + ;; + l|list) + [[ ${conf_val} == "[]" ]] \ + && return + [[ ${conf_val} == "{}" ]] \ + && return + ;; + a|array) + [[ ${conf_val} == "[]" ]] \ + && return + ;; + o|obj|object) + [[ ${conf_val} == "{}" ]] \ + && return + ;; + e|empty|null) + _cfg_is_null "${conf_key}" \ + && return + ;; + esac + + return 1 +} + + # # Attempt to resolve any value type # @@ -608,14 +1013,14 @@ function _cfg_get_bool { # function _cfg_ret_bool { - [[ "$(_cfg_get_bool "${1}" "${2}")" == "true" ]] \ - && return 0 \ - || return 1 + if [[ "$(_cfg_get_bool "${1}" "${2}")" != "true" ]]; then + return 1 + fi } # -# Read configuration string +# Read configuration array values # function _cfg_get_array_values { @@ -626,16 +1031,16 @@ function _cfg_get_array_values { # -# Read configuration string +# Read configuration array keys => values # -function _config_read_array_assoc { +function _cfg_get_array_assoc { local key="${1}" local set if _cfg_is_type object "${key}"; then for k in $(_cfg_get_key "${1}"); do - _o_text '%s=' "${k}" \ + _o_text '%s===>' "${k}" \ && _try_cfg_get_val $( _cfg_get_type "${key}[\"${k}\"]" ) "${key}[\"${k}\"]" "${def}" \ @@ -646,14 +1051,46 @@ function _config_read_array_assoc { } +# +# Read configuration array keys +# + +function _cfg_get_array_keys { + local key="${1}" + local set + + if _cfg_is_type object "${key}" || _cfg_is_type array "${key}"; then + for k in $(_cfg_get_key "${1}"); do + _o_line '%s' "${k}" + done + fi +} + + +# +# Read configuration array size +# + +function _cfg_get_array_size { + local key="${1}" + + if ! _cfg_is_type object "${key}" && ! _cfg_is_type array "${key}"; then + _o_text '%d' 0 + fi + + _o_text '%d' "$(_try_cfg_get_val number "${key} | length" 0)" +} + + # # trim line width to max columns of terminal window # + function _trim_line_width { local cols local line="${1}" - cols=$(tput cols) + cols=$(_terminal_dims_w) if [[ ${#line} -gt ${cols} ]]; then cols=$((${cols} - 3)) @@ -669,10 +1106,13 @@ function _trim_line_width { # function _logger_enabled { - return $( - _cfg_ret_bool \ - 'systems.dot_zsh.logs.enabled' - ) + if [[ -z ${_DZ_LOG_ENABLED} ]]; then + typeset -g _DZ_LOG_ENABLED + _cfg_ret_bool 'systems.dot_zsh.logs.enabled' + _DZ_LOG_ENABLED=$? + fi + + return ${_DZ_LOG_ENABLED} } @@ -681,16 +1121,29 @@ function _logger_enabled { # function _logger_file_path { - local default="${HOME}/.dot-zsh.log" + if [[ -z ${_DZ_INC_JSON_PATH} ]]; then + typeset -g _DZ_INC_JSON_PATH + _DZ_INC_JSON_PATH=$( + _cfg_get_string \ + 'systems.dot_zsh.logs.path' \ + "${HOME}/.dot-zsh.log" + ) + fi +} - if [[ -z "${_DZ_INC_JSON_PATH}" ]]; then - echo "${default}" - return + +# +# Return 0 if logging enabled, -255 otherwise. +# + +function _load_enabled { + if [[ -z ${_DZ_LOAD_ENABLED} ]]; then + typeset -g _DZ_LOAD_ENABLED + _cfg_ret_bool 'systems.dot_zsh.show.loading' + _DZ_LOAD_ENABLED=$? fi - _cfg_get_string \ - 'systems.dot_zsh.logs.path' \ - "${default}" + return ${_DZ_LOAD_ENABLED} } @@ -699,6 +1152,10 @@ function _logger_file_path { # function _wrt_log { + _load_enabled \ + && _o_progress_write \ + || _o_progress_close + local d="${1}" ; shift local l="${1}" ; shift local c="${1}" ; shift @@ -709,19 +1166,23 @@ function _wrt_log { typeset -g _DZ_LOG_BUFFER_LINES fi - p="$(_o_text '%s:%s' ${c} ${d})" - _DZ_LOG_BUFFER_LINES+=("${p} $(_o_text ${m} "$@")") - + if [[ ${_DZ_IO_VERBOSITY} -lt 0 ]]; then + return + fi + + p="$(_o_text '%s:%s' ${c} ${d})" + _DZ_LOG_BUFFER_LINES+=("${p} $(_o_text ${m} "$@")") + if [[ ! -z ${_DZ_LOGS_PATH} ]] && [[ "${#_DZ_LOG_BUFFER_LINES}" -gt 0 ]]; then for b in "${_DZ_LOG_BUFFER_LINES[@]}"; do _logger_enabled && \ - echo "${b}" | \ - tee -a "${_DZ_LOGS_PATH}" &> /dev/null + echo "${b}" | tee -a "${_DZ_LOGS_PATH}" &> /dev/null done _DZ_LOG_BUFFER_LINES=() fi + _file_out_buffer _buf_flush_lines } @@ -731,14 +1192,10 @@ function _wrt_log { # function _buf_flush_lines { - _cfg_ret_bool 'systems.dot_zsh.show.loading' 'true' \ - && _show_loading \ - || _disable_loading - if [[ ${_DZ_IO_VERBOSITY} -lt 0 ]]; then return fi - _disable_loading + _o_progress_close for line in ${_DZ_IO_BUFF_LINES[@]}; do _trim_line_width "$(_o_text '%s\n' "${line}")" @@ -752,19 +1209,18 @@ function _buf_flush_lines { # Define simple top-level std out logger function. # -function _log_normal { - local d - local m - local c="$USER/dot-zsh" - local l="${1}" ; shift +function _log_norm { + local d=$(_get_date %s) + local c="${USER}/${_DZ_NAME}" + local l="${1}" + shift + local m="$(_str_trim_right_chars "${1}")" + shift if [[ -z ${_DZ_IO_BUFF_NORM} ]]; then typeset -g _DZ_IO_BUFF_NORM fi - d=$(_get_date %s) - m="$(echo ${1} | sed 's/[ ]*$//g')" ; shift - if [[ ! "${m}" ]]; then return fi @@ -773,62 +1229,238 @@ function _log_normal { _log_buffer 0 "$(_o_text ${m} "$@")" } +function _get_log_control_action { + local name="${1}" + local default="${2}" + + for a in "${@:3}"; do + if [[ ${a:0:$((${#name} + 1))} == "${name}:" ]] && [[ $((${#a} - $((${#name} + 1)))) -gt 0 ]]; then + _o_text '%s' "${a:$((${#name} + 1))}" + return 0 + fi + done + + _o_text '%s' "${default}" +} + +function _filter_control_actions { + for s in "${@}"; do + if [[ ${s} =~ ^[a-z]+:.+$ ]]; then + continue + fi + + printf '%s\n' "${s}" + done +} + +function _log_message_compile { + local format="${1}" + local interp=() + local indent=$(_get_log_control_action indent 2 "${@:2}") + local marker="$(_get_log_control_action marker '-->' "${@:2}")" + local header="$(_get_log_control_action header '' "${@:2}")" + local a_temp + + _ifs_newlines + for a in $(_filter_control_actions "${@:2}"); do + if ! [[ ${a} =~ ^[a-z]+:.*$ ]]; then + interp+="${a}" + fi + done + _ifs_reset + + if [[ ${#header} -gt 0 ]]; then + header="$(tr '[:lower:]' '[:upper:]' <<< "${header}: ")" + fi + + _o_text "%s%s %s${format}" "$(_out_indent ${indent})" "${marker}" "${header}" "${interp[@]}" +} + +function _log_info { + _wrt_log "$(_get_date %s)" 0 "${USER}/${_DZ_NAME}" "$(_log_message_compile "${@}")" + _log_buffer 0 "$(_log_message_compile "${@}")" +} + + +# +# Define simple log warning. +# + +function _log_warn { + _wrt_log "$(_get_date %s)" 0 "${USER}/${_DZ_NAME}" "$(_log_message_compile "${@}" 'marker:###' 'header:warn')" + _log_buffer 0 "$(_log_message_compile "${@}" 'marker:###' 'header:warn')" +} + # # Define simple log notice. # -function _log_warn_old { - local d - local c="$USER/dot-zsh" - local m="!!! WARNING: $(echo ${1} | sed 's/[ ]*$//g')" ; shift - local l="${1:-2}" +function _log_crit { + _wrt_log "$(_get_date %s)" 0 "${USER}/${_DZ_NAME}" "$(_log_message_compile "${@}" 'indent:0' 'marker:!!!' 'header:crit')" + _log_buffer 0 "$(_log_message_compile "${@}" 'indent:0' 'marker:!!!' 'header:crit')" +} - d=$(_get_date %s) - _wrt_log "${d}" "${l}" "${c}" "$(_out_indent ${l})${m}" "$@" - _log_buffer 0 "$(_o_text ${m} "$@")" +# +# Simple info-level logger that interpolates the first format string argument +# with other passed replacement arguments, exposing the same signature as used +# with "_o_text" and other interpolating output functions. +# +# For example, take the following call, where the first argument defines the +# intended output string, and the remaining three arguments are all used as +# values for interpolation into the format string: +# +# > _logf_info 'Encountered %d info errors with input value of %s: "%s"' \ +# > ${errorCounter} \ +# > ${usersInValue} \ +# > ${errorMessage} +# + +function _logf_info { + _log_info "${@}" } # -# Define simple log warning. +# Simple warning-level logger that interpolates the first format string argument +# with other passed replacement arguments, exposing the same signature as used +# with "_o_text" and other interpolating output functions. +# +# For example, take the following call, where the first argument defines the +# intended output string, and the remaining three arguments are all used as +# values for interpolation into the format string: +# +# > _logf_warn 'Encountered %d warning errors with input value of %s: "%s"' \ +# > ${errorCounter} \ +# > ${usersInValue} \ +# > ${errorMessage} # -function _log_warn { - typeset -g _DZ_IO_BUFF_WARN +function _logf_warn { + _log_warn "${@}" +} - local c="!!WARNING!!" - local l=2 - local m="$1" - local d - local w +# +# Simple critical-level logger that interpolates the first format string argument +# with other passed replacement arguments, exposing the same signature as used +# with "_o_text" and other interpolating output functions. +# +# For example, take the following call, where the first argument defines the +# intended output string, and the remaining three arguments are all used as +# values for interpolation into the format string: +# +# > _logf_crit 'Encountered %d critical errors with input value of %s: "%s"' \ +# > ${errorCounter} \ +# > ${usersInValue} \ +# > ${errorMessage} +# - shift +function _logf_crit { + _log_crit "${@}" +} + + +# +# Simple info-level logger that handles interpolation of the format string +# just as "_logf_info" would (starting with the second argument and past), but +# adds a first argument to define the return value expected, allowing for +# "return" statements to be on the same line as the "_rlogf_info" call. +# +# For example, take the following call, where a info log entry is called and +# its return is then directly used to return from the shell context, as well: +# +# > if is_func_return_true; do +# > return $( +# > _logrf_info 255 'Disabling selective feature: %s' "${featDescription}" +# > ); +# > fi +# - d=$(_get_date %s) - w="$(_o_text ${m} "$@")" +function _logrf_info { + _logf_info "${@:2}" - _wrt_log "${d}" "${l}" "${c}" "$(_out_indent ${l})--> ${m}" - _log_buffer 0 "$(_o_text "---> ${m}" "$@")" + return $( + _get_sanitized_return_code "${1}" 0 + ) } # -# Define simple log notice. +# Simple warning-level logger that handles interpolation of the format string +# just as "_logf_warn" would (starting with the second argument and past), but +# adds a first argument to define the return value expected, allowing for +# "return" statements to be on the same line as the "_rlogf_warn" call. +# +# For example, take the following call, where a warning log entry is called and +# its return is then directly used to return from the shell context, as well: +# +# > if is_failure; do +# > return $( +# > _logrf_warn 255 'We hit a snag: %s' "${errorDescription}" +# > ); +# > fi # -function _log_crit { - local d - local c="$USER/dot-zsh" - local m="!!! CRITICAL: $(echo ${1} | sed 's/[ ]*$//g')" ; shift - local l="${1:-2}" +function _logrf_warn { + _logf_warn "${@:2}" - d=$(_get_date %s) + return $( + _get_sanitized_return_code "${1}" 0 + ) +} - _wrt_log "${d}" "${l}" "${c}" "$(_out_indent ${l})${m}" "$@" - _log_buffer 0 "$(_o_text ${m} "$@")" + +# +# Simple critical-level logger that handles interpolation of the format string +# just as "_logf_crit" would (starting with the second argument and past), but +# adds a first argument to define the return value expected, allowing for +# "return" statements to be on the same line as the "_rlogf_crit" call. +# +# For example, take the following call, where a critical log entry is called and +# its return is then directly used to return from the shell context, as well: +# +# > if is_failure; do +# > return $( +# > _logrf_crit 255 'We hit a snag: %s' "${errorDescription}" +# > ); +# > fi +# + +function _logrf_crit { + _logf_crit "${@:2}" + + return $( + _get_sanitized_return_code "${1}" 0 + ) +} + + +# +# Sanitize a return status code, primarily by ensuring it is a number and not +# a string, boolean, or other type. +# + +function _get_sanitized_return_code { + local status="${1}" + local useDef="${2:-0}" + + if ! [[ ${status} =~ ^-?[0-9]+$ ]]; then + if [[ ${useDef} =~ ^-?[0-9]+$ ]]; then + _logf_warn \ + 'Passed return "%s" not an integer; using default: "%s".' \ + "${status}" "${useDef}" + status=${useDef} + else + _logf_warn \ + 'Passed return "%s" and passed default "%s" are not integers; '\ + 'using hard-coded default: 0.' "${status}" "${useDef}" + status=0 + fi + fi + + _o_text "%d" "${status}" } @@ -892,6 +1524,7 @@ function _self_repo_parse_branch { # # Get last commit hash prepended with @ (i.e. @8a323d0) # + function _self_repo_parse_hash { export _DZ_SELF_COMMIT local prepend="${1:-0}" @@ -1190,140 +1823,6 @@ function _flatten_lines { } -# -# Define fancy complete message display function. -# - -function _show_summary { - local frmt_stat="%s - %s - %s" - local frmt_desc="%sInitialized %s%s@%s%s shell configuration%s" - local frmt_time="%s(%sloaded in %s seconds%s)%s" - local text_stat="${1:-OK}" - local text_desc - local text_time - local text_comp - local text_comp_no_seq - local columns - local pre_pad=0 - - columns=$(tput cols) - - text_desc="$( - _o_text "${frmt_desc}" \ - "$(_ansi_clear; _fg_light_gray; _style_dim)" \ - "$(_style_bold)" \ - "${USER}" \ - "$(hostname -s)" \ - "$(_ansi_clear; _fg_light_gray; _style_dim)" \ - "$(_ansi_clear)" - )" - - text_time="$( - _o_text "${frmt_time}" \ - "$(_fg_dark_gray; _style_dim)" \ - "$(_fg_dark_gray)" \ - "$( - _get_unix_time_diff \ - "${_DZ_LOAD_TIME}" \ - "$(_get_microtime)" - )" \ - "$(_fg_dark_gray; _style_dim)" \ - "$(_ansi_clear)" - )" - - text_stat="$( - _o_text "${frmt_stat}" \ - "$(_fg_green; _bg_black; _style_invert; _style_bold)" \ - "${text_stat}" \ - "$(_ansi_clear)" - )" - - text_comp="$( - _o_text "%s %s $(_fg_light_gray; _style_dim)...$(_ansi_clear) %s" \ - "${text_desc}" \ - "${text_time}" \ - "${text_stat}" - )" - - text_comp_no_seq=$(_ansi_rm_sgr_el "${text_comp}") - pre_pad=$((${columns} - ${#text_comp_no_seq} - 1)) - - _ansi_clear - echo -en "\n" - - if [[ ${pre_pad} -gt 0 ]]; then - for i in $(seq 1 ${pre_pad}); do - echo -en ' ' - done - fi - - echo -en "${text_comp}\n" && \ - _ansi_clear -} - - -# -# ready loading global vars -# - -function _show_loader_globals { - if [[ -z ${_DZ_LOADER_OUT_LVL} ]]; then - typeset -g _DZ_LOADER_OUT_LVL=0 - typeset -g _DZ_LOADER_DISABLE=0 - typeset -g _DZ_LOADER_CLEARED=0 - fi -} - - -# -# Define fancy complete message display function. -# - -function _disable_loading { - _show_loader_globals - _clear_loading - _DZ_LOADER_DISABLE=1 -} - - -# -# Define fancy complete message display function. -# - -function _clear_loading { - _show_loader_globals - - if [[ ${_DZ_LOADER_OUT_LVL} -eq 1 ]] && [[ ${_DZ_LOADER_DISABLED} -eq 0 ]] && [[ ${_DZ_LOADER_CLEARED} -eq 0 ]]; then - clear - fi - - _DZ_LOADER_OUT_LVL=0 - _DZ_LOADER_CLEARED=1 -} - - -# -# Define fancy complete message display function. -# - -function _show_loading { - _show_loader_globals - - if [[ ${_DZ_LOADER_DISABLE} -eq 1 ]]; then - return - fi - - _DZ_LOADER_CLEARED=0 - - if [[ ${_DZ_LOADER_OUT_LVL} -eq 1 ]]; then - _o_text "$(_ansi_clear; _fg_dark_gray; _style_dim).$(_ansi_clear)" - else - _o_text "\n $(_ansi_clear; _fg_dark_gray; _style_bold)Loading$(_ansi_clear)$(_ansi_clear; _fg_dark_gray; _style_dim)...$(_ansi_clear)" - _DZ_LOADER_OUT_LVL=1 - fi -} - - # # Define simple logger for include files. # @@ -1331,7 +1830,7 @@ function _show_loading { function _log_source { local i="$1" ; shift ; local l="$1" ; shift ; local m="$1" ; shift - _log_normal "${l}" "$(_out_indent ${i})--> ${m}" "$@" + _log_norm "${l}" "$(_out_indent ${i})--> ${m}" "$@" } @@ -1346,7 +1845,7 @@ function _log_action { shift fi - _log_normal 4 "$(_out_indent ${i})--- ${m}" "$@" + _log_norm 4 "$(_out_indent ${i})--- ${m}" "$@" } @@ -1362,13 +1861,13 @@ function _add_env_path_dir { t="${2:-default}" if [[ ! -d "${p}" ]]; then - _log_normal 2 \ + _log_norm 2 \ " --- Skipping '${p}' addition to 'PATH' environment variable (does not exist)" return fi if [[ ":$PATH:" == *":${p}:"* ]]; then - _log_normal 2 \ + _log_norm 2 \ " --- Skipping '${p}' addition to 'PATH' environment variable (already added)" return fi @@ -1384,6 +1883,7 @@ function _add_env_path_dir { # function _aliases_setup_ssh_connections { + local indented="${1:-3}" local prefixes=( "ssh-" "s-" "" ) local opts_desc local host @@ -1394,10 +1894,10 @@ function _aliases_setup_ssh_connections { local alias_k local alias_v - for name in $(_cfg_get_key 'configs.aliases.ssh_connections'); do + for name in $(_cfg_get_key 'configs.aliases.set_ssh_connections'); do host="$( _cfg_get_string \ - "configs.aliases.ssh_connections[\"${name}\"].host" \ + "configs.aliases.set_ssh_connections[\"${name}\"].host" \ 'false' )" @@ -1407,7 +1907,7 @@ function _aliases_setup_ssh_connections { port="$( _cfg_get_number \ - "configs.aliases.ssh_connections[\"${name}\"].port" \ + "configs.aliases.set_ssh_connections[\"${name}\"].port" \ 'false' )" @@ -1417,7 +1917,7 @@ function _aliases_setup_ssh_connections { user="$( _cfg_get_string \ - "configs.aliases.ssh_connections[\"${name}\"].user" \ + "configs.aliases.set_ssh_connections[\"${name}\"].user" \ 'false' )" @@ -1427,7 +1927,7 @@ function _aliases_setup_ssh_connections { opts="$( _cfg_get_string \ - "configs.aliases.ssh_connections[\"${name}\"].opts" \ + "configs.aliases.set_ssh_connections[\"${name}\"].opts" \ 'false' )" @@ -1437,7 +1937,7 @@ function _aliases_setup_ssh_connections { wait="$( _cfg_get_number \ - "configs.aliases.ssh_connections[\"${name}\"].wait" \ + "configs.aliases.set_ssh_connections[\"${name}\"].wait" \ 'false' )" @@ -1460,14 +1960,15 @@ function _aliases_setup_ssh_connections { "${wait}" )" - if ( which "${alias_key}" &> /dev/null ); then - continue && \ - _log_action "Alias skipped (name exists) "\ - "'${alias_key}=\"${alias_val}\"'" + if _cfg_ret_bool 'configs.aliases.new_ssh_connections' 'true' && alias | grep -E "^${alias_key}=" &> /dev/null; then + unalias "${alias_key}" 2> /dev/null \ + && _log_action "Removed prior alias: '${alias_key}'" ${indented} \ + || _log_action "Failed alias remove: '${alias_key}'" ${indented} fi - alias $alias_key="${alias_val}" &> /dev/null && \ - _log_action "Alias defined '${alias_key}' => '${alias_val}'" + alias "${alias_key}"="${alias_val}" &> /dev/null \ + && _log_action "Defined alias value: '${alias_key}' => '${alias_val}'" ${indented} \ + || _log_action "ailed alias assign: '${alias_key}' => '${alias_val}'" ${indented} done done } @@ -1526,7 +2027,7 @@ function _aliases_build_ssh_command { # function _get_array_key { - echo "${1%%=*}" + echo "${1%%===>*}" } @@ -1535,7 +2036,7 @@ function _get_array_key { # function _get_array_val { - echo "${1#*=}" + echo "${1#*===>}" } @@ -1593,7 +2094,7 @@ function _log_src_fail { local levl=${3:-1} local what=${4:-} - _log_normal ${levl} "$( + _log_norm ${levl} "$( _printf_log_src 'Failures for' "${file}" "${desc}" ${levl} "${what}" )" } @@ -1609,7 +2110,7 @@ function _log_src_skip { local levl=${3:-1} local what=${4:-} - _log_normal ${levl} "$( + _log_norm ${levl} "$( _printf_log_src 'Skipping the' "${file}" "${desc}" ${levl} "${what}" )" } @@ -1625,7 +2126,7 @@ function _log_src_done { local levl=${3:-1} local what=${4:-} - _log_normal ${levl} "$( + _log_norm ${levl} "$( _printf_log_src 'Sourcing the' "${file}" "${desc}" ${levl} "${what}" )" } @@ -1883,7 +2384,7 @@ function _log_definition_list { _DZ_IO_BUFF_DEFINITION_VALUES=() for k v in ${(@kv)lines}; do - _log_normal \ + _log_norm \ ${_DZ_IO_BUFF_DEFINITION_INDENT[$k]} \ "$(_out_indent ${_DZ_IO_BUFF_DEFINITION_INDENT[$k]})${_DZ_IO_BUFF_DEFINITION_PREFIX[$k]} ${v}" done @@ -1897,16 +2398,63 @@ function _log_definition_list { # reverse boolean value # -function _bool_reverse { - ([[ "${1}" == "true" ]] || [[ ${1} == 1 ]]) \ - && _o_text false \ - || _o_text true +function _cast_bool_to_inverse_string { + local bool="${1:-1}" + + if _cast_bool_to_ret "${bool}"; then + _o_text false + else + _o_text true + fi +} + + +# +# reverse boolean value +# + +function _cast_bool_to_string { + local bool="${1:-1}" + + if _cast_bool_to_ret "${bool}"; then + _o_text true + else + _o_text false + fi +} + + +# +# reverse boolean value +# + +function _cast_bool_to_ret { + local bool="${1:-1}" + + if [[ $(_str_trim_edge ${bool}) =~ ^(true|TRUE|yes|YES|y|Y|0)$ ]]; then + return 0 + else + return 1 + fi +} + + +# +# reverse boolean value +# + +function _cast_bool_to_int { + local bool="${1:-1}" + + _cast_bool_to_ret "${1}" + _o_text '%d' $? } # # Add to output buffer # + function _file_log_buffer { local string="${1}" local indent="${2:-3}"; shift @@ -1921,22 +2469,22 @@ function _file_log_buffer { # function _file_out_buffer { - if [[ ${_DZ_IO_VERBOSITY} -lt 0 ]]; then - if [[ -f "${_DZ_PATH_OUT_BUFFERING}" ]]; then - rm -f "${_DZ_PATH_OUT_BUFFERING}" - fi - + if [[ ! -f "${_DZ_PATH_OUT_BUFFERING}" ]]; then return fi - _ifs_newlines - for l in $(cat "${_DZ_PATH_OUT_BUFFERING}"); do - _trim_line_width "$(_o_text '%s\n' "${l}")" - done - _ifs_reset - - if [[ -f "${_DZ_PATH_OUT_BUFFERING}" ]]; then + if [[ ${_DZ_IO_VERBOSITY} -lt 0 ]]; then rm -f "${_DZ_PATH_OUT_BUFFERING}" + else + _ifs_newlines + for l in $(cat "${_DZ_PATH_OUT_BUFFERING}"); do + _trim_line_width "$(_o_text '%s\n' "${l}")" + done + _ifs_reset + + if [[ -f "${_DZ_PATH_OUT_BUFFERING}" ]]; then + rm -f "${_DZ_PATH_OUT_BUFFERING}" + fi fi } @@ -1958,3 +2506,346 @@ function _log_assignment { _o_text "${val}" } + + + + +# +# Output padding of the specified length +# + +function _o_padding { + local padding_len="${1:-0}" + local padding_str="${2:- }" + + if [[ ${padding_len} -gt 0 ]]; then + for i in $(seq 1 ${padding_len}); do + _o_text "${padding_str}" + done + fi +} + + +# +# Define fancy complete message display function. +# + +function _load_summary_display { + local padding_len=0 + local format_stat="%s - %s - %s" + local format_info="%sInitialized %s%s@%s%s shell configuration%s" + local format_used="%s(%sloaded in %s seconds and mapped %s%s memory%s)%s" + local format_comp="%s %s %s...%s %s" + local string_stat="${1:-OK}" + local string_ansi + local string_none + local memory_used + local memory_size + local memory_type + + memory_used="$( + pmap -d ${$} 2> /dev/null \ + | tail -n 1 2> /dev/null \ + | sed -E 's/^mapped: ([0-9]+[A-Z]{0,2}).+/\1/g' 2> /dev/null + )" + memory_size="$( + grep -o -E '[0-9]+' <<< "${memory_used}" + )" + memory_type="$( + grep -o -E '[A-Z]{0,3}' <<< "${memory_used}" + )" + string_ansi="$( + _o_text "${format_comp}" \ + "$( + _o_text "${format_info}" \ + "$(_o_ansi_clear; _o_fg_light_gray; _o_style_dim)" \ + "$(_o_style_bold)" \ + "${USER}" \ + "$(hostname -s)" \ + "$(_o_ansi_clear; _o_fg_light_gray; _o_style_dim)" \ + "$(_o_ansi_clear)" + )" \ + "$( + _o_text "${format_used}" \ + "$(_o_fg_dark_gray; _o_style_dim)" \ + "$(_o_fg_dark_gray)" \ + "$( + _get_unix_time_diff \ + "${_DZ_LOAD_TIME}" \ + "$(_get_microtime)" + )" \ + "$( + LC_NUMERIC=en_US printf "%'.f\n" "${memory_size}" + )" \ + "${memory_type}" \ + "$(_o_fg_dark_gray; _o_style_dim)" \ + "$(_o_ansi_clear)" + )" \ + "$(_o_fg_light_gray; _o_style_dim)" \ + "$(_o_ansi_clear)" \ + "$( + _o_text "${format_stat}" \ + "$(_o_fg_green; _o_bg_black; _o_style_invert; _o_style_bold)" \ + "${string_stat}" \ + "$(_o_ansi_clear)" + )" + )" + + string_none=$(_o_ansi_al_sequence_remove "${string_ansi}") + padding_len=$(($(_terminal_dims_w) - ${#string_none} - 2)) + + _o_nl + _o_padding ${padding_len} + _o_line "${string_ansi}" + _o_ansi_clear +} + + +# +# manage progress loader state configuration for terminal info +# + +function _o_progress_cfg_state_setup_terminal_info { + typeset -g _DZ_LOADER_COL_MAX=$(_terminal_dims_w) + typeset -g _DZ_LOADER_COL_POS=${_DZ_LOADER_COL_POS:-0} +} + + +# +# manage progress loader state configuration for loader action type +# + +function _o_progress_cfg_state_setup_loader_action { + typeset -g _DZ_LOADER_STARTED=${_DZ_LOADER_STARTED:-0} + typeset -g _DZ_LOADER_DISABLE=${_DZ_LOADER_DISABLE:-0} + typeset -g _DZ_LOADER_CLEARED=${_DZ_LOADER_CLEARED:-0} +} + + +# +# manage progress loader state configuration +# + +function _o_progress_cfg_state_setup { + _o_progress_cfg_state_setup_terminal_info + _o_progress_cfg_state_setup_loader_action +} + + +# +# manage progress loader state configuration for terminal info +# + +function _o_progress_cfg_state_reset_terminal_info { + typeset -g _DZ_LOADER_COL_MAX=$(_terminal_dims_w) + typeset -g _DZ_LOADER_COL_POS=0 +} + + +# +# manage progress loader state configuration for loader action type +# + +function _o_progress_cfg_state_reset_loader_action { + typeset -g _DZ_LOADER_STARTED=0 + typeset -g _DZ_LOADER_DISABLE=0 + typeset -g _DZ_LOADER_CLEARED=1 +} + + +# +# manage progress loader state configuration +# + +function _o_progress_cfg_state_reset { + _o_progress_cfg_state_reset_terminal_info + _o_progress_cfg_state_reset_loader_action +} + + +# +# manage progress loader state configuration +# + +function _o_progress_cfg_state_close { + _o_progress_cfg_state_setup + _DZ_LOADER_DISABLE=1 +} + + +# +# manage progress loader state configuration +# + +function _o_progress_cfg_state_clear { + _o_progress_cfg_state_setup + _DZ_LOADER_CLEARED=0 +} + + +# +# manage progress loader state configuration +# + +function _o_progress_cfg_state_start { + _o_progress_cfg_state_clear + _DZ_LOADER_STARTED=1 +} + + +# +# Define fancy complete message display function. +# + +function _o_progress_close { + local reset="${1:-0}" + + _o_progress_cfg_state_setup + + if [[ ${_DZ_LOADER_STARTED} -eq 1 ]] && [[ ${_DZ_LOADER_DISABLE} -ne 1 ]]; then + _o_progress_write_step_char_term && sleep 0.75 && reset=1 + fi + + [[ ${reset} -eq 1 ]] && _o_progress_reset + + _o_progress_cfg_state_close +} + + +# +# Define fancy complete message display function. +# + +function _o_progress_reset { + _o_progress_cfg_state_setup + + if [[ ${_DZ_LOADER_STARTED} -eq 1 ]] && [[ ${_DZ_LOADER_DISABLED} -eq 0 ]] && [[ ${_DZ_LOADER_CLEARED} -eq 0 ]]; then + clear + fi + + _o_progress_cfg_state_reset +} + + +function _o_progress_tracked_write_step_section { + local frmt="%s%s%s" + local text="${1}" + + _o_progress_tracked_write_text \ + "${frmt}" \ + "$(_o_ansi_clear; _o_fg_dark_gray; _o_style_dim)" \ + "${text}" \ + "$(_o_ansi_clear)" +} + + +function _o_progress_tracked_write_nl { + _o_progress_cfg_state_reset_terminal_info + _o_nl +} + + +function _o_progress_tracked_write_text { + local text + + text="$(_o_text "${@}")" + _DZ_LOADER_COL_POS=$(( ${_DZ_LOADER_COL_POS} + $(_str_length "${text}" "false") )) + + _o_text "${text}" +} + + +function _o_progress_tracked_write_pads { + local size="${1}" + + _o_padding ${size} + _DZ_LOADER_COL_POS=$(( ${_DZ_LOADER_COL_POS} + ${size} )) +} + + +# +# Output load progress step indicator +# + +function _o_progress_write_step_section { + local text="${1}" + local incs="${2:-true}" + + if [[ ${incs} == "true" ]] && [[ ${_DZ_LOADER_COL_POS} -ge $(( ${_DZ_LOADER_COL_MAX} - 3 )) ]]; then + _o_progress_write_step_char_term "false" + _o_progress_write_step_text + fi + + _o_progress_tracked_write_step_section "${text}" +} + + +# +# Write progress iteration step character: initializing (first) character +# + +function _o_progress_write_step_char_init { + _o_progress_write_step_section "[" +} + + +# +# Write progress iteration step character: terminating (last) character +# + +function _o_progress_write_step_char_term { + _o_progress_write_step_section "] " "${1:-true}" +} + + +# +# Write progress iteration step character +# + +function _o_progress_write_step_char { + _o_progress_write_step_section "—" +} + + +# +# Write progress iteration step "loading" text +# + +function _o_progress_write_step_text { + local cont="${1:-false}" + local frmt=" %s %' 7s %s " + local text="loading" + + _o_progress_tracked_write_nl + _o_progress_tracked_write_text \ + "${frmt}" \ + "$(_o_fg_dark_gray; _o_bg_black; _o_style_invert; _o_style_bold; _o_style_dim)" \ + "${text:u}" \ + "$(_o_ansi_clear)" + _o_progress_write_step_char_init + _o_progress_write_step_char + _o_progress_write_step_char + _o_progress_write_step_char +} + + +# +# Write progress loading information +# + +function _o_progress_write { + _o_progress_cfg_state_setup + + if [[ ${_DZ_LOADER_DISABLE} -eq 1 ]]; then + return + fi + + _o_progress_cfg_state_clear + + if [[ ${_DZ_LOADER_STARTED} -eq 1 ]]; then + _o_progress_write_step_char + else + _o_progress_write_step_text + _o_progress_cfg_state_start + fi +} diff --git a/include.d-core/env-define-variables-bootstrap.zsh b/include.d-core/env-define-variables-bootstrap.zsh index 399918b..6b40d5d 100644 --- a/include.d-core/env-define-variables-bootstrap.zsh +++ b/include.d-core/env-define-variables-bootstrap.zsh @@ -21,8 +21,8 @@ _DZ_LOAD_TIME=$(_get_microtime) # Define full-name, base-name, and path. # -_DZ_NAME="${(%):-%x}" -_DZ_BASE="$(basename ${_DZ_NAME})" +_DZ_NAME="$(dirname "${_DZ_NAME}")" +_DZ_BASE="$(sed -E 's/^[^a-z]//g' <<< "$(basename "${_DZ_NAME}")")" # diff --git a/include.d-core/env-define-variables-internal.zsh b/include.d-core/env-define-variables-internal.zsh index 4b9abbb..2e57204 100644 --- a/include.d-core/env-define-variables-internal.zsh +++ b/include.d-core/env-define-variables-internal.zsh @@ -89,7 +89,6 @@ _DZ_UNSET_VS+=("_DZ_IO_BUFF_DEFINITION_PREFIX") _DZ_UNSET_VS+=("_DZ_IO_BUFF_DEFINITION_VALUES") _DZ_UNSET_VS+=("_DZ_IO_BUFF_LINES") _DZ_UNSET_VS+=("_DZ_IO_BUFF_NORM") -_DZ_UNSET_VS+=("_DZ_IO_BUFF_WARN") _DZ_UNSET_VS+=("_DZ_IO_VERBOSITY") _DZ_UNSET_VS+=("_DZ_LOAD_PATH") _DZ_UNSET_VS+=("_DZ_LOAD_TIME") @@ -128,30 +127,30 @@ _DZ_UNSET_FS+=("_buf_definition_list") _DZ_UNSET_FS+=("_add_env_path_dir") _DZ_UNSET_FS+=("_aliases_build_ssh_command") _DZ_UNSET_FS+=("_aliases_setup_ssh_connections") -_DZ_UNSET_FS+=("_ansi_clear") +_DZ_UNSET_FS+=("_o_ansi_clear") _DZ_UNSET_FS+=("_ansi_color") -_DZ_UNSET_FS+=("_ansi_rm_sgr_el") -_DZ_UNSET_FS+=("_bg_black") -_DZ_UNSET_FS+=("_bg_blue") -_DZ_UNSET_FS+=("_bg_cyan") -_DZ_UNSET_FS+=("_bg_dark_gray") -_DZ_UNSET_FS+=("_bg_default") -_DZ_UNSET_FS+=("_bg_green") -_DZ_UNSET_FS+=("_bg_light_blue") -_DZ_UNSET_FS+=("_bg_light_cyan") -_DZ_UNSET_FS+=("_bg_light_gray") -_DZ_UNSET_FS+=("_bg_light_green") -_DZ_UNSET_FS+=("_bg_light_magenta") -_DZ_UNSET_FS+=("_bg_light_red") -_DZ_UNSET_FS+=("_bg_light_yellow") -_DZ_UNSET_FS+=("_bg_magenta") -_DZ_UNSET_FS+=("_bg_red") -_DZ_UNSET_FS+=("_bg_white") -_DZ_UNSET_FS+=("_bg_yellow") +_DZ_UNSET_FS+=("_o_ansi_al_sequence_remove") +_DZ_UNSET_FS+=("_o_bg_black") +_DZ_UNSET_FS+=("_o_bg_blue") +_DZ_UNSET_FS+=("_o_bg_cyan") +_DZ_UNSET_FS+=("_o_bg_dark_gray") +_DZ_UNSET_FS+=("_o_bg_default") +_DZ_UNSET_FS+=("_o_bg_green") +_DZ_UNSET_FS+=("_o_bg_light_blue") +_DZ_UNSET_FS+=("_o_bg_light_cyan") +_DZ_UNSET_FS+=("_o_bg_light_gray") +_DZ_UNSET_FS+=("_o_bg_light_green") +_DZ_UNSET_FS+=("_o_bg_light_magenta") +_DZ_UNSET_FS+=("_o_bg_light_red") +_DZ_UNSET_FS+=("_o_bg_light_yellow") +_DZ_UNSET_FS+=("_o_bg_magenta") +_DZ_UNSET_FS+=("_o_bg_red") +_DZ_UNSET_FS+=("_o_bg_white") +_DZ_UNSET_FS+=("_o_bg_yellow") _DZ_UNSET_FS+=("_check_extern_source_file") _DZ_UNSET_FS+=("_check_extern_source_file_enabled") _DZ_UNSET_FS+=("_get_definition_list_line") -_DZ_UNSET_FS+=("_config_read_array_assoc") +_DZ_UNSET_FS+=("_cfg_get_array_assoc") _DZ_UNSET_FS+=("_cfg_get_array_values") _DZ_UNSET_FS+=("_cfg_req_array_values") _DZ_UNSET_FS+=("_cfg_get_bool") @@ -165,23 +164,23 @@ _DZ_UNSET_FS+=("_cfg_req_string") _DZ_UNSET_FS+=("_cfg_resolve_array") _DZ_UNSET_FS+=("_cfg_resolve_string") _DZ_UNSET_FS+=("_cfg_ret_bool") -_DZ_UNSET_FS+=("_fg_black") -_DZ_UNSET_FS+=("_fg_blue") -_DZ_UNSET_FS+=("_fg_cyan") -_DZ_UNSET_FS+=("_fg_dark_gray") -_DZ_UNSET_FS+=("_fg_default") -_DZ_UNSET_FS+=("_fg_green") -_DZ_UNSET_FS+=("_fg_light_blue") -_DZ_UNSET_FS+=("_fg_light_cyan") -_DZ_UNSET_FS+=("_fg_light_gray") -_DZ_UNSET_FS+=("_fg_light_green") -_DZ_UNSET_FS+=("_fg_light_magenta") -_DZ_UNSET_FS+=("_fg_light_red") -_DZ_UNSET_FS+=("_fg_light_yellow") -_DZ_UNSET_FS+=("_fg_magenta") -_DZ_UNSET_FS+=("_fg_red") -_DZ_UNSET_FS+=("_fg_white") -_DZ_UNSET_FS+=("_fg_yellow") +_DZ_UNSET_FS+=("_o_fg_black") +_DZ_UNSET_FS+=("_o_fg_blue") +_DZ_UNSET_FS+=("_o_fg_cyan") +_DZ_UNSET_FS+=("_o_fg_dark_gray") +_DZ_UNSET_FS+=("_o_fg_default") +_DZ_UNSET_FS+=("_o_fg_green") +_DZ_UNSET_FS+=("_o_fg_light_blue") +_DZ_UNSET_FS+=("_o_fg_light_cyan") +_DZ_UNSET_FS+=("_o_fg_light_gray") +_DZ_UNSET_FS+=("_o_fg_light_green") +_DZ_UNSET_FS+=("_o_fg_light_magenta") +_DZ_UNSET_FS+=("_o_fg_light_red") +_DZ_UNSET_FS+=("_o_fg_light_yellow") +_DZ_UNSET_FS+=("_o_fg_magenta") +_DZ_UNSET_FS+=("_o_fg_red") +_DZ_UNSET_FS+=("_o_fg_white") +_DZ_UNSET_FS+=("_o_fg_yellow") _DZ_UNSET_FS+=("_flatten_lines") _DZ_UNSET_FS+=("_get_array_key") _DZ_UNSET_FS+=("_get_array_val") @@ -192,13 +191,12 @@ _DZ_UNSET_FS+=("_log_definition_list") _DZ_UNSET_FS+=("_log_action") _DZ_UNSET_FS+=("_buf_flush_lines") _DZ_UNSET_FS+=("_log_crit") -_DZ_UNSET_FS+=("_log_normal") +_DZ_UNSET_FS+=("_log_norm") _DZ_UNSET_FS+=("_log_source") _DZ_UNSET_FS+=("_log_src_done") _DZ_UNSET_FS+=("_log_src_fail") _DZ_UNSET_FS+=("_log_src_skip") _DZ_UNSET_FS+=("_log_warn") -_DZ_UNSET_FS+=("_log_warn_old") _DZ_UNSET_FS+=("_parse_shell_path") _DZ_UNSET_FS+=("_parse_zsh_path") _DZ_UNSET_FS+=("_parse_zsh_version") @@ -221,12 +219,12 @@ _DZ_UNSET_FS+=("_self_repo_repo") _DZ_UNSET_FS+=("_self_repo_tag") _DZ_UNSET_FS+=("_self_repo_vers") _DZ_UNSET_FS+=("_self_repo_whos") -_DZ_UNSET_FS+=("_style_blink") -_DZ_UNSET_FS+=("_style_bold") -_DZ_UNSET_FS+=("_style_dim") -_DZ_UNSET_FS+=("_style_hide") -_DZ_UNSET_FS+=("_style_invert") -_DZ_UNSET_FS+=("_style_strikeout") -_DZ_UNSET_FS+=("_style_underline") +_DZ_UNSET_FS+=("_o_style_blink") +_DZ_UNSET_FS+=("_o_style_bold") +_DZ_UNSET_FS+=("_o_style_dim") +_DZ_UNSET_FS+=("_o_style_hide") +_DZ_UNSET_FS+=("_o_style_invert") +_DZ_UNSET_FS+=("_o_style_strikeout") +_DZ_UNSET_FS+=("_o_style_underline") _DZ_UNSET_FS+=("_trim_line_width") _DZ_UNSET_FS+=("_wrt_log") diff --git a/include.d-libs/fonts b/include.d-libs/fonts index a44abd0..03d8843 160000 --- a/include.d-libs/fonts +++ b/include.d-libs/fonts @@ -1 +1 @@ -Subproject commit a44abd0e742ad6e7fd8d8bc4c3cad5155c9f3a92 +Subproject commit 03d8843f66181a40d7f737d91f98d8b2ba29c887 diff --git a/include.d-libs/oh-my-zsh b/include.d-libs/oh-my-zsh new file mode 160000 index 0000000..c494869 --- /dev/null +++ b/include.d-libs/oh-my-zsh @@ -0,0 +1 @@ +Subproject commit c4948696328eab3b954932eb940ec8ec97b12906 diff --git a/include.d-load/A b/include.d-libs/oh-my-zsh-plugins/.gitkeep similarity index 100% rename from include.d-load/A rename to include.d-libs/oh-my-zsh-plugins/.gitkeep diff --git a/include.d-libs/oh-my-zsh-plugins/auto-suggestions b/include.d-libs/oh-my-zsh-plugins/auto-suggestions new file mode 160000 index 0000000..70f36c0 --- /dev/null +++ b/include.d-libs/oh-my-zsh-plugins/auto-suggestions @@ -0,0 +1 @@ +Subproject commit 70f36c007db30a5fe1edf2b63664088b502a729c diff --git a/include.d-libs/oh-my-zsh-plugins/history-substring-search b/include.d-libs/oh-my-zsh-plugins/history-substring-search new file mode 160000 index 0000000..47a7d41 --- /dev/null +++ b/include.d-libs/oh-my-zsh-plugins/history-substring-search @@ -0,0 +1 @@ +Subproject commit 47a7d416c652a109f6e8856081abc042b50125f4 diff --git a/include.d-libs/oh-my-zsh-plugins/syntax-highlighting b/include.d-libs/oh-my-zsh-plugins/syntax-highlighting new file mode 160000 index 0000000..d61ebbc --- /dev/null +++ b/include.d-libs/oh-my-zsh-plugins/syntax-highlighting @@ -0,0 +1 @@ +Subproject commit d61ebbcbbf7da8fc35040f591e37b89272623036 diff --git a/include.d-libs/oh-my-zsh-plugins/wakatime b/include.d-libs/oh-my-zsh-plugins/wakatime new file mode 160000 index 0000000..fc24455 --- /dev/null +++ b/include.d-libs/oh-my-zsh-plugins/wakatime @@ -0,0 +1 @@ +Subproject commit fc244551f8c2d0c1dcfab6410d31aac8d2026c41 diff --git a/include.d-libs/oh-my-zsh-themes/.gitkeep b/include.d-libs/oh-my-zsh-themes/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/include.d-load/00-000-env-configs-setups.zsh b/include.d-load/00-000-env-configs-setups.zsh new file mode 100644 index 0000000..77b54e7 --- /dev/null +++ b/include.d-load/00-000-env-configs-setups.zsh @@ -0,0 +1,27 @@ +#!/usr/bin/env zsh + +# +# This file is part of the `src-run/dot-zsh` project. +# +# (c) Rob Frawley 2nd +# +# For the full copyright and license information, view the LICENSE.md +# file distributed with this source code. +# + + +# +# Assign internal variables +# + +_ifs_newlines +for a in $(_cfg_get_array_assoc 'configs.setups.internal_variables'); do + k="$(_get_array_key "${a}")" + v="$(_get_array_val "${a}")" + + export ${k}="${v}" \ + && _log_action "Intern assign '${k}' => '${v}' (success)" \ + || _log_action "Intern assign '${k}' => '${v}' (failure)" + +done +_ifs_reset diff --git a/include.d-load/00-000-inc-systems-oh-my-zsh.zsh b/include.d-load/01-000-inc-systems-oh-my-zsh.zsh similarity index 81% rename from include.d-load/00-000-inc-systems-oh-my-zsh.zsh rename to include.d-load/01-000-inc-systems-oh-my-zsh.zsh index 9994836..7324b85 100644 --- a/include.d-load/00-000-inc-systems-oh-my-zsh.zsh +++ b/include.d-load/01-000-inc-systems-oh-my-zsh.zsh @@ -22,15 +22,25 @@ _log_action "Loading configured plugins" # Configure theme to use (See ".oh-my-zsh/themes/" for available themes or use # the name "random" to have a random theme each time the shell is loaded). # -ZSH_THEME="$(_log_assignment ZSH_THEME "$( - _cfg_get_string 'systems.oh_my_zsh.display.prompt_theme' -)")" + +case "${TERM}" in + xterm-color|xterm-256color|screen-color|screen-256color ) + ZSH_THEME="$(_log_assignment ZSH_THEME "$( + _cfg_get_string 'systems.oh_my_zsh.display.prompt_theme' 'agnoster' + )")" + ;; + *) + ZSH_THEME="$(_log_assignment ZSH_THEME "af-magic")" + ;; +esac + # # Configure colors for "ls" command. # + DISABLE_LS_COLORS="$(_log_assignment DISABLE_LS_COLORS "$( - _bool_reverse $( + _cast_bool_to_inverse_string $( _cfg_get_bool 'systems.oh_my_zsh.display.use_ls_color' ) )")" @@ -39,8 +49,9 @@ DISABLE_LS_COLORS="$(_log_assignment DISABLE_LS_COLORS "$( # # Configure auto-setting of the terminal title. # + DISABLE_AUTO_TITLE="$(_log_assignment DISABLE_AUTO_TITLE "$( - _bool_reverse $( + _cast_bool_to_inverse_string $( _cfg_get_bool 'systems.oh_my_zsh.display.window_title_assign' ) )")" @@ -50,14 +61,16 @@ DISABLE_AUTO_TITLE="$(_log_assignment DISABLE_AUTO_TITLE "$( # Configure the command execution time stamp shown in the history command. # Formats include: "mm/dd/yyyy" or "dd.mm.yyyy" or "yyyy-mm-dd". # + HIST_STAMPS="$(_log_assignment HIST_STAMPS "$( - _cfg_get_string 'systems.oh_my_zsh.display.history_date_format' + _cfg_get_string 'systems.oh_my_zsh.display.history_date_format' 'yyyy-mm-dd' )")" # # Use case-sensitive completion. # + CASE_SENSITIVE="$(_log_assignment CASE_SENSITIVE "$( _cfg_get_bool 'systems.oh_my_zsh.completions.use_case_sensitivity' )")" @@ -67,8 +80,9 @@ CASE_SENSITIVE="$(_log_assignment CASE_SENSITIVE "$( # Use hyphen-insensitive completion. Case-sensitive completion must be off # and _ and - will be interchangeable. # + HYPHEN_INSENSITIVE="$(_log_assignment HYPHEN_INSENSITIVE "$( - _bool_reverse $( + _cast_bool_to_string $( _cfg_get_bool 'systems.oh_my_zsh.completions.use_hyph_sensitivity' ) )")" @@ -77,6 +91,7 @@ HYPHEN_INSENSITIVE="$(_log_assignment HYPHEN_INSENSITIVE "$( # # Configure command auto-correction. # + ENABLE_CORRECTION="$(_log_assignment ENABLE_CORRECTION "$( _cfg_get_bool 'systems.oh_my_zsh.completions.cmd_show_corrections' )")" @@ -85,13 +100,16 @@ ENABLE_CORRECTION="$(_log_assignment ENABLE_CORRECTION "$( # # Configure display of red dots while waiting for completion. # + COMPLETION_WAITING_DOTS="$(_log_assignment COMPLETION_WAITING_DOTS "$( _cfg_get_bool 'systems.oh_my_zsh.completions.display_working_dots' )")" + # # Ignore permissions issues when completion files are loaded # + ZSH_DISABLE_COMPFIX="$(_log_assignment ZSH_DISABLE_COMPFIX "$( _cfg_get_bool 'systems.oh_my_zsh.completions.no_permisions_checks' )")" @@ -100,8 +118,9 @@ ZSH_DISABLE_COMPFIX="$(_log_assignment ZSH_DISABLE_COMPFIX "$( # # Configure bi-weekly auto-update checks. # + DISABLE_AUTO_UPDATE="$(_log_assignment DISABLE_AUTO_UPDATE "$( - _bool_reverse $( + _cast_bool_to_inverse_string $( _cfg_get_bool 'systems.oh_my_zsh.updates.auto_check' ) )")" @@ -110,8 +129,18 @@ DISABLE_AUTO_UPDATE="$(_log_assignment DISABLE_AUTO_UPDATE "$( # # Set how often to auto-update (in days). # + export UPDATE_ZSH_DAYS="$(_log_assignment UPDATE_ZSH_DAYS "$( - _cfg_get_number 'systems.oh_my_zsh.updates.every_days' + _cfg_get_number 'systems.oh_my_zsh.updates.every_days' 7 +)")" + + +# +# Set default user. +# + +export DEFAULT_USER="$(_log_assignment DEFAULT_USER "$( + _cfg_get_string 'systems.oh_my_zsh.def_user' "${USER}" )")" @@ -122,7 +151,7 @@ export UPDATE_ZSH_DAYS="$(_log_assignment UPDATE_ZSH_DAYS "$( # DISABLE_UNTRACKED_FILES_DIRTY="$(_log_assignment DISABLE_UNTRACKED_FILES_DIRTY "$( - _bool_reverse $( + _cast_bool_to_inverse_string $( _cfg_get_bool 'systems.oh_my_zsh.git.use_untracked_in_dirty_check' ) )")" @@ -142,27 +171,21 @@ ZSH_LANG_TYPE="$(_log_assignment ZSH_LANG_TYPE "$( # -# flush buffered assignment log lines -# - -_file_out_buffer - - -# -# setup plugins +# setup plug-ins # plugins=() -for p in $(_cfg_get_array_values 'systems.oh_my_zsh.plugins'); do +for p in $(_cfg_get_array_keys 'systems.oh_my_zsh.plugins'); do plugins+=(${p}) \ - && _log_action "Setting plugin '${p}' as active" 3 + && _log_action "Activated plug-in: '${p}'" 3 done # # attempt to resolve oh-my-zsh real paths # + if [[ $(which realpath 2> /dev/null) ]]; then _OH_ROOT_PATH="$(realpath "${_OH_ROOT_PATH}" 2> /dev/null)" _OH_LOAD_PATH="$(realpath "${_OH_LOAD_PATH}" 2> /dev/null)" @@ -172,6 +195,7 @@ fi # # export and source oh-my-zsh or display error message # + if [[ -d "${_OH_ROOT_PATH}" ]] && [[ -f "${_OH_LOAD_PATH}" ]]; then export ZSH="${_OH_ROOT_PATH}" source "${_OH_LOAD_PATH}" \ diff --git a/include.d-load/10-000-env-configs-aliases.zsh b/include.d-load/10-000-env-configs-aliases.zsh index adfb0d7..193f544 100644 --- a/include.d-load/10-000-env-configs-aliases.zsh +++ b/include.d-load/10-000-env-configs-aliases.zsh @@ -10,6 +10,13 @@ # +# +# Log ssh connection alias assignment section +# + +_log_action "Setting up configured aliases (ssh connections)..." + + # # Assign ssh aliases # @@ -17,15 +24,36 @@ _aliases_setup_ssh_connections +# +# Log basic command alias assignment section +# + +_log_action "Setting up configured aliases (basic commands)..." + + # # Assign simple aliases # + +# set ifs variable to newlines _ifs_newlines -for a in $(_config_read_array_assoc 'configs.aliases.set_simple_cmds'); do + +# loop over configured simple command aliases +for a in $(_cfg_get_array_assoc 'configs.aliases.set_simple_commands'); do k="$(_get_array_key "${a}")" v="$(_get_array_val "${a}")" - alias ${k}="${v}" && - _log_action "Alias defined '${k}' => '${v}'" + + if _cfg_ret_bool 'configs.aliases.new_simple_commands' 'true' && alias | grep -E "^${k}=" &> /dev/null; then + unalias "${k}" 2> /dev/null \ + && _log_action "Removed prior alias: '${k}'" 3 \ + || _log_action "Failed alias remove: '${k}'" 3 + fi + + alias "${k}"="${v}" 2> /dev/null \ + && _log_action "Defined alias value: '${k}' => '${v}'" 3 \ + || _log_action "Failed alias assign: '${k}' => '${v}'" 3 done + +# reset ifs variable to prior value _ifs_reset diff --git a/include.d-load/50-000-env-configs-zsh.zsh b/include.d-load/50-000-env-configs-zsh.zsh new file mode 100644 index 0000000..a7a99ae --- /dev/null +++ b/include.d-load/50-000-env-configs-zsh.zsh @@ -0,0 +1,25 @@ +#!/usr/bin/env zsh + +# +# This file is part of the `src-run/dot-zsh` project. +# +# (c) Rob Frawley 2nd +# +# For the full copyright and license information, view the LICENSE.md +# file distributed with this source code. +# + + +# +# Loop though exports array and export 'em. +# + +for dir in $(_cfg_get_array_values 'configs.change_directory_paths.paths'); do + if [[ ! -d "${dir}" ]]; then + continue + fi + + cdpath+=( "${dir}" ) && \ + _log_action "Registering '${dir}' in 'cdpath' environment variable" || + _log_warn "Failed to add '${dir}' to 'cdpath' environment variable" +done diff --git a/include.d-load/60-000-env-configs-exports.zsh b/include.d-load/60-000-env-configs-exports.zsh new file mode 100644 index 0000000..a4746e2 --- /dev/null +++ b/include.d-load/60-000-env-configs-exports.zsh @@ -0,0 +1,30 @@ +#!/usr/bin/env zsh + +# +# This file is part of the `src-run/dot-zsh` project. +# +# (c) Rob Frawley 2nd +# +# For the full copyright and license information, view the LICENSE.md +# file distributed with this source code. +# + + +# +# Loop though exports array and export 'em. +# + +for raw in $(_cfg_get_array_assoc 'configs.exports.first'); do + key="$(_get_array_key "${raw}")" + val="$(_get_array_val "${raw}")" + + if [[ ${val} == null ]]; then + export "${key}" && + _log_action "Exporting '${key}' variable" || + _log_warn "Failed to export '${key}' variable" + else + export "${key}"="${val}" && + _log_action "Exporting '${key}' variable with '${val}' assignment" || + _log_warn "Failed to export '${e}' variable with '${val}' assignment" + fi +done diff --git a/include.d-load/70-000-inc-plugins-nvm.zsh b/include.d-load/70-000-inc-plugins-nvm.zsh new file mode 100644 index 0000000..902c6f9 --- /dev/null +++ b/include.d-load/70-000-inc-plugins-nvm.zsh @@ -0,0 +1,150 @@ +#!/usr/bin/env zsh + +# +# This file is part of the `src-run/dot-zsh` project. +# +# (c) Rob Frawley 2nd +# +# For the full copyright and license information, view the LICENSE.md +# file distributed with this source code. +# + + +# +# Log nvm environment setup actions +# + +_log_action "Assigning nvm variables" + + +# +# Assign nvm dir variable +# + +if [[ -z "${NVM_DIR}" ]]; then + NVM_DIR="$(_log_assignment NVM_DIR "$( + _cfg_get_string 'plugins.nvm.mortal_root_path' + )")" +fi + + +# +# Unset nvm dir variable if path does not exist or is not readable +# + +if [[ ! -d "${NVM_DIR}" ]] || [[ ! -r "${NVM_DIR}" ]]; then + unset NVM_DIR 2> /dev/null \ + && _log_action "Unset variable 'NVM_DIR' with value '${NVM_DIR}' (invalid path)" 3 +fi + + +# +# Log installation of required nvm versions +# + +_log_action "Requiring nvm releases" + + +# +# Require nvm versions +# + +for k in $(_cfg_get_array_keys 'plugins.nvm.define_v_install'); do + _NVM_VER="$( + _cfg_get_string "plugins.nvm.define_v_install[${k}].install_vers_nvm" 'undefined' + )" + + _NVM_OPT=($(sed -E 's/[ ]+/ /g' 2> /dev/null <<< "$( + _cfg_get_string "plugins.nvm.define_v_install[${k}].install_opts_use" '' + )")) + + _cfg_ret_bool "plugins.nvm.define_v_install[${k}].install_opts_add" 'false' \ + && _NVM_OPT+=('--lts') + + if [[ -z "${_NVM_VER}" ]] || [[ 'undefined' == "${_NVM_VER}" ]]; then + _log_action "Version string for nvm config entry ${k} invalid..." 3 \ + && continue + fi + + if ! which nvm &> /dev/null; then + _log_action "Unable to locate nvm binary..." 3 \ + && continue + fi + + if ! nvm ls-remote "${_NVM_VER}" ${_NVM_OPT[@]} &> /dev/null; then + _log_action "Remote could not locate nvm version: '${_NVM_VER}'" 3 \ + && continue + fi + + if _cfg_ret_bool "plugins.nvm.define_v_install[${k}].removes_existing" 'false'; then + nvm uninstall "${_NVM_VER}" &> /dev/null \ + && _log_action "Removed prior nvm version: '${_NVM_VER}'" 3 \ + || _log_action "Failed prior nvm removal: '${_NVM_VER}'" 3 + fi + + if nvm ls ${_NVM_VER} &>/dev/null; then + _log_action "Found prior nvm installation: '${_NVM_VER}'" 3 \ + && continue + fi + + _cfg_ret_bool "plugins.nvm.define_v_install[${k}].install_with_npm" 'false' \ + && _NVM_OPT+=('--latest-npm') + + nvm install "${_NVM_VER}" ${_NVM_OPT[@]} &> /dev/null \ + && _log_action "Installing nvm version: '${_NVM_VER}'" 3 \ + || _log_action "Failed nvm installation: '${_NVM_VER}'" 3 +done + + +# +# Log assignment of nvm aliases +# + +_log_action "Assigning nvm aliases for nvm versions" + + +# +# Assign nvm version aliases +# + +_ifs_newlines +for a in $(_cfg_get_array_assoc 'plugins.nvm.define_v_aliases'); do + k="$(_get_array_key "${a}")" + v="$(_get_array_val "${a}")" + + if nvm alias "${k}" &> /dev/null; then + if _cfg_ret_bool 'plugins.nvm.remove_v_aliases'; then + nvm unalias "${k}" &> /dev/null + else + _log_action "Found existing nvm alias: '${k}' => '${v}'" 3 \ + && continue + fi + fi + + nvm alias "${k}" "${v}" &> /dev/null \ + && _log_action "Defined nvm alias: '${k}' => '${v}'" 3 \ + || _log_action "Failure defininf nvm alias: '${k}' => '${v}'" 3 +done +_ifs_reset + + +# +# Source nvm shell completion scripts +# + +for f in $(_cfg_get_array_values 'plugins.nvm.completion_files'); do + if [[ ! -f "${f}" ]] || [[ ! -r "${f}" ]]; then + _log_norm 2 \ + " --- Skipping '${f}' completion file (does not exist)" + return + fi + + if [[ ! -r "${f}" ]]; then + _log_norm 2 \ + " --- Skipping '${f}' completion file (is not readable)" + return + fi + + source "${f}" 2> /dev/null && \ + _log_source 2 2 "Sourcing completions file '${f}'" +done diff --git a/include.d-load/80-000-inc-plugins-npm.zsh b/include.d-load/70-001-inc-plugins-npm.zsh similarity index 98% rename from include.d-load/80-000-inc-plugins-npm.zsh rename to include.d-load/70-001-inc-plugins-npm.zsh index d7b0fd9..3576a71 100644 --- a/include.d-load/80-000-inc-plugins-npm.zsh +++ b/include.d-load/70-001-inc-plugins-npm.zsh @@ -61,6 +61,6 @@ if [[ -d "${_DZ_NPM_MANPAGES_PATH}" ]]; then unset _DZ_MAN_PATH_DEFAULTS unset _DZ_MAN_PATH_TO_APPLY else - _log_normal 1 \ + _log_norm 1 \ " --- Skipped registering '${_DZ_NPM_MANPAGES_PATH}' to 'MANPATH' (does not exist)" fi diff --git a/include.d-load/80-000-inc-plugins-apt-fast.zsh b/include.d-load/80-000-inc-plugins-apt-fast.zsh index 98a534d..71760dd 100644 --- a/include.d-load/80-000-inc-plugins-apt-fast.zsh +++ b/include.d-load/80-000-inc-plugins-apt-fast.zsh @@ -11,18 +11,18 @@ # -# Source apt-fast shell completion script +# Source apt-fast shell completion scripts # for f in $(_cfg_get_array_values 'plugins.apt_fast.completion_files'); do if [[ ! -f "${f}" ]] || [[ ! -r "${f}" ]]; then - _log_normal 2 \ + _log_norm 2 \ " --- Skipping '${f}' completion file (does not exist)" return fi if [[ ! -r "${f}" ]]; then - _log_normal 2 \ + _log_norm 2 \ " --- Skipping '${f}' completion file (is not readable)" return fi diff --git a/include.d-load/80-000-inc-plugins-chruby.zsh b/include.d-load/80-000-inc-plugins-chruby.zsh index 358e20e..0eafd7f 100644 --- a/include.d-load/80-000-inc-plugins-chruby.zsh +++ b/include.d-load/80-000-inc-plugins-chruby.zsh @@ -22,6 +22,7 @@ done # # Set ruby default interpreter # + v=$(_cfg_get_string 'plugins.chruby.auto_set_version' 'false') if [[ "${v}" != 'false' ]]; then diff --git a/include.d-load/80-000-inc-plugins-docker.zsh b/include.d-load/80-000-inc-plugins-docker.zsh index 481a1da..9728f42 100644 --- a/include.d-load/80-000-inc-plugins-docker.zsh +++ b/include.d-load/80-000-inc-plugins-docker.zsh @@ -22,6 +22,6 @@ if [[ $? -eq 0 ]]; then _log_action "Docker machine environment '${v}' setup" || \ _log_warn "Failed to setup docker machine '${v}' environment" else - _log_normal 1 \ + _log_norm 1 \ " --- Skipping docker machine configuration (missing 'docker-machine' cmd)" fi diff --git a/include.d-load/80-000-inc-plugins-gnupg.zsh b/include.d-load/80-000-inc-plugins-gnupg.zsh index 417976b..74b7bf5 100644 --- a/include.d-load/80-000-inc-plugins-gnupg.zsh +++ b/include.d-load/80-000-inc-plugins-gnupg.zsh @@ -21,7 +21,7 @@ if [[ ! -z "${v}" ]]; then _log_action "Assigned gpg key to '${v}'" || \ _log_warn "Failed to assign gpg key to '${v}'" else - _log_normal 1 \ + _log_norm 1 \ " --- Skipping gpg key assignment (missing configuration)" fi @@ -32,6 +32,6 @@ if [[ ! -z "${v}" ]]; then _log_action "Assigned gpg tty to '${v}'" || \ _log_warn "Failed to assign gpg tty to '${v}'" else - _log_normal 1 \ + _log_norm 1 \ " --- Skipping gpg tty assignment (missing configuration)" fi diff --git a/include.d-load/80-000-inc-plugins-golang.zsh b/include.d-load/80-000-inc-plugins-golang.zsh index b62d1f5..58e4a4c 100644 --- a/include.d-load/80-000-inc-plugins-golang.zsh +++ b/include.d-load/80-000-inc-plugins-golang.zsh @@ -21,7 +21,7 @@ if [[ -d "${v}" ]]; then _log_action "Assigning 'GOPATH' to '${v}'" || \ _log_warn "Failed assigning 'GOPATH' to '${v}'" else - _log_normal 1 \ + _log_norm 1 \ " --- Skipping 'GOPATH' assignment '${v}' (does not exist)" fi @@ -32,7 +32,7 @@ if [[ -d "${v}" ]]; then _log_action "Assigning 'GOROOT' to '${v}'" || \ _log_warn "Failed assigning 'GOROOT' to '${v}'" else - _log_normal 1 \ + _log_norm 1 \ " --- Skipping 'GOROOT' assignment '${v}' (does not exist)" fi diff --git a/include.d-load/80-000-inc-plugins-google-cloud-sdk.zsh b/include.d-load/80-000-inc-plugins-google-cloud-sdk.zsh index 20d1d4e..7f040da 100644 --- a/include.d-load/80-000-inc-plugins-google-cloud-sdk.zsh +++ b/include.d-load/80-000-inc-plugins-google-cloud-sdk.zsh @@ -11,13 +11,18 @@ # -# Source Google Cloud SDK path helper and completion scripts +# Source Google Cloud SDK path helpers # for f in $(_cfg_get_array_values 'plugins.google_cloud_sdk.env_source_files'); do _check_extern_source_file "${f}" 2 'google-cloud-sdk' && source "${f}" done + +# +# Source Google Cloud SDK completion scripts +# + for f in $(_cfg_get_array_values 'plugins.google_cloud_sdk.completion_files'); do _check_extern_source_file "${f}" 2 'google-cloud-sdk' && source "${f}" done diff --git a/include.d-load/80-000-inc-plugins-phpenv.zsh b/include.d-load/80-000-inc-plugins-phpenv.zsh index 825752e..07b5570 100644 --- a/include.d-load/80-000-inc-plugins-phpenv.zsh +++ b/include.d-load/80-000-inc-plugins-phpenv.zsh @@ -11,21 +11,33 @@ # -# Include phpenv shell helpers. +# Add phpenv executable directories to PATH # for f in $(_cfg_get_array_values 'plugins.phpenv.executable_paths'); do _add_env_path_dir "${f}" scripted done + +# +# Add phpenv completion files to environment +# + for f in $(_cfg_get_array_values 'plugins.phpenv.completion_files'); do _check_extern_source_file "${f}" 2 'phpenv' && source "${f}" done + +# +# Initialize phpenv +# + _ifs_newlines -for e in $(_cfg_get_array_values 'plugins.phpenv.initialize_evals'); do - eval "$(eval ${e})" && \ - _log_action "Evaluated initialization command '${e}'" || \ - _log_warn "Failed evaluated initialization command '${e}'" +for eval in $(_cfg_get_array_values 'plugins.phpenv.initialize_evals'); do + _log_action "Evaluating initialization script: '${eval}'" + eval "$(eval "${eval}")" + + [[ $? -ne 0 ]] && \ + _log_warn "Failed evaluation of initialization script: '${eval}'" done _ifs_reset diff --git a/include.d-load/80-000-inc-plugins-python-pip.zsh b/include.d-load/80-000-inc-plugins-python-pip.zsh new file mode 100644 index 0000000..698f06f --- /dev/null +++ b/include.d-load/80-000-inc-plugins-python-pip.zsh @@ -0,0 +1,25 @@ +#!/usr/bin/env zsh + +# +# This file is part of the `src-run/dot-zsh` project. +# +# (c) Rob Frawley 2nd +# +# For the full copyright and license information, view the LICENSE.md +# file distributed with this source code. +# + + +# +# Setup python pip completion +# + +_ifs_newlines +for eval in $(_cfg_get_array_values 'plugins.python_pip.initialize_evals'); do + _log_action "Evaluating initialization script: '${eval}'" + eval "$(eval "${eval}")" + + [[ $? -ne 0 ]] && \ + _log_warn "Failed evaluation of initialization script: '${eval}'" +done +_ifs_reset diff --git a/include.d-load/99-000-env-configs-exports.zsh b/include.d-load/99-000-env-configs-exports.zsh index 7cfe138..6bd8829 100644 --- a/include.d-load/99-000-env-configs-exports.zsh +++ b/include.d-load/99-000-env-configs-exports.zsh @@ -14,8 +14,17 @@ # Loop though exports array and export 'em. # -for e in $(_cfg_get_array_values 'configs.exports.variables'); do - export "${e}" && - _log_action "Exporting '${e}' variable" || - _log_warn "Failed to export '${e}' variable" +for raw in $(_cfg_get_array_assoc 'configs.exports.final'); do + key="$(_get_array_key "${raw}")" + val="$(_get_array_val "${raw}")" + + if [[ ${val} == null ]]; then + export "${key}" && + _log_action "Exporting '${key}' variable" || + _log_warn "Failed to export '${key}' variable" + else + export "${key}"="${val}" && + _log_action "Exporting '${key}' variable with '${val}' assignment" || + _log_warn "Failed to export '${e}' variable with '${val}' assignment" + fi done diff --git a/include.d-omzc/plugins/.gitkeep b/include.d-omzc/plugins/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/include.d-omzc/plugins/wakatime b/include.d-omzc/plugins/wakatime new file mode 120000 index 0000000..28af890 --- /dev/null +++ b/include.d-omzc/plugins/wakatime @@ -0,0 +1 @@ +../../include.d-libs/oh-my-zsh-plugins/wakatime \ No newline at end of file diff --git a/include.d-omzc/plugins/zsh-autosuggestions b/include.d-omzc/plugins/zsh-autosuggestions new file mode 120000 index 0000000..99d3101 --- /dev/null +++ b/include.d-omzc/plugins/zsh-autosuggestions @@ -0,0 +1 @@ +../../include.d-libs/oh-my-zsh-plugins/auto-suggestions \ No newline at end of file diff --git a/include.d-omzc/plugins/zsh-history-substring-search b/include.d-omzc/plugins/zsh-history-substring-search new file mode 120000 index 0000000..84196e2 --- /dev/null +++ b/include.d-omzc/plugins/zsh-history-substring-search @@ -0,0 +1 @@ +../../include.d-libs/oh-my-zsh-plugins/history-substring-search \ No newline at end of file diff --git a/include.d-omzc/plugins/zsh-syntax-highlighting b/include.d-omzc/plugins/zsh-syntax-highlighting new file mode 120000 index 0000000..176fe3e --- /dev/null +++ b/include.d-omzc/plugins/zsh-syntax-highlighting @@ -0,0 +1 @@ +../../include.d-libs/oh-my-zsh-plugins/syntax-highlighting \ No newline at end of file diff --git a/include.d-omzc/themes/.gitkeep b/include.d-omzc/themes/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/install.sh b/install.bash old mode 100644 new mode 100755 similarity index 89% rename from install.sh rename to install.bash index 202c550..5de6e51 --- a/install.sh +++ b/install.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # @@ -556,23 +556,39 @@ function main { git submodule update --init &> /dev/null out_state_close $? - #out_state_start "Installing fonts" - #${_DZ_INSTALL_TO}/fonts/install.sh &> /dev/null - #out_state_close $? - - #out_state_start "Installing fonts" - #wget -O chruby-0.3.9.tar.gz https://github.com/postmodern/chruby/archive/v0.3.9.tar.gz &> /dev/null - #tar -xzvf chruby-0.3.9.tar.gz &> /dev/null - #cd chruby-0.3.9/ &> /dev/null - #sudo make install - #out_state_close $? + out_state_start "Installing fonts" + sudo printf '' + INSTALL_FONT_ROOT_PATH="${HOME}/.local/share/fonts" ${_DZ_INSTALL_TO}/include.d-libs/fonts/install.bash &> /dev/null + out_state_close $? - #cd .. + out_state_start "Installing fonts" + ( + wget -O chruby-0.3.9.tar.gz https://github.com/postmodern/chruby/archive/v0.3.9.tar.gz &> /dev/null && \ + tar -xzvf chruby-0.3.9.tar.gz &> /dev/null && \ + cd chruby-0.3.9/ &> /dev/null && \ + sudo make install && \ + cd .. && \ + sudo rm -r chruby-0.3.9.tar.gz chruby-0.3.9/ + ) &> /dev/null + out_state_close $? - #out_state_start "Installing phpenv" - #git clone https://github.com/src-run/phpenv.git &> /dev/null - #phpenv/bin/phpenv-install.sh - #out_state_close $? + APT_SRC_BK="/etc/apt/sources.list.backup-${RANDOM}" + out_state_start "Installing phpenv" + ( + git clone https://github.com/src-run/phpenv.git &> /dev/null && \ + cd phpenv && \ + git submodule update --init && \ + sudo cp /etc/apt/sources.list "${APT_SRC_BK}" && \ + sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list && \ + sudo add-apt-repository ppa:ondrej/php --yes && \ + sudo apt upgrade --yes && \ + sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list.d/ondrej-ubuntu-php-*.list && \ + sudo apt update --quiet && \ + NON_INTERFACTIVE=1 bin/phpenv-installer.bash && \ + cd ../ && \ + sudo rm -r ./phpenv/ + ) &> /dev/null + out_state_close $? # Start config components state and force newline out_state_start "Configuring components" diff --git a/load.zsh b/load.zsh index edf7c3f..c028f05 100644 --- a/load.zsh +++ b/load.zsh @@ -9,12 +9,36 @@ # file distributed with this source code. # +# +# Define script path. +# + +_DZ_NAME="${(%):-%N}" + + +# +# Enable shell tracing if environment variable set +# + +if [[ -n "${_DZ_TRACE}" ]] && [[ ${_DZ_TRACE} -gt 0 ]]; then + export PS4='${_DZ_TRACE_PS4:-date[$(date "+%s:%N")] locale[%x:%i|%I] status[%?] state[%_|%^] depth[%e] context[%N] }' + + if [[ ${_DZ_TRACE} -gt 1 ]]; then + exec 3>&2 2>"${HOME:-/tmp}/.dot-zsh-${$}-trace.log" + fi + + setopt xtrace prompt_subst + set -x +fi + + # # Use PCRE regular expressions # setopt re_match_pcre + # # Define root path # @@ -28,8 +52,20 @@ _DZ_IO_BUFF_LINES=() # function _failed_required_file_source { - printf 'Failed to locate a required file: "%s" (%s)...' "${1}" "${2}" - sleep 30 + printf -- \ +' !! [FAIL] Unable to locate or source an integral file that is required for'\ +' this script to function: "%s" (%s)...\n !! [FAIL] Halting any further'\ +' execution of this script due to the unavailability of the aforementioned'\ +' dependency requirement!\n'\ +' ++ [NOTE] To immediately stop this script, press the CONTROL-C key combo'\ +' (this may inadvertently close your terminal/console window in addition to'\ +' terminating the script itself, depending on the script invocation method'\ +' used when calling this executable)...\n'\ +' -- [WAIT] Entered a 5 minute sleep state to preserve any on-screen warnings'\ +' or errors; take this time to reference any prior output or logged data to'\ +' aid in the diagnosis of this unexpected failure state.\n' "${1}" "${2}" + + sleep 300 exit 255 } @@ -68,6 +104,7 @@ _log_buffer 1 "--- Starting micro-time logged at '${_DZ_LOAD_TIME}'" # # Source requires variables assignments and function definitions # + for f in ${_DZ_PATH}/include.d-core/*-internal.zsh; do if [[ ! -f "${f}" ]]; then _failed_required_file_source "${f}" 'it does not exist' @@ -78,14 +115,15 @@ for f in ${_DZ_PATH}/include.d-core/*-internal.zsh; do || _failed_required_file_source "${f}" 'it could not be sourced' done + # # Validate config scheme version. # -_log_normal 1 "--> Validating configuration scheme version ..." +_log_norm 1 "--> Validating configuration scheme version ..." if [[ "$(_cfg_get_string 'package.version.schemes')" == "0.2.1" ]]; then - _log_normal 1 " --> Validated as '0.2.1' in file '${_DZ_INC_JSON_PATH}' ..." + _log_norm 1 " --> Validated as '0.2.1' in file '${_DZ_INC_JSON_PATH}' ..." else _log_crit "Failed to validate scheme (using '${_DZ_DEF_JSON_PATH}' instead)!" _DZ_INC_JSON_PATH="${_DZ_DEF_JSON_PATH}" @@ -107,9 +145,10 @@ _buf_definition_list 1 "LOADER SCRIPT PATH" "$(_self_repo_load)" _buf_definition_list 1 "PREVIOUS SHELL BIN PATH" "$(_parse_shell_path)" _buf_definition_list 1 "FOUND ZSH BIN PATH" "$(_parse_zsh_path)" _buf_definition_list 1 "FOUND ZSH VERSION" "$(_parse_zsh_version)" -_log_normal 3 '--> Loader script environment variables ...' +_log_norm 3 '--> Loader script environment variables ...' _log_definition_list + # # Flushed all buffered lines. # @@ -121,24 +160,25 @@ _buf_flush_lines # Load our configuration files. # -_log_normal 1 \ +_log_norm 1 \ "--> Loading configuration file(s) from '${_DZ_INC_CONF_PATH}' ..." for f in ${_DZ_INC_CONF_PATH}/??-???-*.zsh; do - [[ ! -f "${f}" ]] && \ - _log_normal 1 \ - " --> Failed to source config file '$(basename ${f})'" && \ + if [[ ! -f "${f}" ]]; then + _log_norm 1 " --> Failed to source config file '$(basename ${f})'" continue - - _log_normal 1 " --> Sourcing config file '$(basename ${f})'" && \ + else + _log_norm 1 " --> Sourcing config file '$(basename ${f})'" source "${f}" + fi done + # # Source all enabled includes by int-prefix order. # -_log_normal 1 \ +_log_norm 1 \ "--> Loading enabled include files(s) from '${_DZ_INC_LOAD_PATH}' ..." for f in ${_DZ_INC_LOAD_PATH}/??-???-*.zsh; do @@ -151,7 +191,7 @@ done # _cfg_ret_bool 'systems.dot_zsh.show.loading' && \ - _disable_loading + _o_progress_close # @@ -159,17 +199,17 @@ _cfg_ret_bool 'systems.dot_zsh.show.loading' && \ # _cfg_ret_bool 'systems.dot_zsh.show.summary' && \ - _DZ_DONE_MESSAGE="$(_show_summary)" + _DZ_DONE_MESSAGE="$(_load_summary_display)\n" # # Cleanup all internal variables and functions (unset them). # -_log_normal 1 "--> Performing final cleanup pass ..." +_log_norm 1 "--> Performing final cleanup pass ..." _log_action "Unsetting ${#_DZ_UNSET_VS[@]} internal variables ..." 1 _log_action "Unsetting ${#_DZ_UNSET_FS[@]} internal functions ..." 1 -_log_normal 1 "--> Completed all operations ..." +_log_norm 1 "--> Completed all operations ..." for v in ${_DZ_UNSET_VS[@]}; do eval "unset ${v}" 2> /dev/null @@ -191,3 +231,9 @@ if [[ ! -z "${_DZ_DONE_MESSAGE}" ]]; then echo -en "${_DZ_DONE_MESSAGE}" unset _DZ_DONE_MESSAGE fi + +# BEGIN SNIPPET: Platform.sh CLI configuration +HOME=${HOME:-'/home/rmf'} +export PATH="$HOME/"'.platformsh/bin':"$PATH" +if [ -f "$HOME/"'.platformsh/shell-config.rc' ]; then . "$HOME/"'.platformsh/shell-config.rc'; fi # END SNIPPET +