From a12c9bcff9390992774d128697e0ce88c932b214 Mon Sep 17 00:00:00 2001 From: pztrn Date: Mon, 4 Jan 2016 15:05:09 +0500 Subject: [PATCH] Changed "colors" app nam in enabled apps config to "showcolors". Fixed gitinfo application, now it would not spam on jist-git-init'ed repos, fixing #1. Also reworked checks things, now every function will call gitinfo_internal_checks function and do nothing if internal checks method returns 1. --- zsh/apps/gitinfo.app.zsh | 41 ++++++++++++++++++++++++++++----------- zsh/defaults/02-apps.conf | 2 +- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/zsh/apps/gitinfo.app.zsh b/zsh/apps/gitinfo.app.zsh index a26a414..8e274cb 100644 --- a/zsh/apps/gitinfo.app.zsh +++ b/zsh/apps/gitinfo.app.zsh @@ -12,8 +12,8 @@ GITINFO_STASHES_COUNT=0 ###################################################################### function gitinfo() { - curdir=`pwd` - if [ ! -d "${curdir}/.git" ]; then + gitinfo_internal_checks + if [ $? -eq 1 ]; then echo "This is not a git repository." return 1 fi @@ -54,9 +54,15 @@ function gitinfo_chpwd() function gitinfo_check() { curdir=`pwd` + if [ "${#GITINFO_BRANCH}" -eq 0 ]; then return 1 fi + + objects=`ls .git/objects | grep -v "info\|pack" | wc -l` + if [ ${objects} -lt 1 ]; then + return 1 + fi } ###################################################################### @@ -64,8 +70,8 @@ function gitinfo_check() ###################################################################### function gitinfo_get_branch() { - curdir=`pwd` - if [ ! -d "${curdir}/.git" ]; then + gitinfo_internal_checks + if [ $? -eq 1 ]; then GITINFO_BRANCH="" return 1 fi @@ -77,8 +83,8 @@ function gitinfo_get_branch() ###################################################################### function gitinfo_get_changes() { - curdir=`pwd` - if [ ! -d "${curdir}/.git" ]; then + gitinfo_internal_checks + if [ $? -eq 1 ]; then GITINFO_NEW_FILES="" GITINFO_MODIFIED_FILES="" return 1 @@ -93,8 +99,8 @@ function gitinfo_get_changes() ###################################################################### function gitinfo_get_commit_data() { - curdir=`pwd` - if [ ! -d "${curdir}/.git" ]; then + gitinfo_internal_checks + if [ $? -eq 1 ]; then GITINFO_COMMIT_SHORTID="" GITINFO_COMMIT_ID="" GITINFO_COMMIT_COUNT="" @@ -110,8 +116,8 @@ function gitinfo_get_commit_data() ###################################################################### function gitinfo_get_remotes() { - curdir=`pwd` - if [ ! -d "${curdir}/.git" ]; then + gitinfo_internal_checks + if [ $? -eq 1 ]; then GITINFO_REMOTES="" return 1 fi @@ -122,11 +128,24 @@ function gitinfo_get_remotes() # Gets current directory's stashes count. ###################################################################### function gitinfo_get_stashes() +{ + + GITINFO_STASHES_COUNT=$(git stash list 2>/dev/null | wc -l) +} + +###################################################################### +# Some common checks that is used everywhere. +###################################################################### +function gitinfo_internal_checks() { curdir=`pwd` if [ ! -d "${curdir}/.git" ]; then GITINFO_STASHES_COUNT="" return 1 fi - GITINFO_STASHES_COUNT=$(git stash list 2>/dev/null | wc -l) + + objects=`ls .git/objects | grep -v "info\|pack" | wc -l` + if [ ${objects} -lt 1 ]; then + return 1 + fi } diff --git a/zsh/defaults/02-apps.conf b/zsh/defaults/02-apps.conf index 409ba7e..16b28dc 100644 --- a/zsh/defaults/02-apps.conf +++ b/zsh/defaults/02-apps.conf @@ -1,2 +1,2 @@ # Apps list to enable. -ENABLED_APPS=("colors") +ENABLED_APPS=("showcolors")