Refactor vcs aliases / functions
This commit is contained in:
parent
2282d01a7d
commit
d8e96bf4c6
73
aliases/git
73
aliases/git
|
@ -1,49 +1,58 @@
|
||||||
#!/bin/zsh
|
#!/bin/zsh
|
||||||
ginit() {
|
ginit() {
|
||||||
git init;
|
git init;
|
||||||
git add ${*:-"."};
|
git add ${*:-"."};
|
||||||
git commit -a -m "Initial Commit"
|
git commit -a -m "Initial Commit"
|
||||||
}
|
}
|
||||||
|
|
||||||
gst() {
|
# define a function that calls different versioning systems depending on
|
||||||
if [[ "${vcs_info_msg_0_[2,3]}" == 'hg' ]]; then
|
# detected vcs for current directory
|
||||||
hg status "$@"
|
# usage: defvcsfun <command name> <parameters for git> <parameters for hg> <parameters for svn>
|
||||||
else
|
# see below for examples
|
||||||
git status "$@"
|
defvcsfun() {
|
||||||
fi
|
local name=$1; shift
|
||||||
|
local args=($@)
|
||||||
|
eval "$name() {
|
||||||
|
case \$VCS_DETECTED in
|
||||||
|
git)
|
||||||
|
git ${=args[1]} \"\$@\";;
|
||||||
|
hg)
|
||||||
|
hg ${=args[2]} \"\$@\";;
|
||||||
|
svn)
|
||||||
|
svn ${=args[3]} \"\$@\";;
|
||||||
|
*)
|
||||||
|
echo \"unknown vcs: \$VCS_DETECTED\";;
|
||||||
|
esac
|
||||||
|
}"
|
||||||
}
|
}
|
||||||
|
|
||||||
gpl() {
|
#VCS command git hg svn
|
||||||
if [[ "${vcs_info_msg_0_[2,3]}" == 'hg' ]]; then
|
defvcsfun gst "status -s" "status" "status"
|
||||||
hg pull "$@"
|
defvcsfun gpl "pull" "pull" "update"
|
||||||
else
|
defvcsfun gcm "commit" "commit" "commit"
|
||||||
git pull "$@"
|
defvcsfun ga "add" "add" "add"
|
||||||
fi
|
defvcsfun gpu "push" "push" "i_am_not_distributed_please_dont_push_me"
|
||||||
}
|
|
||||||
|
|
||||||
alias gca="git commit -a"
|
|
||||||
alias gcm="git commit"
|
|
||||||
alias gco="git checkout"
|
alias gco="git checkout"
|
||||||
alias ga="git add"
|
alias gca="git commit -a"
|
||||||
alias gap="git add --patch"
|
alias gap="git add --patch"
|
||||||
alias gpu="git push"
|
|
||||||
|
|
||||||
|
|
||||||
gls() {
|
gls() {
|
||||||
zmodload zsh/mapfile
|
zmodload zsh/mapfile
|
||||||
gitignore="$(git rev-parse --show-toplevel 2>/dev/null)/.gitignore"
|
gitignore="$(git rev-parse --show-toplevel 2>/dev/null)/.gitignore"
|
||||||
globalgitignore="$(git config core.excludesfile)"
|
globalgitignore="$(git config core.excludesfile)"
|
||||||
|
|
||||||
typeset -a ignores
|
typeset -a ignores
|
||||||
for i in $gitignore $globalgitignore; do
|
for i in $gitignore $globalgitignore; do
|
||||||
if [[ -e $i ]]; then
|
if [[ -e $i ]]; then
|
||||||
for ignore in "${(f)mapfile[$i]}"; do
|
for ignore in "${(f)mapfile[$i]}"; do
|
||||||
ignores+="--ignore=$ignore"
|
ignores+="--ignore=$ignore"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
ls --color=auto -h $ignores "$@"
|
ls --color=auto -h $ignores "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
alias gll="gls -l"
|
alias gll="gls -l"
|
||||||
|
|
Loading…
Reference in a new issue