Skip to content

Improve performance #2

@stuaxo

Description

@stuaxo

Hi,
Thanks for this, I couldn't quite get powerline itself to work in my setup so this is handy.

Where I work the git repo is really big so each git command takes about 0.3 seconds.

As there a few it takes about a second to draw for the prompt to draw.

I don't know git well enough to provide a patch, but I was looking at whether its possible to get more of the stats using fewer external commands,

As an experiment I've made a script that gets the changed file count, and the the amount of insertions, using one call to git diff --shortstat and then parsing the output in bash.

Maybe this would be useful in helping speed up rendering of the prompt?

$  ./parse_git_stats.sh

original output: " 3 files changed"
changed: '3'
inserted: '4'

script:

#!/bin/bash

# Set comma as the delimiter
IFS=','

read -a gitstat <<< $(git diff --shortstat)

# Example output from git diff --shortstat:
#  3 files changed, 4 insertions(+)
#
# read has split it by comma, next remove space prefix and text suffix
# using bash.

git_changed=${gitstat[0]%" files changed"}
git_changed=${git_changed# }

git_insertions=${gitstat[1]% "insertions(+)"}
git_insertions=${git_insertions# }

echo "changed: '"$git_changed"'"
echo "inserted: '"$git_insertions"'"

Most of the work is removing the prefixes + suffixes from the strings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions