Browse Source

Add remote-edit script and alias for it

Alois Mahdal 5 years ago
parent
commit
fb319630d0
2 changed files with 49 additions and 0 deletions
  1. 48
    0
      dotfiles/gittum/bin/remote-edit
  2. 1
    0
      dotfiles/gittum/main.gitconfig

+ 48
- 0
dotfiles/gittum/bin/remote-edit View File

@@ -0,0 +1,48 @@
1
+#!/bin/bash
2
+
3
+#
4
+# Edit URL of remote $1 using vipe(1)
5
+#
6
+
7
+die() {
8
+    echo "$@" 1>&2
9
+    exit 1
10
+}
11
+
12
+usage() {
13
+    echo "usage: git $(basename "$0") [-v|--verbose] REMOTE"
14
+    exit 0
15
+}
16
+
17
+think() {
18
+    $verbose && echo "$@"
19
+}
20
+
21
+main() {
22
+    local remote
23
+    local oldurl
24
+    local newurl
25
+    local verbose=false
26
+    while true; do case $1 in
27
+        -v|--verbose) verbose=true; shift ;;
28
+        -*) usage ;;
29
+        *)  break ;;
30
+    esac done
31
+    remote="$1"
32
+    test -n "$remote" || usage
33
+    command -v vipe >/dev/null \
34
+     || die "need vipe(1) from moreutils"
35
+    think "remote='$remote'"
36
+    oldurl=$(git remote get-url "$remote") \
37
+     || die "failed to get old URL"
38
+    think "oldurl='$oldurl'"
39
+    think "EDITOR='$EDITOR'"
40
+    think "VISUAL='$VISUAL'"
41
+    newurl=$(vipe <<<"$oldurl") \
42
+     || die "failed to edit URL (is vipe installed?)"
43
+    think "newurl='$newurl'"
44
+    git remote set-url "$remote" "$newurl" \
45
+     || die "failed to set new remote URL"
46
+}
47
+
48
+main "$@"

+ 1
- 0
dotfiles/gittum/main.gitconfig View File

@@ -32,6 +32,7 @@
32 32
   rb = rebase
33 33
   rbc = rebase --continue
34 34
   rbi = rebase --interactive
35
+  rme = ! ~/.gittum/bin/remote-edit
35 36
   rmv = remote --verbose
36 37
   sibling = ! ~/.gittum/bin/sibling
37 38
   slurp = ! ~/.gittum/bin/slurp