# This function should be bound to Alt-G, and is used to show the current git status of the directory inder the cursor.

function __show_git_status -d "Show git status at token under the cursor if it is a directory, or the current directory"
    set -l target (commandline -t)
    printf "\n"
    if test ! -d $target
        set -l dir (dirname -- $target)
        if test $dir != . -a -d $dir
            set target $dir
        else
            set target .
        end
    end

    git -C $target rev-parse &>/dev/null
    and git -C $target status
    or echo "Not a Git repository"

    string repeat -N \n --count=(math (count (fish_prompt)) - 1)

    commandline -f repaint
end