more XDG refactors; now with scwrypts v5 going into main I can finally include FROG 🐸
This commit is contained in:
parent
a20d23ad5e
commit
0db79302d7
18
zsh/env.zsh
Normal file
18
zsh/env.zsh
Normal file
@ -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
|
||||
}
|
4
zsh/rc
4
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
|
||||
|
@ -11,6 +11,6 @@
|
||||
}
|
||||
|
||||
: \
|
||||
&& source "${DOTWRYN}/config/dotwryn.env.zsh" \
|
||||
&& source "${DOTWRYN}/zsh/env.zsh" \
|
||||
&& source "${XDG_CONFIG_HOME:-${HOME}/.config}/wryn/env.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"
|
||||
|
||||
#####################################################################
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
#####################################################################
|
||||
|
@ -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
|
||||
|
@ -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$" \
|
||||
|
154
zsh/rc.d/80.frog.zsh
Normal file
154
zsh/rc.d/80.frog.zsh
Normal file
@ -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 <sed regex> the regex to search for
|
||||
-r, --replace <string> 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)" \
|
||||
;
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user