1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/bin/bash
-
- #
- # Edit URL of remote $1 using vipe(1)
- #
-
- warn() {
- echo "$@" >&2
- }
-
- die() {
- warn "$@"
- exit 3
- }
-
- usage() {
- warn "usage: git $(basename "$0") [-v|--verbose] REMOTE"
- exit 2
- }
-
- think() {
- $verbose && echo "$@"
- }
-
- main() {
- local remote
- local oldurl
- local newurl
- local verbose=false
- while true; do case $1 in
- -v|--verbose) verbose=true; shift ;;
- -*) usage ;;
- *) break ;;
- esac done
- remote="$1"
- test -n "$remote" || usage
- command -v vipe >/dev/null \
- || die "need vipe(1) from moreutils"
- think "remote='$remote'"
- oldurl=$(git remote get-url "$remote") \
- || die "failed to get old URL"
- test "$newurl" == "$oldurl" && {
- warn "URL was not changed"
- return 1
- }
- think "oldurl='$oldurl'"
- think "EDITOR='$EDITOR'"
- think "VISUAL='$VISUAL'"
- newurl=$(vipe <<<"$oldurl") \
- || die "failed to edit URL (is vipe installed?)"
- think "newurl='$newurl'"
- git remote set-url "$remote" "$newurl" \
- || die "failed to set new remote URL"
- }
-
- main "$@"
|