remove manage script and move things around for gnu stow

This commit is contained in:
tjp 2024-02-19 19:53:23 -07:00
parent cba7e576dc
commit 7120f4217f
29 changed files with 2 additions and 226 deletions

2
.stow-local-ignore Normal file
View File

@ -0,0 +1,2 @@
\.git
LICENSE\.txt

226
manage
View File

@ -1,226 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
GREEN="$(printf '\e[0;32m')"
YELLOW="$(printf '\e[0;33m')"
RED="$(printf '\e[0;31m')"
CLEAR="$(printf '\e[0m')"
HERE="$(cd $(dirname $0); pwd)"
CONF="${XDG_CONFIG_HOME:-$HOME/.config}"
help() {
cat <<EOF
Manage symlinks from directories in this repository to XDG_CONFIG_HOME.
With NAME, it will only operate on the one directory. Otherwise it loops
through all of them.
Usage:
$0 link [ NAME ]
$0 unlink [ NAME ]
$0 status [ NAME ]
$0 help
EOF
}
link() {
if [[ "${1:-}" != "" ]]; then
if [[ $1 == home/* ]]; then
dotlink ${1##home/}
return
fi
name="$1"
src="$HERE/$name"
if [ ! -d $src -o $name = "home" ]; then return; fi
echo -n "$name..."
tgt="$CONF/$name"
bu="${tgt}_bu"
if [[ -e $bu ]]; then
echo -n "${RED}removing old _bu${CLEAR}..."
rm -rf ${bu}
fi
if [[ -e $tgt ]]; then
echo -n "${YELLOW}moving existing config to ${name}_bu${CLEAR}..."
mv $tgt $bu
fi
echo -n "${GREEN}linking${CLEAR}..."
ln -s $src $tgt
echo "${GREEN}LINKED${CLEAR}"
else
for path in $HERE/*; do
link $(basename $path)
done
for path in $HERE/home/*; do
dotlink ${path##$HERE/home/}
done
fi
}
dotlink() {
name="$1"
src="$HERE/home/${name}"
if [[ ! -e $src ]]; then return; fi
echo -n "home/$name..."
tgt="$HOME/.${name}"
bu="${tgt}_bu"
if [[ -e $bu ]]; then
echo -n "${RED}removing old _bu${CLEAR}..."
rm -rf ${bu}
fi
if [[ -e $tgt ]]; then
echo -n "${YELLOW}moving existing config to ${name}_bu${CLEAR}..."
mv $tgt $bu
fi
echo -n "${GREEN}linking${CLEAR}..."
ln -s $src $tgt
echo "${GREEN}LINKED${CLEAR}"
}
unlink() {
if [[ "${1:-}" != "" ]]; then
if [[ $1 == home/* ]]; then
dotunlink ${1##home/}
return
fi
name="$1"
src="$HERE/$name"
if [ ! -d $src -o $name = "home" ]; then return; fi
echo -n "$name..."
tgt="$CONF/$name"
bu="${tgt}_bu"
if [[ ! -e $tgt ]]; then
echo "${RED}WAS NOT LINKED${CLEAR}"
return
fi
echo -n "${YELLOW}unlinking${CLEAR}..."
rm $tgt
if [[ -e $bu ]]; then
echo -n "${YELLOW}restoring from ${name}_bu${CLEAR}..."
mv $bu $tgt
fi
echo "${GREEN}UNLINKED${CLEAR}"
else
for path in $HERE/*; do
unlink $(basename $path)
done
for path in $HERE/home/*; do
dotunlink ${path##$HERE/home/}
done
fi
}
dotunlink() {
name="$1"
src="$HERE/home/${name}"
if [[ ! -e $src ]]; then return; fi
echo -n "home/$name..."
tgt="$HOME/.${name}"
bu="${tgt}_bu"
if [[ ! -e $tgt ]]; then
echo "${RED}WAS NOT LINKED${CLEAR}"
return
fi
echo -n "${YELLOW}unlinking${CLEAR}..."
rm $tgt
if [[ -e $bu ]]; then
echo -n "${YELLOW}restoring from ${name}_bu${CLEAR}..."
mv $bu $tgt
fi
echo "${GREEN}UNLINKED${CLEAR}"
}
status() {
if [[ "${1:-}" != "" ]]; then
if [[ $1 == home/* ]]; then
dotstatus ${1##home/}
return
fi
name="$1"
src="$HERE/$name"
if [ ! -d $src -o $name = "home" ]; then return; fi
tgt="$CONF/$name"
echo -n "$name "
if [[ ! -e $tgt ]]; then
echo "${YELLOW}IS NOT LINKED and does not exist${CLEAR}"
return
fi
if [[ "$(readlink $tgt)" = $src ]]; then
echo "${GREEN}IS LINKED${CLEAR}"
else
echo "${YELLOW}IS NOT LINKED but exists${CLEAR}"
fi
else
for path in $HERE/*; do
status $(basename $path)
done
for path in $HERE/home/*; do
dotstatus ${path##$HERE/home/}
done
fi
}
dotstatus() {
name="$1"
src="$HERE/home/${name}"
if [[ ! -e $src ]]; then return; fi
tgt="$HOME/.${name}"
echo -n "home/$name "
if [[ ! -e $tgt ]]; then
echo "${YELLOW}IS NOT LINKED and does not exist${CLEAR}"
return
fi
if [[ "$(readlink $tgt)" = $src ]]; then
echo "${GREEN}IS LINKED${CLEAR}"
else
echo "${YELLOW}IS NOT LINKED but exists${CLEAR}"
fi
}
case "${1:-}" in
link | unlink | help | status)
"$@"
;;
*)
help
exit 1
;;
esac