1#!/bin/sh
2
3# Git status plugin for CliFM
4# Written by L. Abramovich
5
6# Description: Check if the current directory is inside a git work
7# tree, and, if true, print status, i.e., branch name and non
8# commited/tracked files
9
10# NOTE: This script is not intended to be used as a normal plugin,
11# that is, called via an action name, but rather to be executed as
12# a prompt command (see the configuration file)
13
14# Some useful git commands for a more complex output:
15
16#am I inside git repo? [ "$(git rev-parse --is-inside-work-tree)" = "true" ] && echo "Yes"
17#current remote/repo: git rev-parse --abbrev-ref @{upstream}
18#current repo: git describe --contains --all HEAD
19#total upstream commits: git rev-list --count @{upstream}
20#last local commit short hash: git rev-parse --short HEAD
21#last upstream commit short hash: git rev-parse --short @{upstream}
22#Is something stashed: git rev-parse --verify --quiet refs/stash
23#Non-commited/tracked local changes: git status | grep -q "nothing to commit" && echo "No" || echo "Yes" or git status -sb
24
25if [ -n "$1" ] && [ "$1" = "--help" ]; then
26	printf "Print current git status (if in a git repository). This script is intended to be executed as a prompt command. Add the absolute path to this plugin to the PROMPT COMMANDS section in the configuration file.\n"
27	exit 0
28fi
29
30[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" != "true" ] && exit 1
31
32git status -sb 2>/dev/null
33
34exit 0
35