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