bootstrap & clean scripts: minor refactor
This commit is contained in:
parent
af1ff21c42
commit
a2d62b670d
17
bootstrap
17
bootstrap
|
@ -7,10 +7,14 @@
|
||||||
# 2. run $topic/install the first time
|
# 2. run $topic/install the first time
|
||||||
# 3. run $topic/update on consecutive runs
|
# 3. run $topic/update on consecutive runs
|
||||||
|
|
||||||
|
CWD="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
pushd "$CWD" >/dev/null
|
||||||
set -e
|
set -e
|
||||||
source "$(cd $(dirname $0) && pwd -P)/shell/common.sh"
|
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
|
# shellcheck source=shell/common.sh
|
||||||
|
source "shell/common.sh"
|
||||||
|
|
||||||
#
|
#
|
||||||
blue="\033[34m"
|
blue="\033[34m"
|
||||||
magenta="\033[35m"
|
magenta="\033[35m"
|
||||||
|
@ -22,7 +26,7 @@ nc="\033[0m"
|
||||||
#
|
#
|
||||||
|
|
||||||
_run() {
|
_run() {
|
||||||
local cmd="${@//$DOTFILES\//}"
|
local cmd="${*//$DOTFILES\//}"
|
||||||
cmd="${cmd//$HOME/~}"
|
cmd="${cmd//$HOME/~}"
|
||||||
local clr=""
|
local clr=""
|
||||||
case $cmd in
|
case $cmd in
|
||||||
|
@ -40,7 +44,7 @@ _link() {
|
||||||
if [[ $yes ]]; then
|
if [[ $yes ]]; then
|
||||||
[[ $yes = 1 ]] && choice=y || choice=n
|
[[ $yes = 1 ]] && choice=y || choice=n
|
||||||
else
|
else
|
||||||
read -n 1 -p "? ${1##*/} exists in $2 -- overwrite? [y/n] " choice
|
read -r -n 1 -p "? ${1##*/} exists in $2 -- overwrite? [y/n] " choice
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
case $choice in
|
case $choice in
|
||||||
|
@ -57,6 +61,7 @@ _link() {
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
|
export SERVER=
|
||||||
install=1
|
install=1
|
||||||
link=1
|
link=1
|
||||||
update=1
|
update=1
|
||||||
|
@ -99,10 +104,8 @@ done
|
||||||
shift $((OPTIND-1))
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
#
|
#
|
||||||
CWD=$(cd $(dirname $0) && pwd -P)
|
ENABLED_DIR=".enabled.d"
|
||||||
ENABLED_DIR="$CWD/.enabled.d"
|
for topic in "${@:-$(ls -1 "$ENABLED_DIR" | sed 's%_%/%')}"; do
|
||||||
pushd $CWD >/dev/null
|
|
||||||
for topic in ${@:-$(ls -1 "$ENABLED_DIR" | sed 's%_%/%')}; do
|
|
||||||
[[ -d $topic ]] || continue
|
[[ -d $topic ]] || continue
|
||||||
|
|
||||||
echo -e "${green}${topic}${nc}"
|
echo -e "${green}${topic}${nc}"
|
||||||
|
|
12
clean
12
clean
|
@ -8,7 +8,13 @@
|
||||||
# -d Do a dry run (only output commands, no changes)
|
# -d Do a dry run (only output commands, no changes)
|
||||||
# -u Uninstall all enabled topics
|
# -u Uninstall all enabled topics
|
||||||
|
|
||||||
_run() { [[ $DRYRUN ]] && echo "$@" || $@; }
|
_run() {
|
||||||
|
if [[ $DRYRUN ]]; then
|
||||||
|
echo "$@"
|
||||||
|
else
|
||||||
|
$@
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
uninstall=
|
uninstall=
|
||||||
while getopts du opt; do
|
while getopts du opt; do
|
||||||
|
@ -24,13 +30,13 @@ shift $((OPTIND-1))
|
||||||
|
|
||||||
# Remove enabled topics
|
# Remove enabled topics
|
||||||
if [[ $uninstall ]]; then
|
if [[ $uninstall ]]; then
|
||||||
_run rm -v "$(cd $(dirname $0) && pwd -P)"/.enabled.d/*
|
_run rm -v "$(cd "$(dirname "$0")" && pwd -P)"/.enabled.d/*
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove dead links
|
# Remove dead links
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
links=( $HOME/.* $HOME/.*/* )
|
links=( $HOME/.* $HOME/.*/* )
|
||||||
for link in ${links[@]}; do
|
for link in "${links[@]}"; do
|
||||||
if [[ -h "$link" && ! -e "$link" ]]; then
|
if [[ -h "$link" && ! -e "$link" ]]; then
|
||||||
_run rm -vf "$link"
|
_run rm -vf "$link"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue