Created
March 13, 2017 12:57
-
-
Save jan-matejka/f605465eb1bef82bc08917c8c0b78391 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env zsh | |
| function latest_backup_id() { | |
| local branch="${1}" | |
| [[ "${branch}" == "" ]] && return 1 | |
| local prefix="${b}.backup" | |
| git branch --list --color=never "${prefix}*" \ | |
| | sed "s/^..${prefix}//" \ | |
| | sort -nr \ | |
| | head -n1 \ | |
| } | |
| function new_backup_id() { | |
| local branch="${1}" | |
| latest=$(latest_backup_id "${branch}") || return 1 | |
| echo $(( $latest + 1 )) | |
| } | |
| main() { | |
| local b id | |
| b=$(git rev-parse --abbrev-ref HEAD) || return 1 | |
| id=$(new_backup_id "${b}") || return 1 | |
| git checkout -b "${b}.backup${id}" || return 1 | |
| git checkout "${b}" || return 1 | |
| } | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment