feat: flags for git pull

This commit is contained in:
hesam-init 2024-05-21 12:19:04 +03:30
parent 7b39e65323
commit c3efb1c9d9
2 changed files with 39 additions and 8 deletions

38
pull.sh
View file

@ -1,14 +1,40 @@
#!/bin/bash
git_pull() {
git pull
if [[ "$1" == "-p" ]]; then
git stash
git pull
git stash pop
else
git pull
fi
}
git_pull_submodule() {
git submodule update --recursive --remote
git submodule foreach git checkout main
git submodule foreach git pull origin main
if [[ "$1" == "-s" ]]; then
git submodule update --recursive --remote
git submodule foreach git checkout main
git submodule foreach git pull origin main
else
echo "Usage: $0 -s"
fi
}
git_pull
git_pull_submodule
while getopts "ps" opt; do
case $opt in
p)
git_pull -p
;;
s)
git_pull_submodule -s
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
if [[ $# -eq 0 ]]; then
git_pull
fi

View file

@ -53,7 +53,7 @@ unstow() {
log "All configs ustowed successfully !"
}
while getopts ":suh" opt; do
while getopts "ps" opt; do
case $opt in
s)
stow
@ -61,8 +61,13 @@ while getopts ":suh" opt; do
u)
unstow
;;
*)
\?)
display_help
exit 1
;;
esac
done
if [[ $# -eq 0 ]]; then
display_help
fi