c.sh/c.sh

67 lines
1.3 KiB
Bash
Raw Normal View History

2021-12-06 15:01:12 +01:00
#!/usr/bin/env bash
2023-01-20 21:31:21 +01:00
[[ $# -eq 0 ]] && echo "no subcommand given, sorry :(" && exit 1
2021-12-06 15:01:12 +01:00
2021-12-07 22:28:57 +01:00
WORKDIR="$(dirname "$(realpath "$0")")/../repo"
2021-12-06 15:01:12 +01:00
PWD=`pwd`
RESOURCE_TO_TRACK=""
[[ $1 = "track" && $# -eq 2 ]] && RESOURCE_TO_TRACK="$(realpath "$2")"
cd $WORKDIR
case $1 in
"commit")
shift
MESSAGE="$*"
2021-12-06 15:04:28 +01:00
[[ "$MESSAGE" = "" ]] && MESSAGE="c.sh commit from $HOSTNAME"
2021-12-06 15:01:12 +01:00
git add --all
git commit -m "$MESSAGE"
;;
"track")
if [[ $# -ne 2 ]]; then
echo "no file or folder given"
exit 1
fi
# Check if there is a .git folder. If so, we need to temporary
# rename it, so we can track the file/folder.
GIT_DIR=
TRAVERSAL_PATH="$RESOURCE_TO_TRACK"
while [[ "$TRAVERSAL_PATH" != "/" ]]; do
if [[ -d "$TRAVERSAL_PATH/.git" ]]; then
GIT_DIR="$TRAVERSAL_PATH/.git"
break
fi
TRAVERSAL_PATH="$(dirname $TRAVERSAL_PATH)"
done
[[ "$GIT_DIR" != "" ]] && mv "$GIT_DIR" "$GIT_DIR.keep"
git add -v -f "$RESOURCE_TO_TRACK"
[[ "$GIT_DIR" != "" ]] && mv "$GIT_DIR.keep" "$GIT_DIR"
;;
"diff")
git status -s
git diff -p
;;
"revert")
echo "Not implemented"
;;
"log")
echo "Last changes:"
git log --pretty=format:' * %cr: %s' | head -3
;;
*)
2021-12-07 22:32:34 +01:00
echo "commit (save snapshot of the current state)"
2021-12-06 15:01:12 +01:00
echo "track (add a file or folder to git)"
echo "diff (show unpushed changes)"
2021-12-06 15:04:28 +01:00
echo "log (show last commits)"
2021-12-06 15:01:12 +01:00
;;
esac