diff options
| author | Karel Kočí <karel.koci@nic.cz> | 2018-11-29 13:21:09 +0100 | 
|---|---|---|
| committer | Karel Kočí <karel.koci@nic.cz> | 2018-11-29 13:21:09 +0100 | 
| commit | 001e4f345bb8e267844f0eb7dafcbd824a3832f2 (patch) | |
| tree | 126b576f1ea415a85bc7b91f5a1ced91785deac3 | |
| parent | 4d70d5f316dc3721d36bd1f7c63247e56b667b20 (diff) | |
| download | shellrc-001e4f345bb8e267844f0eb7dafcbd824a3832f2.tar.gz shellrc-001e4f345bb8e267844f0eb7dafcbd824a3832f2.tar.bz2 shellrc-001e4f345bb8e267844f0eb7dafcbd824a3832f2.zip | |
git: Add gitbcheckout
| -rw-r--r-- | bash-completion/gitbcheckout | 14 | ||||
| -rw-r--r-- | bash-completion/gitbmerge | 27 | ||||
| -rw-r--r-- | shellrc.d/git | 15 | ||||
| -rw-r--r-- | zsh-completion/_gitbcheckout | 16 | ||||
| -rw-r--r-- | zsh-completion/_gitbmerge | 20 | 
5 files changed, 58 insertions, 34 deletions
| diff --git a/bash-completion/gitbcheckout b/bash-completion/gitbcheckout new file mode 100644 index 0000000..a3c1d8e --- /dev/null +++ b/bash-completion/gitbcheckout @@ -0,0 +1,14 @@ +_gitbcheckout() { +	[ "$COMP_CWORD" -gt 1 ] &&  return # Complete only single branch +	local cur prev words cword +	_init_completion || return +	local gdir branch +	gdir="$(git rev-parse --git-common-dir 2>/dev/null)" || return +	local branches=() +	# TODO ignore current HEAD (merging HEAD to HEAD does not makes sense) +	while read -r branch; do +		branches+=("$branch") +	done < <(find "$gdir/refs/heads" "$gdir/refs/remotes" -mindepth 1 -printf '%P\n') +	COMPREPLY=($(compgen -W "${branches[*]}" -- ${cur})) +} +complete -F _gitbcheckout gitbcheckout diff --git a/bash-completion/gitbmerge b/bash-completion/gitbmerge index 8706fc8..33e8ed0 100644 --- a/bash-completion/gitbmerge +++ b/bash-completion/gitbmerge @@ -1,21 +1,14 @@  _gitbmerge() { -	local cur prev +	[ "$COMP_CWORD" -gt 1 ] &&  return # Complete only single branch +	local cur prev words cword  	_init_completion || return -	[ $COMP_CWORD -gt 1 ] &&  return # Complete only single dependency -	COMPREPLY=() -	local GDIR="$(pwd)" -	while [ ! -d "$GDIR/.git"  ]; do -		[ -z "$GDIR" ] && return -		GDIR="${GDIR%/*}" -	done -	GDIR="$GDIR/.git" -	[ -f "$GDIR" ] && GDIR="$(cat "$GDIR")" # This just points to some other directory -	[ -d "$GDIR/refs/heads" ] || return # No completion if there is no local branch -	local ops="" -	for B in "$GDIR"/refs/heads/*; do -		# TODO skip branch on HEAD -		ops="$ops ${B#$GDIR/refs/heads/}" -	done -	COMPREPLY+=($(compgen -W "${ops}" -- ${cur})) +	local gdir branch +	gdir="$(git rev-parse --git-common-dir 2>/dev/null)" || return +	local branches=() +	# TODO ignore current HEAD (merging HEAD to HEAD does not makes sense) +	while read -r branch; do +		branches+=("$branch") +	done < <(find "$gdir/refs/heads" -mindepth 1 -printf '%P\n') +	COMPREPLY=($(compgen -W "${branches[*]}" -- ${cur}))  }  complete -F _gitbmerge gitbmerge diff --git a/shellrc.d/git b/shellrc.d/git index 47edae5..1403ea4 100644 --- a/shellrc.d/git +++ b/shellrc.d/git @@ -19,11 +19,18 @@ gitbmerge() {  	)  } +# Checkout branch to new work tree +gitbcheckout() { +	local nw +	nw="$(git rev-parse --show-toplevel)-$1" +	git worktree add "$nw" "$1" +	cd "$nw" +	git submodule update --init --recursive +} +alias gitbco='gitcheckout' +  # Create new branch from HEAD  gitbnew() {  	git branch "$1" HEAD -	local NW="$(git rev-parse --show-toplevel)-$1" -	git worktree add "$NW" $1 -	cd "$NW" -	git submodule update --init --recursive +	gitbcheckout "$1"  } diff --git a/zsh-completion/_gitbcheckout b/zsh-completion/_gitbcheckout new file mode 100644 index 0000000..050457d --- /dev/null +++ b/zsh-completion/_gitbcheckout @@ -0,0 +1,16 @@ +#compdef gitbmerge +#autoload + +_gitbcheckout() { +	((CURRENT > 2)) &&  return # Complete only single branch +	local gdir branch +	gdir="$(git rev-parse --git-common-dir 2>/dev/null)" || return +	local branches=() +	while read -r branch; do +		branches+=("$branch") +	done < <(find "$gdir/refs/heads" "$gdir/refs/remotes" -mindepth 1 -printf '%P\n') +	_describe -t branches 'gitbcheckout' branches +} + +_gitbcheckout +# vim: ft=zsh diff --git a/zsh-completion/_gitbmerge b/zsh-completion/_gitbmerge index 733dbfb..0b598a0 100644 --- a/zsh-completion/_gitbmerge +++ b/zsh-completion/_gitbmerge @@ -2,20 +2,14 @@  #autoload  _gitbmerge() { -	(( CURRENT > 2)) &&  return # Complete only single dependency -	local GDIR="$(pwd)" -	while [ ! -d "$GDIR/.git"  ]; do -		[ -z "$GDIR" ] && return -		GDIR="${GDIR%/*}" -	done -	GDIR="$GDIR/.git" -	[ -f "$GDIR" ] && GDIR="$(cat "$GDIR")" # This just points to some other directory -	[ -d "$GDIR/refs/heads" ] || return # No completion if there is no local branch +	((CURRENT > 2)) &&  return # Complete only single branch +	local gdir branch +	gdir="$(git rev-parse --git-common-dir 2>/dev/null)" || return  	local branches=() -	for B in "$GDIR"/refs/heads/*; do -		# TODO skip branch on HEAD -		branches+=("${B#$GDIR/refs/heads/}") -	done +	# TODO ignore current HEAD (merging HEAD to HEAD does not makes sense) +	while read -r branch; do +		branches+=("$branch") +	done < <(find "$gdir/refs/heads" -mindepth 1 -printf '%P\n')  	_describe -t branches 'gitbmerge' branches  } | 
