diff --git a/.config/starship.toml b/.config/starship.toml index 1e985a7..020c634 100644 --- a/.config/starship.toml +++ b/.config/starship.toml @@ -11,8 +11,14 @@ $git_status\ """ right_format = """\ +${custom.sl_status}\ """ +[custom.sl_status] +command = '''~/bin/starship-sl-status''' +when = true +style = "italic bg:#79AE6F fg:#ffffff" +format = '🌱 [](fg:#79AE6F)[ $output ]($style)' [character] success_symbol = "%" diff --git a/bin/starship-sl-status b/bin/starship-sl-status new file mode 100755 index 0000000..8a80026 --- /dev/null +++ b/bin/starship-sl-status @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -xfeuo pipefail + +state="${XDG_RUNTIME_DIR}/starship-sl-status" +checkout="${state}.checkout" +status="${state}.data" + +if [[ "$PWD" != $(readlink -f "$state")* ]]; then + rm -f "$state" + root="$(sl root 2>/dev/null || true)" + ln -s "$root" "$state" + if [[ -z "${root}" ]]; then + echo >"${status}" + echo >"${checkout}" + exit 0 + fi +fi + +saved_cid=$(cat "${checkout}" 2>/dev/null || true) +root_cid=$(cat "${state}/.sl/checkoutidentifier" || true) +if [[ ${root_cid} != "${saved_cid}" ]]; then + echo "${root_cid}" >"${checkout}" + sl log -r . -T '{if(github_pull_request_number, "#{github_pull_request_number} @ ", if(bookmarks, "{bookmarks} @ "))}{node|short}{if(remotenames, ":{remotenames}")}' >"${status}" +fi + +cat "$status" || true