]> infiniteadaptability.org Git - git-extra/commitdiff
minor updates v1.0.0
authoralex <[email protected]>
Thu, 23 Sep 2021 03:32:12 +0000 (20:32 -0700)
committeralex <[email protected]>
Thu, 23 Sep 2021 07:12:32 +0000 (00:12 -0700)
added support for bash completion
cosmetic improvements to git-extra

Makefile
git-extra
git-extra.bash-completion [new file with mode: 0644]

index c36ab6c076e701ff3947a6d6aff38331a8c9c60c..51dc802688305d9a5ba2d0de8d106e8b41c09059 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,9 @@
 PREFIX ?= /usr/local
 BINDIR ?= $(PREFIX)/bin
 
+BASHCOMPPREFIX ?= /usr
+BASHCOMPDIR ?= $(BASHCOMPPREFIX)/share/bash-completion/completions
+
 all:
        @echo "git-extra is a shell script; nothing to make. Try 'make install' instead."
 
@@ -13,6 +16,7 @@ clean:
 
 install:
        @install -v -d "$(BINDIR)/" && install -m 0755 -v git-extra "$(BINDIR)/git-ex"
+       @install -v -d "$(BASHCOMPDIR)/" && install -m 0644 -v git-extra.bash-completion "$(BASHCOMPDIR)/git-ex"
 
 uninstall:
        @rm -vrf \
index f566e17ae5819ed1b15be732268ff13e57ecc0fd..a581b82937432d3014847dcee79f8682d2080a50 100644 (file)
--- a/git-extra
+++ b/git-extra
@@ -144,8 +144,8 @@ parse_arguments() {
 branch_create() {
        log_info "creating branch $BRANCH"
        git check-ref-format --branch "$BRANCH" > /dev/null
-       HASH=`echo "" | git mktree --batch`
-       TREE_HASH=`git commit-tree -m "init" "$HASH"`
+       local HASH=`echo "" | git mktree --batch`
+       local TREE_HASH=`git commit-tree -m "init" "$HASH"`
        git update-ref "refs/heads/$BRANCH" "$TREE_HASH"
 }
 
@@ -180,12 +180,12 @@ add_to_index() {
        # fills PREV_COMMIT with $BRANCH's previous commit hash
        branch_hash
 
-       hash=`git hash-object "$1" -w`
+       local hash=`git hash-object "$1" -w`
        rm "$1"
 
        git update-index --add --cacheinfo 100644 "$hash" "$2"
-       tree_hash=`git write-tree`
-       commit_hash=`git commit-tree -m "${MESSAGE:-updated using git-extra}" -p "$PREV_COMMIT" "$tree_hash"`
+       local tree_hash=`git write-tree`
+       local commit_hash=`git commit-tree -m "${MESSAGE:-updated using git-extra}" -p "$PREV_COMMIT" "$tree_hash"`
 
        git update-ref "refs/heads/$BRANCH" "$commit_hash"
        
@@ -205,7 +205,7 @@ add() {
                usage
        fi
 
-       tmpfile=`mktemp`
+       local tmpfile=`mktemp`
 
        if [[ -n "$TEMPLATE" ]]; then
                if [[ -r "$TEMPLATE" ]]; then
@@ -226,7 +226,7 @@ add() {
 
 cat_file() {
        branch_exists
-       HASH=`git ls-tree "$BRANCH" "$1" | awk -F ' ' '{print $3}'`
+       local HASH=`git ls-tree "$BRANCH" "$1" | awk -F ' ' '{print $3}'`
        if [[ -z "$HASH" ]]; then
                log_err "$1 doesn't exist"
                exit 1
@@ -240,7 +240,7 @@ cat_file() {
 }
 
 edit() {
-       tmpfile=`mktemp`
+       local tmpfile=`mktemp`
 
        log_info "editing $1 using $tmpfile"
 
@@ -256,7 +256,7 @@ edit() {
 editor() {
        log_info "opening temporary file '$1'"
 
-       pre_edit_hash=`b2sum $1`
+       local pre_edit_hash=`b2sum $1`
 
        if [[ -z "$EDITOR" ]]; then
                log_info "no editor found, checking git config"
@@ -269,10 +269,10 @@ editor() {
                fi
        fi
 
-       CMD=`printf "$EDITOR %s\n" "$1"`
+       local CMD=`printf "$EDITOR %s\n" "$1"`
        eval "$CMD"
 
-       post_edit_hash=`b2sum $1`
+       local post_edit_hash=`b2sum $1`
 
        if [[ "$pre_edit_hash" == "$post_edit_hash" ]]; then
                log_err "no changes detected"
diff --git a/git-extra.bash-completion b/git-extra.bash-completion
new file mode 100644 (file)
index 0000000..55c28af
--- /dev/null
@@ -0,0 +1,24 @@
+# bash completions when called as own excutable, as 'git-ex'
+_git-ex() {
+       IFS=$'\n'
+       COMPREPLY=()
+       local commands=$'add\ncat\nedit\nls'
+       case "$3" in
+               cat|edit|ls)
+                       COMPREPLY+=($(git-ex ls | grep "$2"))
+                       ;;
+               git-ex|ex)
+                       COMPREPLY+=($(compgen -W "${commands}" -- "$2"))
+                       ;;
+       esac
+}
+
+complete -F _git-ex git-ex
+
+# completions called by git's completions script
+_git_ex() {
+       compopt +o nospace
+       _git-ex "git-ex" "${COMP_WORDS[$COMP_CWORD]}" "${COMP_WORDS[($COMP_CWORD-1)]}"
+}
+
+