Added tab completion
This commit is contained in:
parent
26145b88a7
commit
2d51867efd
3 changed files with 53 additions and 5 deletions
10
README.md
10
README.md
|
|
@ -28,7 +28,7 @@ get reset %FILES% | git checkout %FILES%
|
||||||
get commit %MESSAGE% | git commit -m %MESSAGE%
|
get commit %MESSAGE% | git commit -m %MESSAGE%
|
||||||
get branch %BRANCH% | stashes working tree, creates or switches branch, and checks out branch
|
get branch %BRANCH% | stashes working tree, creates or switches branch, and checks out branch
|
||||||
get rmbranch %BRANCH% | git branch -d %BRANCH% *TODO: rename?*
|
get rmbranch %BRANCH% | git branch -d %BRANCH% *TODO: rename?*
|
||||||
get update | Fetches all remote branches and fast-forwards all local branches
|
get fetch | Fetches all remotes and fast-forwards local branches when possible
|
||||||
get status | git status
|
get status | git status
|
||||||
get review | git diff --cached
|
get review | git diff --cached
|
||||||
get diff | compare working tree with HEAD (git diff HEAD)
|
get diff | compare working tree with HEAD (git diff HEAD)
|
||||||
|
|
@ -37,5 +37,11 @@ get diff %REF% | compare working tree with %REF% (git diff %REF%)
|
||||||
get diff STAGE %REF% | compare stage with %REF% (git diff --cached %REF%)
|
get diff STAGE %REF% | compare stage with %REF% (git diff --cached %REF%)
|
||||||
get diff %REFA% %REFB% | compare %REFA% with %REFB% (git diff %REFA% %REFB%)
|
get diff %REFA% %REFB% | compare %REFA% with %REFB% (git diff %REFA% %REFB%)
|
||||||
|
|
||||||
|
### TODO
|
||||||
|
Now that I've added tab completion, I think "stage" and "status" are too similar.
|
||||||
|
Also, I have three commands that start with "r" which is a problem.
|
||||||
|
|
||||||
|
### Changelog
|
||||||
|
- I renamed "update" to "fetch" to avoid completion conflicts with "unstage".
|
||||||
|
Also, it really is just fetch + fast-forward. One of my goals is NOT to use
|
||||||
|
different terminology than git, because that makes StackOverflow less useful.
|
||||||
|
|
|
||||||
38
bash_completion
Normal file
38
bash_completion
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
#!/bin/bash
|
||||||
|
list_branches() {
|
||||||
|
git for-each-ref refs/heads --format="%(refname:short)"
|
||||||
|
}
|
||||||
|
|
||||||
|
_get_complete()
|
||||||
|
{
|
||||||
|
# Available variables:
|
||||||
|
# COMP_LINE COMP_POINT COMP_KEY COMP_TYPE COMP_WORDS COMP_CWORD
|
||||||
|
# $1 : name of command whose arguments are being completed
|
||||||
|
# $2 : the word being completed
|
||||||
|
# $3 : the word preceding the word being completed
|
||||||
|
case ${COMP_CWORD} in
|
||||||
|
1)
|
||||||
|
commands="branch commit diff fetch ignore reset rmbranch review stage status unstage"
|
||||||
|
COMPREPLY=( $(compgen -W "${commands}" "$2") )
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
case "$3" in
|
||||||
|
branch | rmbranch | fetch)
|
||||||
|
commands=$(list_branches)
|
||||||
|
COMPREPLY=( $(compgen -W "${commands}" "$2") )
|
||||||
|
;;
|
||||||
|
stage | unstage | ignore)
|
||||||
|
COMPREPLY=( $(compgen -A file -X .git "$2") )
|
||||||
|
;;
|
||||||
|
diff)
|
||||||
|
commands="STAGE"
|
||||||
|
COMPREPLY=( $(compgen -A file -X .git -W "${commands}" "$2") )
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
COMPREPLY=()
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
complete -F _get_complete get
|
||||||
8
get
8
get
|
|
@ -10,7 +10,11 @@ list_branches() {
|
||||||
list_remote_branches() {
|
list_remote_branches() {
|
||||||
git for-each-ref refs/heads --format="%(refname:short)"
|
git for-each-ref refs/heads --format="%(refname:short)"
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
"")
|
||||||
|
echo 'TODO: Display help, or git status if inside a repo'
|
||||||
|
;;
|
||||||
|
|
||||||
stage)
|
stage)
|
||||||
if [ -z "$2" ]; then
|
if [ -z "$2" ]; then
|
||||||
|
|
@ -76,7 +80,7 @@ else
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
update)
|
fetch)
|
||||||
echo Updating
|
echo Updating
|
||||||
if [ -z "$2" ]; then
|
if [ -z "$2" ]; then
|
||||||
git fetch --all
|
git fetch --all
|
||||||
|
|
@ -108,12 +112,12 @@ status)
|
||||||
# TODO: figure out how to git config --global color.status always automatically.
|
# TODO: figure out how to git config --global color.status always automatically.
|
||||||
git status \
|
git status \
|
||||||
| grep -v '# On branch' \
|
| grep -v '# On branch' \
|
||||||
|
| grep -v '# (use "git push" to publish your local commits)' \
|
||||||
| grep -v '# (use "git reset HEAD <file>..." to unstage)' \
|
| grep -v '# (use "git reset HEAD <file>..." to unstage)' \
|
||||||
| grep -v '# (use "git add <file>..." to update what will be committed)' \
|
| grep -v '# (use "git add <file>..." to update what will be committed)' \
|
||||||
| grep -v '# (use "git checkout -- <file>..." to discard changes in working directory)' \
|
| grep -v '# (use "git checkout -- <file>..." to discard changes in working directory)' \
|
||||||
| grep -v '# (use "git add <file>..." to include in what will be committed)' \
|
| grep -v '# (use "git add <file>..." to include in what will be committed)' \
|
||||||
| grep -v 'nothing added to commit but untracked files present (use "git add" to track)'
|
| grep -v 'nothing added to commit but untracked files present (use "git add" to track)'
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
diff)
|
diff)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue