Skip to content

Instantly share code, notes, and snippets.

@jaggzh
Last active May 24, 2024 03:28

Revisions

  1. jaggzh revised this gist May 24, 2024. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion git-ls-last-status
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,15 @@
    #!/bin/bash
    . ansi.sh
    # List repo status of latest files in current directory
    # (With colors and chars and easy to see)
    #
    # Example runs:
    # git-ls-last-status
    # (Displays up to 10 files)
    # or
    # git-ls-last-status 30
    ourdir="$(dirname "$(readlink -f "$0")")"
    . "$ourdir/ansi.sh"

    # Default to the last 10 files if no argument is given
    n=${1:-10}

  2. jaggzh revised this gist May 24, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-ls-last-status
    Original file line number Diff line number Diff line change
    @@ -33,4 +33,4 @@ cat <<-EOT
    $cin[*]$rst In repo. $cmod[m]$rst Modified. $cnin[X]$rst NOT in repo.
    EOT
    } | less -F
    } | less -F -R -X
  3. jaggzh created this gist May 23, 2024.
    24 changes: 24 additions & 0 deletions ansi.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    bgbla=''; bgred=''; bggre=''; bgbro='';
    bgblu=''; bgmag=''; bgcya=''; bggra='';
    bla=''; red=''; gre=''; bro='';
    blu=''; mag=''; cya=''; gra='';
    bbla=''; bred=''; bgre=''; yel='';
    bblu=''; bmag=''; bcya=''; whi='';
    rst=''; inv=''; cll=''; cllr='';
    cls=''; clsb='';

    bgblae='\033[40m'; bgrede='\033[41m'; bggree='\033[42m'; bgbroe='\033[43m';
    bgblue='\033[44m'; bgmage='\033[45m'; bgcyae='\033[46m'; bggrae='\033[47m';
    blae='\033[30m'; rede='\033[31m'; gree='\033[32m'; broe='\033[33m';
    blue='\033[34m'; mage='\033[35m'; cyae='\033[36m'; grae='\033[37m';
    bblae='\033[30;1m'; brede='\033[31;1m'; bgree='\033[32;1m'; yele='\033[33;1m';
    bblue='\033[34;1m'; bmage='\033[35;1m'; bcyae='\033[36;1m'; whie='\033[37;1m';
    rste='\033[0m'; inve='\033[7m'; clle='\033[2K'; cllre='\033[K';
    clse='\033[2J'; clsbe='\033[J';

    a24fg () { # [0-255] Usage: a24fg r g b
    printf '%s' "[38;2;$1;$2;${3}m"
    }
    a24bg () { # [0-255] Usage: a24fg r g b
    printf '%s' "[48;2;$1;$2;${3}m"
    }
    36 changes: 36 additions & 0 deletions git-ls-last-status
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    #!/bin/bash
    . ansi.sh
    # Default to the last 10 files if no argument is given
    n=${1:-10}

    # Get the last $n files sorted by modification time
    files=$(ls -lrt | tail -n $n | awk '{print $9}')

    cin=$gre
    cmod=$bro
    cnin=$red

    # Loop through each file and check its git status
    {
    for file in $files; do
    # Check if the file is tracked by git
    git ls-files --error-unmatch $file &> /dev/null
    if [ $? -eq 0 ]; then
    # The file is tracked by Git, check for modifications
    modified=$(git status --short $file)
    if [ -z "$modified" ]; then
    echo "$cin[*]$rst $file"
    else
    # Display the modification status
    echo "$cmod[m]$rst $file"
    fi
    else
    echo "$cnin[X]$rst $file"
    fi
    done

    cat <<-EOT
    $cin[*]$rst In repo. $cmod[m]$rst Modified. $cnin[X]$rst NOT in repo.
    EOT
    } | less -F