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"
}
# 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"
usage
fi
- tmpfile=`mktemp`
+ local tmpfile=`mktemp`
if [[ -n "$TEMPLATE" ]]; then
if [[ -r "$TEMPLATE" ]]; then
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
}
edit() {
- tmpfile=`mktemp`
+ local tmpfile=`mktemp`
log_info "editing $1 using $tmpfile"
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"
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"
--- /dev/null
+# 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)]}"
+}
+
+