mirror of
https://github.com/wfxr/forgit.git
synced 2026-09-10 07:16:23 -04:00
my changed state
This commit is contained in:
parent
7a40a11e79
commit
0a5b5572b9
|
|
@ -323,7 +323,7 @@ _forgit_diff() {
|
|||
$FORGIT_FZF_DEFAULT_OPTS
|
||||
+m -0 --bind=\"enter:execute($FORGIT diff_enter {} $escaped_commits | $FORGIT pager enter)\"
|
||||
--preview=\"$FORGIT diff_view {} '$_forgit_preview_context' $escaped_commits\"
|
||||
--bind=\"alt-e:execute-silent($FORGIT edit_diffed_file {})+refresh-preview\"
|
||||
--bind=\"alt-e:execute($FORGIT edit_diffed_file {})+refresh-preview\"
|
||||
$FORGIT_DIFF_FZF_OPTS
|
||||
--prompt=\"${commits[*]} > \"
|
||||
"
|
||||
|
|
@ -348,12 +348,29 @@ _forgit_add_preview() {
|
|||
fi
|
||||
}
|
||||
|
||||
_forgit_unstage_preview() {
|
||||
file=$(echo "$1" | _forgit_get_single_file_from_add_line)
|
||||
if (git status -s -- "$file" | grep '^??') &>/dev/null; then # diff with /dev/null for untracked files
|
||||
git diff --color=always --no-index -- /dev/null "$file" | _forgit_pager diff | sed '2 s/added:/untracked:/'
|
||||
else
|
||||
git diff --color=always -- "$file" | _forgit_pager diff
|
||||
fi
|
||||
}
|
||||
|
||||
_forgit_git_add() {
|
||||
_forgit_add_git_opts=()
|
||||
_forgit_parse_array _forgit_add_git_opts "$FORGIT_ADD_GIT_OPTS"
|
||||
git add "${_forgit_add_git_opts[@]}" "$@"
|
||||
}
|
||||
|
||||
_forgit_git_unstage() { # TODO! TBD new core
|
||||
_forgit_add_git_opts=()
|
||||
_forgit_parse_array _forgit_add_git_opts "$FORGIT_ADD_GIT_OPTS"
|
||||
# alternative: git rm --cached "$@"
|
||||
git reset "${_forgit_add_git_opts[@]}" -q HEAD -- "$@" bla
|
||||
|
||||
}
|
||||
|
||||
_forgit_get_single_file_from_add_line() {
|
||||
# NOTE: paths listed by 'git status -su' mixed with quoted and unquoted style
|
||||
# remove indicators | remove original path for rename case | remove surrounding quotes
|
||||
|
|
@ -365,7 +382,7 @@ _forgit_get_single_file_from_add_line() {
|
|||
_forgit_edit_add_file() {
|
||||
local input_line=$1
|
||||
filename=$(echo "$input_line" | _forgit_get_single_file_from_add_line)
|
||||
$EDITOR "$filename" >/dev/tty </dev/tty
|
||||
$EDITOR "$filename" # >/dev/tty </dev/tty
|
||||
}
|
||||
|
||||
# git add selector
|
||||
|
|
@ -382,7 +399,7 @@ _forgit_add() {
|
|||
$FORGIT_FZF_DEFAULT_OPTS
|
||||
-0 -m --nth 2..,..
|
||||
--preview=\"$FORGIT add_preview {}\"
|
||||
--bind=\"alt-e:execute-silent($FORGIT edit_add_file {})+refresh-preview\"
|
||||
--bind=\"alt-e:execute($FORGIT edit_add_file {})+refresh-preview\"
|
||||
$FORGIT_ADD_FZF_OPTS
|
||||
"
|
||||
files=()
|
||||
|
|
@ -397,6 +414,38 @@ _forgit_add() {
|
|||
echo 'Nothing to add.'
|
||||
}
|
||||
|
||||
# git unstage selector
|
||||
_forgit_unstage() {
|
||||
_forgit_inside_work_tree || return 1
|
||||
local changed unmerged untracked files opts
|
||||
# Add files if passed as arguments
|
||||
[[ $# -ne 0 ]] && { _forgit_git_unstage "$@" && git status -s; return $?; }
|
||||
|
||||
changed=$(git config --get-color color.status.changed red)
|
||||
staged=$(git config --get-color color.status.changed green)
|
||||
unmerged=$(git config --get-color color.status.unmerged red)
|
||||
untracked=$(git config --get-color color.status.untracked red)
|
||||
# TODO!! is reusing add_preview sufficient? bla
|
||||
opts="
|
||||
$FORGIT_FZF_DEFAULT_OPTS
|
||||
-0 -m --nth 2..,..
|
||||
--preview=\"$FORGIT add_preview {}\"
|
||||
--bind=\"alt-e:execute($FORGIT edit_add_file {})+refresh-preview\"
|
||||
$FORGIT_ADD_FZF_OPTS
|
||||
"
|
||||
|
||||
files=()
|
||||
while IFS='' read -r file; do
|
||||
files+=("$file")
|
||||
done < <(git -c color.status=always -c status.relativePaths=true -c core.quotePath=false status -s |
|
||||
grep -F -e "$staged" |
|
||||
sed -E 's/^(..[^[:space:]]*)[[:space:]]+(.*)$/[\1] \2/' |
|
||||
FZF_DEFAULT_OPTS="$opts" fzf |
|
||||
_forgit_get_single_file_from_add_line)
|
||||
[[ "${#files[@]}" -gt 0 ]] && _forgit_git_unstage "${files[@]}" && git status -s && return
|
||||
echo 'Nothing to unstage.'
|
||||
}
|
||||
|
||||
_forgit_reset_head_preview() {
|
||||
file=$1
|
||||
git diff --staged --color=always -- "$file" | _forgit_pager diff
|
||||
|
|
@ -1004,6 +1053,7 @@ _forgit_ignore_clean() {
|
|||
|
||||
public_commands=(
|
||||
"add"
|
||||
"unstage"
|
||||
"blame"
|
||||
"branch_delete"
|
||||
"checkout_branch"
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ _git_forgit()
|
|||
|
||||
cmds="
|
||||
add
|
||||
unstage
|
||||
blame
|
||||
branch_delete
|
||||
checkout_branch
|
||||
|
|
@ -86,6 +87,7 @@ _git_forgit()
|
|||
3)
|
||||
case ${prev} in
|
||||
add) _git_add ;;
|
||||
_git_unstage ;;
|
||||
branch_delete) _git_branch_delete ;;
|
||||
checkout_branch) _git_checkout_branch ;;
|
||||
checkout_commit) _git_checkout ;;
|
||||
|
|
@ -120,6 +122,7 @@ then
|
|||
|
||||
# Completion for forgit plugin shell functions
|
||||
__git_complete forgit::add _git_add
|
||||
__git_complete forgit::unstage _git_unstage
|
||||
__git_complete forgit::branch::delete _git_branch_delete
|
||||
__git_complete forgit::checkout::branch _git_checkout_branch
|
||||
__git_complete forgit::checkout::commit _git_checkout
|
||||
|
|
@ -140,6 +143,7 @@ then
|
|||
# Completion for forgit plugin shell aliases
|
||||
if [[ -z "$FORGIT_NO_ALIASES" ]]; then
|
||||
__git_complete "${forgit_add}" _git_add
|
||||
__git_complete "${forgit_unstage}" _git_unstage
|
||||
__git_complete "${forgit_branch_delete}" _git_branch_delete
|
||||
__git_complete "${forgit_checkout_branch}" _git_checkout_branch
|
||||
__git_complete "${forgit_checkout_commit}" _git_checkout
|
||||
|
|
|
|||
|
|
@ -57,6 +57,10 @@ forgit::add() {
|
|||
"$FORGIT" add "$@"
|
||||
}
|
||||
|
||||
forgit::unstage() {
|
||||
"$FORGIT" unstage "$@"
|
||||
}
|
||||
|
||||
forgit::reset::head() {
|
||||
"$FORGIT" reset_head "$@"
|
||||
}
|
||||
|
|
@ -142,6 +146,7 @@ forgit::ignore::clean() {
|
|||
if [[ -z "$FORGIT_NO_ALIASES" ]]; then
|
||||
|
||||
export forgit_add="${forgit_add:-ga}"
|
||||
export forgit_unstage="${forgit_unstage:-gu}"
|
||||
export forgit_reset_head="${forgit_reset_head:-grh}"
|
||||
export forgit_log="${forgit_log:-glo}"
|
||||
export forgit_reflog="${forgit_reflog:-grl}"
|
||||
|
|
@ -162,6 +167,7 @@ if [[ -z "$FORGIT_NO_ALIASES" ]]; then
|
|||
export forgit_blame="${forgit_blame:-gbl}"
|
||||
|
||||
alias "${forgit_add}"='forgit::add'
|
||||
alias "${forgit_unstage}"='forgit::unstage'
|
||||
alias "${forgit_reset_head}"='forgit::reset::head'
|
||||
alias "${forgit_log}"='forgit::log'
|
||||
alias "${forgit_reflog}"='forgit::reflog'
|
||||
|
|
|
|||
Loading…
Reference in a new issue