Wrap everything in a git function so that zsh can expand any aliases for tab completion
This commit is contained in:
@@ -310,21 +310,28 @@ These aliases also come with tab completion. For example, you can type `gco <tab
|
|||||||
|
|
||||||
### 2) Use your own aliases
|
### 2) Use your own aliases
|
||||||
|
|
||||||
Make sure your git aliases are being defined before you load SCM Breeze.
|
In your `git.scmbrc` config file, just set the `git_setup_aliases` option to `no`.
|
||||||
Then, in the `git.scmbrc` config file, just set the `git_augment_current_aliases` option to `yes`.
|
Your existing git aliases will then be used, and you will still be able to use the numeric shortcuts feature.
|
||||||
Your existing git aliases will then be parsed and wrapped with a SCM Breeze function wrapper, so that you can
|
SCM Breeze creates a function to wrap the 'git' command, which expands numeric arguments, and uses `hub` if available.
|
||||||
use the numeric shortcuts feature.
|
|
||||||
|
|
||||||
A few aliases will still be defined for the central SCM Breeze features, such as `gs` for the extended `git status`,
|
A few aliases will still be defined for the central SCM Breeze features, such as `gs` for the extended `git status`,
|
||||||
and `ga` for the `git add` function.
|
and `ga` for the `git add` function.
|
||||||
|
|
||||||
For example, if you already have an alias like `alias gco="git checkout"`,
|
If you already have an alias like `alias gco="git checkout"`,
|
||||||
then SCM Breeze will automatically redefine it to `alias gco="exec_git_expand_args git checkout"`.
|
you can now type `gco 1` to checkout the first file in the output of SCM Breeze's `git status`.
|
||||||
This means you can type `gco 1` to checkout the first file in the output of SCM Breeze's `git status`.
|
|
||||||
|
|
||||||
Note: If you wrap your own aliases, SCM Breeze will **not** set up tab completion for your aliases.
|
# Notes about Tab Completion for Aliases
|
||||||
|
|
||||||
|
### Bash
|
||||||
|
|
||||||
|
If you wrap your own aliases, SCM Breeze will **not** set up bash tab completion for your aliases.
|
||||||
You will need to set that up yourself.
|
You will need to set that up yourself.
|
||||||
|
|
||||||
|
### Zsh
|
||||||
|
|
||||||
|
You just need to set `setopt no_complete_aliases`, and zsh will expand aliases like `gb` to `git branch`
|
||||||
|
and use the completion for that.
|
||||||
|
|
||||||
|
|
||||||
# Updating
|
# Updating
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ export gs_max_changes="150"
|
|||||||
# - When using the git_add_shorcuts() command, automatically invoke 'git rm' to remove deleted files?
|
# - When using the git_add_shorcuts() command, automatically invoke 'git rm' to remove deleted files?
|
||||||
export ga_auto_remove="yes"
|
export ga_auto_remove="yes"
|
||||||
|
|
||||||
# - Set the following option to 'yes' if you want to augment your existing git aliases,
|
# - Set the following option to 'no' if you want to use your existing git aliases
|
||||||
# instead of overwriting them.
|
# instead of overwriting them.
|
||||||
# Note: Bash tab completion will not be automatically set up for your aliases if you choose this option.
|
# Note: Bash tab completion will not be automatically set up for your aliases if you disable this option.
|
||||||
export git_augment_current_aliases="no"
|
export git_setup_aliases="yes"
|
||||||
|
|
||||||
|
|
||||||
# Git Index Config
|
# Git Index Config
|
||||||
|
|||||||
@@ -9,7 +9,13 @@ alias git_aliases="list_aliases git"
|
|||||||
|
|
||||||
# Wrap git with the 'hub' github wrapper, if installed
|
# Wrap git with the 'hub' github wrapper, if installed
|
||||||
# https://github.com/defunkt/hub
|
# https://github.com/defunkt/hub
|
||||||
if type hub > /dev/null 2>&1; then alias git=hub; fi
|
_git_cmd=git;
|
||||||
|
if type hub > /dev/null 2>&1; then _git_cmd=hub; fi
|
||||||
|
|
||||||
|
# Create 'git' function that calls hub if defined, and expands all numeric arguments
|
||||||
|
function git(){
|
||||||
|
exec_git_expand_args "$_git_cmd" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
_alias $git_alias='git'
|
_alias $git_alias='git'
|
||||||
|
|
||||||
@@ -58,24 +64,23 @@ _alias $git_commit_all_alias='git_commit_all'
|
|||||||
# Git Index alias
|
# Git Index alias
|
||||||
_alias $git_index_alias="git_index"
|
_alias $git_index_alias="git_index"
|
||||||
|
|
||||||
# Only set up aliases if git_augment_current_aliases is not 'yes'
|
# Only set up the following aliases if 'git_setup_aliases' is 'yes'
|
||||||
if [ "$git_augment_current_aliases" != "yes" ]; then
|
if [ "$git_setup_aliases" = "yes" ]; then
|
||||||
|
|
||||||
# Expand numbers and ranges for commands that deal with paths
|
# Commands that deal with paths
|
||||||
_exp="exec_git_expand_args"
|
__git_alias "$git_checkout_alias" "git" "checkout"
|
||||||
__git_alias "$git_checkout_alias" "$_exp git" "checkout"
|
__git_alias "$git_commit_alias" "git" "commit"
|
||||||
__git_alias "$git_commit_alias" "$_exp git" "commit"
|
__git_alias "$git_reset_alias" "git" "reset"
|
||||||
__git_alias "$git_reset_alias" "$_exp git" "reset"
|
__git_alias "$git_reset_del_alias" "git" "reset" "--"
|
||||||
__git_alias "$git_reset_del_alias" "$_exp git" "reset" "--"
|
__git_alias "$git_reset_hard_alias" "git" "reset" "--hard"
|
||||||
__git_alias "$git_reset_hard_alias" "$_exp git" "reset" "--hard"
|
__git_alias "$git_rm_alias" "git" "rm"
|
||||||
__git_alias "$git_rm_alias" "$_exp git" "rm"
|
__git_alias "$git_blame_alias" "git" "blame"
|
||||||
__git_alias "$git_blame_alias" "$_exp git" "blame"
|
__git_alias "$git_diff_alias" "git" "diff"
|
||||||
__git_alias "$git_diff_alias" "$_exp git" "diff"
|
__git_alias "$git_diff_cached_alias" "git" "diff" "--cached"
|
||||||
__git_alias "$git_diff_cached_alias" "$_exp git" "diff" "--cached"
|
__git_alias "$git_add_patch_alias" "git" "add" "-p"
|
||||||
__git_alias "$git_add_patch_alias" "$_exp git" "add" "-p"
|
|
||||||
# Custom default format for git log
|
# Custom default format for git log
|
||||||
git_log_command="log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
|
git_log_command="log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
|
||||||
__git_alias "$git_log_alias" "$_exp git" "$git_log_command"
|
__git_alias "$git_log_alias" "git" "$git_log_command"
|
||||||
|
|
||||||
# Standard commands
|
# Standard commands
|
||||||
__git_alias "$git_clone_alias" "git" 'clone'
|
__git_alias "$git_clone_alias" "git" 'clone'
|
||||||
@@ -109,18 +114,6 @@ if [ "$git_augment_current_aliases" != "yes" ]; then
|
|||||||
_alias $git_log_graph_alias='git log --graph --max-count=5'
|
_alias $git_log_graph_alias='git log --graph --max-count=5'
|
||||||
_alias $git_add_all_alias='git add -A'
|
_alias $git_add_all_alias='git add -A'
|
||||||
_alias $git_branch_all_alias='git branch -a'
|
_alias $git_branch_all_alias='git branch -a'
|
||||||
|
|
||||||
# Otherwise, wrap any existing git aliases with 'exec_git_expand_args'
|
|
||||||
else
|
|
||||||
OLDIFS="$IFS"; IFS=$'\n'
|
|
||||||
for git_alias in $(alias | grep "git " --color=never); do
|
|
||||||
# Set up the new alias if not already wrapped with exec_git_expand_args
|
|
||||||
if [[ "$git_alias" != *exec_git_expand_args* ]]; then
|
|
||||||
new_alias=$(echo -n "$git_alias" | sed -e 's/git /exec_git_expand_args git /g')
|
|
||||||
eval "$new_alias"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
IFS="$OLDIFS"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ git_expand_args() {
|
|||||||
|
|
||||||
# Execute a command with expanded args, e.g. Delete files 6 to 12: $ ge rm 6-12
|
# Execute a command with expanded args, e.g. Delete files 6 to 12: $ ge rm 6-12
|
||||||
# Fails if command is a number or range (probably not worth fixing)
|
# Fails if command is a number or range (probably not worth fixing)
|
||||||
exec_git_expand_args() { eval "$(git_expand_args "$@" | sed -e 's/\([][()<> ]\)/\\\1/g')"; }
|
exec_git_expand_args() { eval "$(git_expand_args "$@" | sed -e 's/\([][()<>^ ]\)/\\\1/g')"; }
|
||||||
|
|
||||||
# Clear numbered env variables
|
# Clear numbered env variables
|
||||||
git_clear_vars() {
|
git_clear_vars() {
|
||||||
|
|||||||
Reference in New Issue
Block a user