mirror of
https://github.com/nikdoof/dotfiles.git
synced 2026-01-31 11:28:14 +00:00
[shell-common] Improve update-dotfiles
This commit is contained in:
@@ -1,13 +1,27 @@
|
|||||||
# Git pulls latest dotfiles
|
# Git pulls latest dotfiles
|
||||||
function update-dotfiles() {
|
function update-dotfiles() {
|
||||||
prevdir=$PWD
|
local prevdir="$PWD"
|
||||||
for dir in "${HOME}/.dotfiles" "${HOME}/.dotfiles-private" "${HOME}/.dotfiles-work"; do
|
local dotfiles_dirs=(".dotfiles" ".dotfiles-private" ".dotfiles-work")
|
||||||
if [ -d "$dir" ]; then
|
|
||||||
cd "$dir"
|
for dir in "${dotfiles_dirs[@]}"; do
|
||||||
git pull --rebase --autostash
|
if [[ -d "${HOME}/$dir" ]]; then
|
||||||
|
if [[ ! -d "${HOME}/$dir/.git" ]]; then
|
||||||
|
echo "Warning: $dir exists but is not a git repository. Skipping..."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Updating $dir..."
|
||||||
|
if cd "${HOME}/$dir" 2>/dev/null; then
|
||||||
|
if ! git pull --rebase --autostash; then
|
||||||
|
echo "Error: Failed to update $dir"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Error: Cannot access directory $dir"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
cd "$prevdir"
|
|
||||||
|
cd "$prevdir" || echo "Warning: Could not return to original directory $prevdir"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Wrapper around ssh-add to easily add SSH keys with a timeout
|
# Wrapper around ssh-add to easily add SSH keys with a timeout
|
||||||
|
|||||||
Reference in New Issue
Block a user