aboutsummaryrefslogblamecommitdiffstatshomepage
path: root/.bashrc_git
blob: 9de238bde2543ee25d4b38ceaf69fb1906494a92 (plain) (tree)
1
2

                                                             













































                                                                 
[ ! -z "${BASHRC_GIT+x}" ] && return || readonly BASHRC_GIT=1

alias list_repo_files='git ls-files -z'

list_repo_dirs() (
  set -o errexit

  { printf '.\0' ; list_repo_files ; } \
    | xargs -0 dirname -z \
    | sort -z \
    | uniq -z \
    | tail -z -n +2
)

tighten_repo_security() (
  set -o errexit

  list_repo_files | xargs -0 chmod 0600
  list_repo_dirs | xargs -0 chmod 0700
  chmod 0700 .git
)

backup_repo() (
  set -o errexit

  local repo_dir="$( realpath . )"
  local repo_name="$( basename "$repo_dir" )"
  local backup_dir="$repo_dir"

  if [ $# -eq 1 ]; then
    backup_dir="$1"
  elif [ $# -gt 1 ]; then
    echo "$FUNCNAME: usage: $FUNCNAME [BACKUP_DIR]" >&2
    exit 1
  fi

  local zip_name="${repo_name}_$( date -u +'%Y%m%dT%H%M%S' ).zip"

  git archive \
    --format=zip -9 \
    --output="$backup_dir/$zip_name" \
    --remote="$repo_dir" \
    HEAD
)

backup_repo_dropbox() {
  backup_repo "$USERPROFILE/Dropbox/backups"
}