diff --git a/zsh/env.zsh b/zsh/env.zsh new file mode 100644 index 0000000..167effc --- /dev/null +++ b/zsh/env.zsh @@ -0,0 +1,18 @@ +##################################################################### +### default .wryn configuration settings ############################ +##################################################################### + +# order of editor preference +export PREFERRED_EDITORS=(vim vi nano) + +# prompt generator settings +PS1_BRANCH_SYMBOL='' +PS1_INDICATOR_SYMBOL='☕' +PS1_SEPARATOR='::' +PS1_USER='%m' + +# run at each zsh login +WELCOME () { + [[ ${TERM} =~ tmux ]] && return 0 + { figlet 'Welcome, beautiful'; cowsay -p 'damn u sexy'; } | lolcat +} diff --git a/zsh/rc b/zsh/rc index 8f4c44d..418b0ae 100644 --- a/zsh/rc +++ b/zsh/rc @@ -1,8 +1,8 @@ #!/bin/zsh for RC_FILE in $(find "${0:a:h}/rc.d/" -type f | sort) do - source "$RC_FILE" || { - echo "something went wrong in '$RC_FILE'; aborting dotwryn load" + source "${RC_FILE}" || { + echo "something went wrong in '${RC_FILE}'; aborting dotwryn load early" return 1 } done diff --git a/zsh/rc.d/00.config.zsh b/zsh/rc.d/00.config.zsh index 7463448..de21cf7 100644 --- a/zsh/rc.d/00.config.zsh +++ b/zsh/rc.d/00.config.zsh @@ -11,6 +11,6 @@ } : \ - && source "${DOTWRYN}/config/dotwryn.env.zsh" \ + && source "${DOTWRYN}/zsh/env.zsh" \ && source "${XDG_CONFIG_HOME:-${HOME}/.config}/wryn/env.zsh" \ ; diff --git a/zsh/rc.d/01.config-xdg.zsh b/zsh/rc.d/01.config-xdg.zsh index 31d0d81..82c68fb 100644 --- a/zsh/rc.d/01.config-xdg.zsh +++ b/zsh/rc.d/01.config-xdg.zsh @@ -15,8 +15,13 @@ export XDG_CONFIG_DIRS=/etc/xdg export AWS_CONFIG_FILE="${XDG_DATA_HOME}/aws/config" export AWS_SHARED_CREDENTIALS_FILE="${XDG_DATA_HOME}/aws/credentials" export CARGO_HOME="${XDG_DATA_HOME}/cargo" +export DOCKER_CONFIG="${XDG_CONFIG_HOME}/docker" export GNUPGHOME="${XDG_DATA_HOME}/gnupg" export GOPATH="${XDG_DATA_HOME}/go" +export GRADLE_USER_HOME="${XDG_DATA_HOME}/gradle" +export KUBECACHEDIR="${XDG_CACHE_HOME}/kube" +export KUBECONFIG="${XDG_CONFIG_HOME}/kube/config" +export MACHINE_STORAGE_PATH="${XDG_DATA_HOME}/docker-machine" export NPM_CONFIG_USERCONFIG="${XDG_CONFIG_HOME}/npm/npmrc" export PYTHONPYCACHEPREFIX="${XDG_CACHE_HOME}/python" export PYTHONUSERBASE="${XDG_DATA_HOME}/python" @@ -27,6 +32,7 @@ export TERMINFO_DIRS="${XDG_DATA_HOME}/terminfo:/usr/share/terminfo" export XAUTHORITY="${XDG_RUNTIME_DIR}/Xauthority" export XINITRC="${XDG_CONFIG_HOME}/X11/xinitrc" export XSERVERRC="${XDG_CONFIG_HOME}/X11/xserverrc" +export _JAVA_OPTIONS=-Djava.util.prefs.userRoot="${XDG_CONFIG_HOME}/java" export _Z_DATA="${XDG_DATA_HOME}/z" ##################################################################### diff --git a/zsh/rc.d/10.plugins.zsh b/zsh/rc.d/10.plugins.zsh index 8992666..e7863ea 100644 --- a/zsh/rc.d/10.plugins.zsh +++ b/zsh/rc.d/10.plugins.zsh @@ -1,10 +1,10 @@ ##################################################################### ZSH_PLUGINS+=( - "$DOTWRYN/colorschemes/active/getty.sh" - "$DOTWRYN/zsh/plugins/code-activator/activator.plugin.zsh" - "$DOTWRYN/zsh/plugins/z/z.sh" - "$DOTWRYN/zsh/alias" + "${DOTWRYN}/config/colorschemes/active/getty.sh" + "${DOTWRYN}/zsh/plugins/code-activator/activator.plugin.zsh" + "${DOTWRYN}/zsh/plugins/z/z.sh" + "${DOTWRYN}/zsh/alias" ) ##################################################################### diff --git a/zsh/rc.d/15.plugins-scwrypts.zsh b/zsh/rc.d/15.plugins-scwrypts.zsh index 182a752..f4a98cf 100644 --- a/zsh/rc.d/15.plugins-scwrypts.zsh +++ b/zsh/rc.d/15.plugins-scwrypts.zsh @@ -1,7 +1,7 @@ ##################################################################### ZSH_PLUGINS+=( - "$(scwrypts --root 2>/dev/null)/scwrypts.plugin.zsh" + "$(scwrypts --root)/scwrypts.plugin.zsh" ) () { # default environment name lookup @@ -14,7 +14,7 @@ ZSH_PLUGINS+=( "dev" \ ; do - [ -f "$HOME/.config/scwrypts/environments/scwrypts/$ENVIRONMENT_NAME" ] \ + [ -f "${XDG_CONFIG_HOME:-${HOME}/.config}/scwrypts/environments/$ENVIRONMENT_NAME.scwrypts.env.yaml" ] \ && export SCWRYPTS_ENV="$ENVIRONMENT_NAME" \ && break done diff --git a/zsh/rc.d/20.setup-path.zsh b/zsh/rc.d/20.setup-path.zsh index 366834e..6a0c558 100644 --- a/zsh/rc.d/20.setup-path.zsh +++ b/zsh/rc.d/20.setup-path.zsh @@ -1,9 +1,10 @@ () { # create path entries local PATH_ENTRY for PATH_ENTRY in \ - "${HOME}/.local/bin" \ - "${HOME}/.local/share/$(hostnamectl --static)" \ "${GOPATH}/bin" \ + "${HOME}/.local/bin" \ + "${DOTWRYN}/config/bin" \ + "${DOTWRYN}/config/local/$(hostnamectl --static)/bin" \ ; do echo "$PATH" | sed 's/:/\n/g' | grep -q "^$PATH_ENTRY$" \ diff --git a/zsh/rc.d/80.frog.zsh b/zsh/rc.d/80.frog.zsh new file mode 100644 index 0000000..d5ed03b --- /dev/null +++ b/zsh/rc.d/80.frog.zsh @@ -0,0 +1,154 @@ +command -v \ + echo.error \ + echo.status \ + echo.success \ + echo.success.color \ + rg \ + sed \ + utils.check-errors \ + utils.colors.green \ + utils.yN \ + &>/dev/null || return 0 + + +frog() { + eval "$(usage.reset)" + + local USAGE__description=' + find-and-replace for all files in the current directory + + frog = [F]ix [R]ip[G]rep ... and "o" because 🐸 + ' + + local USAGE__options=' + -s, --search the regex to search for + -r, --replace replacement value + + -d, --delete delete instead having a replacement value + --trim trim trailing spaces from all files in the work-tree + + -h, --help print this message + ' + + local USAGE__args=' + \$1 search regex + \$2 replacement value + ' + + local SEARCH_REGEX REPLACE_VALUE DELETE=false TRIM=false + + local _S ERRORS=0 POSITIONAL_ARGUMENT_COUNT=0 + while [[ $# -gt 0 ]] + do + _S=1 + + case $1 in + ( -s | --search ) + _S=2 + SEARCH_REGEX="$2" + ;; + + ( -r | --replace ) + _S=2 + REPLACE_VALUE="$2" + ;; + + ( -d | --delete ) + _S=1 + DELETE=true + ;; + + ( --trim ) + _S=1 + TRIM=true + DELETE=true + SEARCH_REGEX='\s+$' + ;; + + ( -h | --help ) + utils.io.usage + return 0 + ;; + + ( * ) + ((POSITIONAL_ARGUMENT_COUNT+=1)) + case ${POSITIONAL_ARGUMENT_COUNT} in + ( 1 ) + case "${SEARCH_REGEX}" in + ( '' ) + SEARCH_REGEX="$1" + ;; + ( * ) + [ ! "${REPLACE_VALUE}" ] \ + && REPLACE_VALUE="$1" \ + || echo.error "too many arguments" \ + ; + ;; + esac + ;; + + ( 2 ) + [ ! "${REPLACE_VALUE}" ] \ + && REPLACE_VALUE="$1" \ + || echo.error "too many arguments" \ + ; + ;; + + ( * ) + echo.error "unknown argument '$1'" + ;; + esac + ;; + esac + + [[ ${_S} -le $# ]] \ + && shift ${_S} \ + || echo.error "argument error for '$1'" \ + || shift $# + done + + [ ! "${SEARCH_REGEX}" ] && [ ! "${REPLACE_VALUE}" ] && [[ ${DELETE} =~ false ]] && [[ ${POSITIONAL_ARGUMENT_COUNT} -eq 0 ]] \ + && utils.io.usage \ + && return 0 \ + ; + + [ "${SEARCH_REGEX}" ] \ + || echo.error "missing search regex" + + [ ! "${REPLACE_VALUE}" ] && [[ ${DELETE} =~ false ]] \ + && echo.error "missing replacement value" + + [ "${REPLACE_VALUE}" ] && [[ ${DELETE} =~ true ]] \ + && echo.error "cannot use '--delete' with a replacement value" + + utils.check-errors || return $? + + ########################################## + + local FILES_MATCHED=($(rg -l -- "${SEARCH_REGEX}")) + [[ ${#FILES_MATCHED[@]} -gt 0 ]] || { + echo.status "no files contain '${SEARCH_REGEX}' in the current tree; nothing to do" + return 0 + } + + clear + + rg -- "${SEARCH_REGEX}" ${FILES_MATCHED[@]} + + echo.status "showing matches from $(utils.colors.green)${#FILES_MATCHED[@]} file(s)$(echo.status.color) in the current directory" + utils.yN "replace all matches with '${REPLACE_VALUE}'?" || return 1 + + [[ ${TRIM} =~ true ]] && SEARCH_REGEX='\s\+$' + + local FILENAME + for FILENAME in ${FILES_MATCHED[@]} + do + sed -i "s${SEARCH_REGEX}${REPLACE_VALUE}g" "${FILENAME}" \ + || echo.error "failed to update '${FILENAME}'" + done + + [[ ${ERRORS} -eq 0 ]] \ + && echo.success "successfully replaced '${SEARCH_REGEX}' with '${REPLACE_VALUE}'" \ + || echo.error "something went wrong (see above)" \ + ; +} diff --git a/zsh/rc.d/99.welcome.zsh b/zsh/rc.d/99.welcome.zsh index 63f78d5..26f8a45 100644 --- a/zsh/rc.d/99.welcome.zsh +++ b/zsh/rc.d/99.welcome.zsh @@ -1,12 +1,13 @@ -case $TERM in - *kitty* | *alacritty* ) +WELCOME +case ${TERM} in + ( *kitty* | *alacritty* ) # when using desktop terminal emulators, automatically launch tmux/omni # if no active omni client can be found : \ && [[ $(tmux -L omni.socket list-clients 2>/dev/null | wc -l) -eq 0 ]] \ - && scwrypts tmux omni \ - || WELCOME \ + && scwrypts -n tmux omni \ ; ;; - * ) WELCOME ;; esac + +return 0