terom@605: #!/bin/bash terom@605: # terom@605: # HG wrappers terom@605: terom@605: ## Run `hg ...` within $REPO. terom@605: function hg { terom@612: local repo=$1; shift terom@612: cmd $HG -R "$repo" "${HG_ARGS[@]}" "$@" terom@605: } terom@605: terom@605: ## Does the repo have local modifications? terom@605: function hg_modified { terom@612: hg $1 id | grep -q '+' terom@605: } terom@605: terom@605: ## Output possible -u flag for commit. terom@605: function hg_user { terom@605: if [ ${SUDO_USER:-} ]; then terom@605: echo '-u' "$SUDO_USER" terom@605: terom@605: elif [ $HOME ] && [ -e $HOME/.hgrc ]; then terom@605: debug "using .hgrc user" terom@605: echo '' terom@605: terom@605: else terom@605: echo '-u' "$USER" terom@605: fi terom@605: } terom@605: terom@605: ## Show changes in repo terom@605: # hg_diff [path ...] terom@605: function hg_diff { terom@612: local repo=$1; shift terom@612: hg $repo diff "$@" terom@605: } terom@605: terom@605: ## Commit changes in repo, with given message: terom@605: # terom@605: # hg_commit $msg terom@605: # terom@605: # Automatically determines possible -u to use when running with sudo. terom@605: function hg_commit { terom@612: local repo=$1 terom@612: local msg=$2 terom@605: local user_opt=$(hg_user) terom@605: local msg_opt= terom@605: terom@605: [ $msg ] && msg_opt=('-m' "$msg") terom@605: terom@605: debug "$user_opt: $msg" terom@612: hg $repo commit ${user_opt[@]} ${msg_opt[@]} terom@605: }