Skip to content

Commit

Permalink
git stage/restore keyboard shortcuts (kelleyma49#168)
Browse files Browse the repository at this point in the history
* Initial version of git add/reset in status

- keyboard shortcuts for adding/reseting changes, similar to git fuzzy

* git stage/restore work

- staged files show diff
- print if file was added/deleted in preview window
  • Loading branch information
kelleyma49 authored Aug 9, 2022
1 parent cee4b26 commit 5ca74fb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
22 changes: 19 additions & 3 deletions PSFzf.Git.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,28 @@ function Invoke-PsFzfGitFiles() {

$headerStrings = Get-HeaderStrings

# add git add and reset keyboard shortcuts:
if ($RunningInWindowsTerminal -or -not $IsWindowsCheck) {
$gitCmdsHeader = "`n`e[7mALT+S`e[0m Git Add`t`e[7mALT+R`e[0m Git Reset"
} else {
$gitCmdsHeader = "`nALT+S-Git Stage`tALT+R-Git Reset"
}
$headerStr = $headerStrings[0] + $gitCmdsHeader
$statusCmd = "git $(Get-ColorAlways '-c color.status=always') status --short"

$reloadBindCmd = "reload($statusCmd)"
$stageScriptPath = Join-Path $PsScriptRoot 'helpers/PsFzfGitFiles-GitAdd.sh'
$gitStageBind = "alt-s:execute-silent(" + "${script:bashPath} ${stageScriptPath} {+2..})+down+${reloadBindCmd}"
$resetScriptPath = Join-Path $PsScriptRoot 'helpers/PsFzfGitFiles-GitReset.sh'
$gitResetBind = "alt-r:execute-silent(" + "${script:bashPath} ${resetScriptPath} {+2..})+down+${reloadBindCmd}"

Invoke-Expression "& $statusCmd" | `
Invoke-Fzf -Multi -Ansi `
-Preview "$previewCmd" -Header $headerStrings[0] -Bind $headerStrings[1] | foreach-object {
$result += $_.Substring('?? '.Length)
}
-Preview "$previewCmd" -Header $headerStr `
-Bind $headerStrings[1],"""$gitStageBind""","""$gitResetBind""" | `
foreach-object {
$result += $_.Substring('?? '.Length)
}
InvokePromptHack
if ($result.Length -gt 0) {
$result = $result -join " "
Expand Down
1 change: 1 addition & 0 deletions helpers/PsFzfGitFiles-GitAdd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git add -- "$@"
1 change: 1 addition & 0 deletions helpers/PsFzfGitFiles-GitReset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git reset -- "$@"
8 changes: 7 additions & 1 deletion helpers/PsFzfGitFiles-Preview.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ file=$1

pushd . > /dev/null
cd "$dir"
git diff $args $file | head -500
if [ ! -e "$file" ]; then
echo "$file deleted"
elif git ls-files --error-unmatch "$1" > /dev/null 2>&1; then
git diff $args HEAD -- $file | head -500
else
echo "$file added"
fi
popd > /dev/null

0 comments on commit 5ca74fb

Please sign in to comment.