[custom.svn]
command = '~/.local/bin/subversion-status'
detect_folders = ['.svn']
symbol = ""
style = "bold purple"
format = 'on [$symbol ($output)]($style)'Im using the Nerd Fonts to display this. I personally like the JetBrains variant.
[custom.svn]
command = '~/.local/bin/subversion-status'
detect_folders = ['.svn']
symbol = ""
style = "bold purple"
format = 'on [$symbol ($output)]($style)'Im using the Nerd Fonts to display this. I personally like the JetBrains variant.
| #!/usr/bin/env bash | |
| # Based on https://codeberg.org/ManfredLotz/svnstatus/src/branch/main/src/main.rs | |
| # Mirrors the Rust behavior: | |
| # - Print SVN revision (no newline in svn output, but echo will add one) | |
| # - If there are status lines, append a compact summary like: A, A:3, M, M:2, ?:5, etc. | |
| # - Skip empty lines and "Performing status on external item" lines. | |
| run_cmd() { | |
| # Usage: run_cmd <stdout_varname> <cmd...> | |
| # Captures stdout on success; on failure prints stderr and returns non-zero. | |
| local __outvar="$1" | |
| shift | |
| local stdout_file stderr_file | |
| stdout_file="$(mktemp)" | |
| stderr_file="$(mktemp)" | |
| if "$@" >"$stdout_file" 2>"$stderr_file"; then | |
| local out | |
| out="$(cat "$stdout_file")" | |
| rm -f "$stdout_file" "$stderr_file" | |
| printf -v "$__outvar" '%s' "$out" | |
| return 0 | |
| else | |
| cat "$stderr_file" >&2 | |
| rm -f "$stdout_file" "$stderr_file" | |
| return 1 | |
| fi | |
| } | |
| append_status_piece() { | |
| # Usage: append_status_piece <char> <count> <dest_varname> | |
| local ch="$1" | |
| local count="$2" | |
| local dest_var="$3" | |
| local piece="" | |
| if [[ "$count" -gt 0 ]]; then | |
| piece="${ch}${count}" | |
| fi | |
| if [[ -n "$piece" ]]; then | |
| # concatenate without separators, matching the Rust output | |
| printf -v "$dest_var" '%s%s\e[0m' "${!dest_var}" "$piece" | |
| fi | |
| } | |
| main() { | |
| local revision | |
| run_cmd revision svn --non-interactive info --no-newline --show-item revision || exit 1 | |
| local status_info | |
| run_cmd status_info svn --non-interactive status || exit 1 | |
| local status_string="" | |
| if [[ -n "$status_info" ]]; then | |
| local added=0 conflicted=0 deleted=0 ignored=0 modified=0 replaced=0 unknown=0 missing=0 | |
| while IFS= read -r line; do | |
| [[ -z "${line//[[:space:]]/}" ]] && continue | |
| [[ "$line" == "Performing status on external item"* ]] && continue | |
| # first character of the line | |
| local first="${line:0:1}" | |
| case "$first" in | |
| A) ((added++)) ;; | |
| C) ((conflicted++)) ;; | |
| D) ((deleted++)) ;; | |
| I) ((ignored++)) ;; | |
| M) ((modified++)) ;; | |
| R) ((replaced++)) ;; | |
| '?') ((unknown++)) ;; | |
| '!') ((missing++)) ;; | |
| *) ;; | |
| esac | |
| done <<<"$status_info" | |
| append_status_piece "\e[0;92;49m " "$added" status_string | |
| append_status_piece "\e[0;91;49m!" "$conflicted" status_string | |
| append_status_piece "\e[0;91;49m " "$deleted" status_string | |
| append_status_piece "\e[9;90;49m" "$ignored" status_string | |
| append_status_piece "\e[0;93;49m " "$modified" status_string | |
| append_status_piece "\e[1;33;49m " "$replaced" status_string | |
| append_status_piece "\e[1;95;49m?" "$unknown" status_string | |
| append_status_piece "\e[1;95;49m!" "$missing" status_string | |
| fi | |
| if [[ -n "$status_string" ]]; then | |
| status_string="($status_string)" | |
| fi | |
| echo -e "#$revision \e[0m$status_string\e[0m " | |
| exit 0 | |
| } | |
| main "$@" |