From 0387deb64168129dce409cc734c8f4d60d0fe8d2 Mon Sep 17 00:00:00 2001 From: xylous Date: Sun, 8 Aug 2021 18:34:17 +0300 Subject: [PATCH] Export a function instead of running w/shebang To make integrating with plugin managers as easy as possible, plugins/scripts shouldn't be sourced on their own; instead, they should export functions. --- README.md | 4 +++- gitstatus.plugin.zsh | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a9f8751..02d00e6 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,11 @@ git clone "https://github.com/xylous/gitstatus.zsh.git" gitstatus Add the following lines to your zshrc: ```zsh +source path/to/installation/gitstatus.plugin.zsh + function precmd() { - local gitstatus="$(path/to/installation/gitstatus.plugin.zsh)" + local gitstatus="$(gitstatus)" PS1="%F{blue}%~%F{default} ${gitstatus} $ " } ``` diff --git a/gitstatus.plugin.zsh b/gitstatus.plugin.zsh index 2df678f..3e4a173 100755 --- a/gitstatus.plugin.zsh +++ b/gitstatus.plugin.zsh @@ -1,6 +1,4 @@ -#!/usr/bin/zsh - -function main() +function gitstatus() { is_in_git_repository || return 1 @@ -84,7 +82,7 @@ function parse_git_status() { git status --porcelain=v1 | while IFS= read -r status_line; do case "$status_line" in - ' M '*) + ' M '*) ((modified++)) ;; 'A '*|'M '*) @@ -149,5 +147,3 @@ function git_determine_color() typeset -g REPLY="$yellow" return 0 } - -main