setup update complete
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#####################################################################
|
||||
|
||||
setup.filesystem.ensure-paths() {
|
||||
local ERRORS=0
|
||||
local directories=(
|
||||
"${XDG_CONFIG_HOME:-${HOME}/.config}/wryn"
|
||||
"${HOME}/.local/bin"
|
||||
)
|
||||
|
||||
local files=(
|
||||
"${HOME}/.zshrc"
|
||||
)
|
||||
|
||||
echo.status 'ensuring required paths exist'
|
||||
local directory
|
||||
for directory in "${directories[@]}"
|
||||
do
|
||||
mkdir -p -- "${directory}" || echo.error "failed to create directory '${directory}'"
|
||||
done
|
||||
unset directory
|
||||
|
||||
local file
|
||||
for file in "${files[@]}"
|
||||
do
|
||||
touch -- "${file}" || echo.error "failed to create file '${file}'"
|
||||
done
|
||||
unset file
|
||||
|
||||
[[ "${ERRORS}" -eq 0 ]] \
|
||||
&& echo.success 'required paths ready' \
|
||||
|| echo.error 'failed to ensure required paths' \
|
||||
;
|
||||
|
||||
return "${ERRORS}"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#####################################################################
|
||||
|
||||
for setup_library in "${0:a:h}"/*.zsh
|
||||
do
|
||||
case "${setup_library:t}" in
|
||||
( filesystem.module.zsh ) ;; # self
|
||||
( * ) source "${setup_library}" ;;
|
||||
esac
|
||||
done
|
||||
unset setup_library
|
||||
|
||||
#####################################################################
|
||||
|
||||
setup.filesystem() { : \
|
||||
&& setup.filesystem.ensure-paths \
|
||||
&& setup.filesystem.git \
|
||||
; }
|
||||
@@ -0,0 +1,81 @@
|
||||
#####################################################################
|
||||
|
||||
setup.filesystem.git() {
|
||||
local sources_dir="${XDG_DATA_HOME:-${HOME}/.local/share}/project-source-code"
|
||||
|
||||
SOURCE_DIR="${DOTWRYN_SETUP__DOTWRYN}" \
|
||||
TARGET_DIR="${sources_dir}/yage/dotwryn" \
|
||||
REMOTE_UPSTREAMS=(
|
||||
'git@github.com:wrynegade/dotwryn.git'
|
||||
'git@yage.io:wrynegade/dotwryn.git'
|
||||
'git@bitbucket.org:wrynegade/dotwryn.git'
|
||||
) setup.filesystem.git._.remotes '.wryn'
|
||||
|
||||
SOURCE_DIR="${DOTWRYN_SETUP__DOTWRYN}/zsh/plugins/code-activator" \
|
||||
TARGET_DIR="${sources_dir}/zsh/code-activator" \
|
||||
REMOTE_UPSTREAMS=(
|
||||
'git@yage.io:zsh/code-activator.git'
|
||||
'git@github.com:wrynegade/code-activator.git'
|
||||
) setup.filesystem.git._.remotes 'zsh-plugins/code-activator'
|
||||
|
||||
SOURCE_DIR="${DOTWRYN_SETUP__DOTWRYN}/zsh/plugins/scwrypts" \
|
||||
TARGET_DIR="${sources_dir}/zsh/scwrypts" \
|
||||
REMOTE_UPSTREAMS=(
|
||||
'git@yage.io:zsh/scwrypts'
|
||||
'git@github.com:wrynegade/scwrypts'
|
||||
) setup.filesystem.git._.remotes 'zsh-plugins/scwrypts'
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
setup.filesystem.git._.remotes() {
|
||||
: \
|
||||
&& [[ "${SOURCE_DIR}" ]] \
|
||||
&& [[ "${TARGET_DIR}" ]] \
|
||||
&& [[ "${#REMOTE_UPSTREAMS[@]}" -gt 0 ]] \
|
||||
|| return 1 \
|
||||
;
|
||||
|
||||
[[ "${1}" ]] && echo.status "updating remotes for '${1}'"
|
||||
|
||||
git -C "${SOURCE_DIR}" remote rm upstream 2>/dev/null
|
||||
git -C "${SOURCE_DIR}" remote add upstream "${REMOTE_UPSTREAMS[1]}"
|
||||
|
||||
local remote_upstream
|
||||
for remote_upstream in "${REMOTE_UPSTREAMS[@]}"
|
||||
do
|
||||
git -C "${SOURCE_DIR}" remote set-url --add --push upstream "${remote_upstream}"
|
||||
|
||||
case "${remote_upstream}" in
|
||||
( git@github.com:* )
|
||||
git -C "${SOURCE_DIR}" remote rm github 2>/dev/null
|
||||
git -C "${SOURCE_DIR}" remote add github "${remote_upstream}"
|
||||
;;
|
||||
( git@yage.io:* )
|
||||
git -C "${SOURCE_DIR}" remote rm yage 2>/dev/null
|
||||
git -C "${SOURCE_DIR}" remote add yage "${remote_upstream}"
|
||||
;;
|
||||
( git@bitbucket.org:* )
|
||||
git -C "${SOURCE_DIR}" remote rm bitbucket 2>/dev/null
|
||||
git -C "${SOURCE_DIR}" remote add bitbucket "${remote_upstream}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
unset remote_upstream
|
||||
|
||||
SOURCE_DIR="${SOURCE_DIR}" TARGET_DIR="${TARGET_DIR}" setup.filesystem.git._.link-to-projects \
|
||||
|| echo.warning "failed to link '${TARGET_DIR}'"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
setup.filesystem.git._.link-to-projects() {
|
||||
[[ "${TARGET_DIR}" ]] && [[ "${SOURCE_DIR}" ]] \
|
||||
|| return 1
|
||||
|
||||
{
|
||||
mkdir -p -- "${TARGET_DIR}"
|
||||
rm -- "${TARGET_DIR}/code"
|
||||
ln -s -- "${SOURCE_DIR}" "${TARGET_DIR}/code"
|
||||
} &>/dev/null
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
#####################################################################
|
||||
|
||||
setup.filesystem.write-managed-block() {
|
||||
# replaces (or appends) a dotwryn-managed block in a file, taking the
|
||||
# block body from stdin, so that every run refreshes the block rather
|
||||
# than appending another copy of it
|
||||
#
|
||||
# callers should use a "<<-" heredoc: it strips leading TABS (letting
|
||||
# the body stay indented with its caller) but leaves SPACES alone, so
|
||||
# indent the block's own nesting with spaces to keep it in the output
|
||||
#
|
||||
# "--one-line" trades the begin/end banner for a trailing comment on
|
||||
# the line itself, which suits a one-line entry like an rc source
|
||||
local file tag
|
||||
local comment='#'
|
||||
local one_line=false
|
||||
|
||||
local _s _p
|
||||
while [[ "${#}" -gt 0 ]]
|
||||
do
|
||||
_s=1
|
||||
case "${1}" in
|
||||
( --comment ) _s=2
|
||||
comment="${2}"
|
||||
;;
|
||||
( --tag ) _s=2
|
||||
tag="${2}"
|
||||
;;
|
||||
( --one-line )
|
||||
one_line=true
|
||||
;;
|
||||
( * )
|
||||
case "$((_p+=1))" in
|
||||
( 1 ) file="${1}" ;;
|
||||
( * ) echo.error "write-managed-block: unexpected argument '${1}'" ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
shift "${_s}"
|
||||
done
|
||||
unset _s _p
|
||||
|
||||
[[ "${file}" ]] \
|
||||
|| echo.error 'write-managed-block: no file given' \
|
||||
|| return 1
|
||||
|
||||
# a single file can carry several managed blocks, so each one has to be
|
||||
# named to know which of them it owns
|
||||
[[ "${tag}" ]] \
|
||||
|| echo.error "write-managed-block: no --tag given for '${file}'" \
|
||||
|| return 1
|
||||
|
||||
local body="$(cat)"
|
||||
|
||||
[[ "${one_line}" == false ]] || [[ "${body}" != *$'\n'* ]] \
|
||||
|| echo.error "write-managed-block: --one-line needs a single-line body for '${file}'" \
|
||||
|| return 1
|
||||
|
||||
mkdir -p -- "${file:h}"
|
||||
touch -- "${file}"
|
||||
|
||||
local -a lines block
|
||||
lines=("${(@f)$(<"${file}")}")
|
||||
[[ -s "${file}" ]] || lines=()
|
||||
|
||||
# an existing block is replaced where it sits, so anything the user
|
||||
# wrote around it keeps its position
|
||||
local begin_index end_index
|
||||
case "${one_line}" in
|
||||
( true )
|
||||
local marker="${comment} managed by dotwryn setup (${tag})"
|
||||
block=("${body} ${marker}")
|
||||
|
||||
# "(b)" keeps the tag's parentheses literal rather than glob
|
||||
begin_index="${lines[(i)*${(b)marker}]}"
|
||||
end_index="${begin_index}"
|
||||
;;
|
||||
( false )
|
||||
local begin="${comment} >>> managed by dotwryn setup (${tag}) >>>"
|
||||
local end="${comment} <<< managed by dotwryn setup (${tag}) <<<"
|
||||
block=("${begin}" "${(@f)body}" "${end}")
|
||||
|
||||
begin_index="${lines[(ie)${begin}]}"
|
||||
end_index="${lines[(ie)${end}]}"
|
||||
[[ "${end_index}" -le "${#lines[@]}" ]] || end_index="${#lines[@]}"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "${begin_index}" -gt "${#lines[@]}" ]]
|
||||
then
|
||||
lines+=("${block[@]}")
|
||||
else
|
||||
lines=(
|
||||
"${lines[@]:0:$((begin_index - 1))}"
|
||||
"${block[@]}"
|
||||
"${lines[@]:${end_index}}"
|
||||
)
|
||||
fi
|
||||
|
||||
print -l -- "${lines[@]}" > "${file}"
|
||||
}
|
||||
Reference in New Issue
Block a user