zsh: Move 'change directory into repo root' logic
Add an alias that switches directories into the repository root, instead of having the normal `cd` command behave like that. Sadly this is not possible (AFAIK) with a git alias as that will always spawn a subshell.
This commit is contained in:
@@ -60,6 +60,7 @@ fi
|
|||||||
alias ga='git add'
|
alias ga='git add'
|
||||||
alias gap='git add -p'
|
alias gap='git add -p'
|
||||||
alias gc='git commit'
|
alias gc='git commit'
|
||||||
|
alias gcd='cd "$(git rev-parse --show-toplevel)"'
|
||||||
alias gch='git checkout'
|
alias gch='git checkout'
|
||||||
alias gd='git diff'
|
alias gd='git diff'
|
||||||
alias gds='git diff --staged'
|
alias gds='git diff --staged'
|
||||||
|
|||||||
@@ -359,10 +359,9 @@ mvln() {
|
|||||||
return $reg
|
return $reg
|
||||||
}
|
}
|
||||||
|
|
||||||
## cd wrapper that when called without arguments, moves into the root of the
|
## cd-wrapper that recognizes a trailing `ls` behind the path (When not properly
|
||||||
## current repo instead of HOME. (Except when already there)
|
## pressing <CR>)
|
||||||
cd() {
|
cd() {
|
||||||
if [[ $# -gt 0 ]]; then
|
|
||||||
# Call `ls` on paths that end on '/ls' and don't exist with the suffix.
|
# Call `ls` on paths that end on '/ls' and don't exist with the suffix.
|
||||||
# (When not properly pressing <CR>)
|
# (When not properly pressing <CR>)
|
||||||
if [[ ! -e ${@[-1]} && -e ${@[-1]%%/ls} ]]; then
|
if [[ ! -e ${@[-1]} && -e ${@[-1]%%/ls} ]]; then
|
||||||
@@ -372,16 +371,6 @@ cd() {
|
|||||||
else
|
else
|
||||||
builtin cd "$@"
|
builtin cd "$@"
|
||||||
fi
|
fi
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
local toplevel
|
|
||||||
toplevel="$(git rev-parse --show-toplevel 2>/dev/null)"
|
|
||||||
if (( $? )) || [[ $PWD = $toplevel ]]; then
|
|
||||||
builtin cd
|
|
||||||
else
|
|
||||||
builtin cd "$toplevel"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Commit, but put the last written commit message into the editor buffer.
|
# Commit, but put the last written commit message into the editor buffer.
|
||||||
|
|||||||
Reference in New Issue
Block a user