From f4ae3f1ab606003abf01c67de58a9b253841e94a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20G=C3=BCnzler?= Date: Thu, 11 Oct 2018 15:16:19 +0200 Subject: [PATCH] Use global porcelain if there is one --- porcelain.tmux | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/porcelain.tmux b/porcelain.tmux index 1aefce4..b38a877 100755 --- a/porcelain.tmux +++ b/porcelain.tmux @@ -1,8 +1,10 @@ #!/usr/bin/env bash CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +PORCELAIN_BIN="$CURRENT_DIR/porcelain" -porcelain_status="#($CURRENT_DIR/porcelain -tmux -path '#{pane_current_path}')" +global_porcelain="" +porcelain_status="#($PORCELAIN_BIN -debug -tmux -path '#{pane_current_path}')" porcelain_interpolation_string="\#{porcelain}" do_interpolation() { @@ -18,17 +20,30 @@ update_tmux_option() { tmux set-option -gq "$option" "$new_option_value" } +install() { + update_tmux_option "status-right" + update_tmux_option "status-left" +} + main() { - if ! [[ -f "$CURRENT_DIR/porcelain" ]] + global_porcelain="$(command -v porcelain)" + if [[ -f "$global_porcelain" ]] + then + PORCELAIN_BIN=$global_porcelain + install + exit 0 + fi + + if ! [[ -f "$PORCELAIN_BIN" ]] then curl -sL "$(curl -s https://api.github.com/repos/robertgzr/porcelain/releases/latest | grep "browser_download_url" | grep "$(uname | tr '[:upper:]' '[:lower:]')"| cut -d\" -f4)" |\ tar -C "$CURRENT_DIR" -xzf - porcelain &>/dev/null fi # try again - if [[ -f "$CURRENT_DIR/porcelain" ]] + if [[ -f "$PORCELAIN_BIN" ]] then - update_tmux_option "status-right" - update_tmux_option "status-left" + install + exit 0 fi } main