From a9627edea4211828510cf99b86285f5ad254fa33 Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Tue, 2 Aug 2022 13:56:40 -0400 Subject: [PATCH] refactor: git stage cli (simplified) --- examples/basic-git-cli.sh | 45 --------------------------------------- examples/git-stage.sh | 12 +++++++++++ 2 files changed, 12 insertions(+), 45 deletions(-) delete mode 100755 examples/basic-git-cli.sh create mode 100755 examples/git-stage.sh diff --git a/examples/basic-git-cli.sh b/examples/basic-git-cli.sh deleted file mode 100755 index 0f5561d..0000000 --- a/examples/basic-git-cli.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -# A basic cli for handling the staging with git -# -# This is a simple cli that utilizes the output from several git commands, and -# pipes them into `gum filter` and `gum choose` to provide a simple cli wrapper -# for `git add` and `git reset`. -# -# For a more feature complete version of this script check out -# [Nickiel12's Git-Gum](https://github.com/Nickiel12/Git-Gum). - -git_add_filter(){ - input=$1 - if [[ $input == "M "* ]]; then - if [ ! -z "$(git ls-files . --exclude-standard --others -m | grep "${input:2}")" ]; then - echo ${input:2} - fi - else - if [ ! -z "$(git ls-files . --exclude-standard --others -m | grep "${input:3}")" ]; then - echo ${input:3} - fi - fi -} - -choice=$(echo -e "add\nreset" | gum filter) - -case $choice in - add ) - export -f git_add_filter - selection=`git status --short | xargs -I{} bash -c 'git_add_filter "{}"' | sed "$ a None" | gum choose --no-limit` - if [ "$selection" = "None" ]; then - echo "No files selected" - else - git add -- "$selection" - fi - ;; - reset ) - selection=`git diff --staged --name-only | sed "$ a None" | gum choose --no-limit` - if [ "$selection" = "None" ]; then - echo "None selected - skipping" - else - echo "$selection" | git reset - fi - ;; -esac diff --git a/examples/git-stage.sh b/examples/git-stage.sh new file mode 100755 index 0000000..1dbd47b --- /dev/null +++ b/examples/git-stage.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +ADD="Add" +RESET="Reset" + +ACTION=$(gum choose "$ADD" "$RESET") + +if [ "$ACTION" == "$ADD" ]; then + git status --short | cut -c 4- | gum choose --no-limit | xargs git add +else + git status --short | cut -c 4- | gum choose --no-limit | xargs git restore +fi