| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #!/bin/bash
- # Basic options
- # Branch to save in
- branch=work
- # Remote to upload to
- remote=origin
- error() {
- echo $1
- exit 1
- }
- # Name of current branch
- cb=$(git rev-parse --abbrev-ref HEAD)
- # Check if correct branch
- [[ $branch == $cb ]] || error "Working on incorrect branch \"$cb\"!"
- # Check if there's anything to commit
- if [ -z "$(git status --porcelain)" ]; then
- error "Nothing to save!"
- fi
- # Name of last commit
- last=$(git log -1 --pretty=%s)
- # Check if last commit name is valid
- # Structure must be "commit###" where # is number
- [[ ${#last} -eq 9 ]] || error "Incorrect last commit name length \"$last\"!"
- [[ ${last:0:6} == "commit" ]] || error "Incorrect last commit name \"$last\"!"
- # Last commit number, also remove leading zeros
- lcn=${last:6:9} | sed 's/^0*//'
- # Check if integer
- [[ $lcn =~ ^-?[0-9]+$ ]] || error "Incorrect last commit number \"$last\"!"
- # New commit number
- printf -v ncn "%03d" $(($lcn + 1))
- git add .
- git commit -m "commit$ncn"
- git push $remote $branch
- echo "Work saved!"
|