From 9b18fa83db34d0f5fa98300bf639b393fd1fd8ab Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Tue, 10 Oct 2023 14:21:38 +0100 Subject: [PATCH] Sync minimal branch with master. --- .bashrc | 96 ++++++++++++++++++++++++++++++++------------------- .gitconfig | 9 +++-- .shellcheckrc | 3 ++ .ssh/config | 7 +--- 4 files changed, 68 insertions(+), 47 deletions(-) create mode 100644 .shellcheckrc diff --git a/.bashrc b/.bashrc index 155af67..8274aa4 100644 --- a/.bashrc +++ b/.bashrc @@ -3,64 +3,73 @@ __prompt_git_status() { # Generate a git branch/status prompt. # Based on git-prompt.sh by Shawn O. Pearce . + # Arguments: + # $1 The printf format string for the prompt. Must include %s. # Environment variables: - # GIT_PROMPT_SHOW_TYPE=1 - Show type of repository (Bare, Shallow). - # GIT_PROMPT_SHOW_IGNORED=1 - Show a ! if the directory is ignored. - # GIT_PROMPT_SHOW_UNSTAGED=1 - Show a * if there are unstaged changes (superceeded by above). - # GIT_PROMPT_SHOW_UNTRACKED=1 - Show a ? if there are untracked files in the working directory (superceeded by above). - # GIT_PROMPT_SHOW_STASH=1 - Show a & if there is a stash in this repository (superceeded by above). - # GIT_PROMPT_SHOW_UPSTREAM=1 - Show status of this repository compaired to upstream: + # GIT_PROMPT_SHOW_TYPE=1 Show type of repository (Bare, Shallow). + # GIT_PROMPT_SHOW_UPSTREAM=1 Show status of this repository compaired to upstream: # ?? - No upstream set. # == - Working tree is equal to upstream. # <> - Divergent from upstream. # >> or >x - Working tree is ahead of upstream (x = commits ahead when used with next option). # << or 5 * + # Returns: Exit code of the command line before entering this function. + # shellcheck disable=SC2155 + local BRANCH COUNT GIT_PROMPT GIT_REPO_INFO PWD=$(pwd -P) RET="$?" # Bail out if there's no format argument given. (( $# != 1 )) && return "$RET" # Get some repository information. # shellcheck disable=SC2207 - GIT_REPO_INFO=( $(git rev-parse --is-bare-repository --is-shallow-repository --is-inside-git-dir --is-inside-work-tree --short HEAD 2>/dev/null) ) + IFS=$'\n' GIT_REPO_INFO=( $(git rev-parse --show-toplevel --git-dir --is-bare-repository --is-shallow-repository --is-inside-git-dir --is-inside-work-tree 2>/dev/null) ) ERR="$?" # Do nothing if there's an error. - (( ERR >= 1 )) || { (( ERR == 128 )) && (( ${#GIT_REPO_INFO[@]} != 3 )); } && return "$RET" + (( ERR >= 1 )) && return "$RET" # Generate the prompt. - if [[ "${GIT_REPO_INFO[2]}" == "true" ]]; then - # If in the git directory, use a special branch marker. + if [[ "${GIT_REPO_INFO[4]}" == "true" ]]; then + # In the git directory, use a special branch marker. GIT_PROMPT+="!GIT_DIR!" - elif [[ "${GIT_REPO_INFO[3]}" == "true" ]]; then - # If in the working directory, generate the prompt. - # Add status markers. + elif [[ "${GIT_REPO_INFO[5]}" == "true" ]]; then + # In the working directory, generate the prompt. + # Add type markers. [[ -n "$GIT_PROMPT_SHOW_TYPE" ]] && { - if [[ "${GIT_REPO_INFO[0]}" == "true" ]]; then + if [[ "${GIT_REPO_INFO[2]}" == "true" ]]; then GIT_PROMPT+="B:" - elif [[ "${GIT_REPO_INFO[1]}" == "true" ]]; then + elif [[ "${GIT_REPO_INFO[3]}" == "true" ]]; then GIT_PROMPT+="S:" fi } - # Add the branch. - GIT_PROMPT+="$(git describe --contains --all HEAD)" - - # Add a marker if directory is ignored, there's untracked files or a stash. - if [[ -n "$GIT_PROMPT_SHOW_IGNORED" ]] && git check-ignore -q "${PWD#"$(git rev-parse --show-toplevel)/"}"; then - GIT_PROMPT+=" !" - elif [[ -n "$GIT_PROMPT_SHOW_UNSTAGED" ]] && git ls-files --modified --exclude-standard --directory --error-unmatch -- ':/*' >/dev/null 2>&1; then - GIT_PROMPT+=" *" - elif [[ -n "$GIT_PROMPT_SHOW_UNTRACKED" ]] && git ls-files --others --exclude-standard --directory --error-unmatch -- ':/*' >/dev/null 2>&1; then - GIT_PROMPT+=" ?" - elif [[ -n "$GIT_PROMPT_SHOW_STASH" ]] && git rev-parse --verify --quiet refs/stash >/dev/null; then - GIT_PROMPT+=" &" + # Add the branch if there have been commits. + if [[ -e "${GIT_REPO_INFO[1]}/refs/heads/master" ]]; then + BRANCH="$(git describe --contains --all HEAD)" + GIT_PROMPT+="$BRANCH" + else + GIT_PROMPT+="!NO COMMITS!" fi - # Get upstream status. + # Add upstream status. [[ -n "$GIT_PROMPT_SHOW_UPSTREAM" ]] || [[ -n "$GIT_PROMPT_SHOW_UPSTREAM_EXTENDED" ]] && { - COUNT="$(git rev-list --count --left-right '@{upstream}'...HEAD 2>/dev/null | tr '[:blank:]' ' ')" + # Whether to run prefetch tasks. + [[ -n "$GIT_PROMPT_AUTO_PREFETCH" ]] && { + # Only prefetch remotes if in the top-level working directory and if the repository is configured for maintenance work. + [[ "$PWD" == "${GIT_REPO_INFO[0]}" ]] && git config --global --get --fixed-value maintenance.repo "$PWD" >/dev/null 2>&1 && { + git maintenance run --task=prefetch 2>/dev/null || printf "\\033[1;31m%s\\033[39m\\n" "Git maintenance 'prefetch' task failed." >&2 + } + } + COUNT="$(git rev-list --count --left-right "${BRANCH:+refs/prefetch/remotes/origin/}${BRANCH:-@{upstream\}}...HEAD" 2>/dev/null | tr '[:blank:]' ' ')" case "$COUNT" in "") # No upstream. @@ -85,7 +94,7 @@ __prompt_git_status() { GIT_PROMPT+=" <" if [[ -n "$GIT_PROMPT_SHOW_UPSTREAM_EXTENDED" ]]; then # Show the number of the difference. - GIT_PROMPT+="${COUNT% 0}" + GIT_PROMPT+="${COUNT% 0}" else GIT_PROMPT+="<" fi @@ -96,6 +105,19 @@ __prompt_git_status() { ;; esac } + + # Add a marker if directory is ignored, there's unstaged files, uncommitted changes, untracked files or a stash. + if [[ -n "$GIT_PROMPT_SHOW_IGNORED" ]] && git check-ignore "${PWD#"${GIT_REPO_INFO[0]}/"}" >/dev/null 2>&1 ; then + GIT_PROMPT+=" !" + elif [[ -n "$GIT_PROMPT_SHOW_UNSTAGED" ]] && git ls-files --modified --exclude-standard --directory --error-unmatch -- ':/*' >/dev/null 2>&1; then + GIT_PROMPT+=" *" + elif [[ -n "$GIT_PROMPT_SHOW_UNCOMMITTED" ]] && ! git diff --name-only --cached --exit-code >/dev/null 2>&1; then + GIT_PROMPT+=" &" + elif [[ -n "$GIT_PROMPT_SHOW_UNTRACKED" ]] && git ls-files --others --exclude-standard --directory --error-unmatch -- ':/*' >/dev/null 2>&1; then + GIT_PROMPT+=" +" + elif [[ -n "$GIT_PROMPT_SHOW_STASH" ]] && git rev-parse --verify --quiet refs/stash >/dev/null; then + GIT_PROMPT+=" $" + fi fi # Output the prompt. @@ -389,12 +411,14 @@ PROMPT_COMMAND="__nanorc_prompt_command; __ssh_agent_prompt_command" # Git prompt options. GIT_PROMPT_SHOW_TYPE=1 -GIT_PROMPT_SHOW_IGNORED=1 -GIT_PROMPT_SHOW_UNSTAGED=1 -GIT_PROMPT_SHOW_UNTRACKED=1 -GIT_PROMPT_SHOW_STASH=1 GIT_PROMPT_SHOW_UPSTREAM=1 GIT_PROMPT_SHOW_UPSTREAM_EXTENDED=1 +GIT_PROMPT_AUTO_PREFETCH=1 +GIT_PROMPT_SHOW_IGNORED=1 +GIT_PROMPT_SHOW_UNSTAGED=1 +GIT_PROMPT_SHOW_UNCOMMITTED=1 +GIT_PROMPT_SHOW_UNTRACKED=1 +GIT_PROMPT_SHOW_STASH=1 # Version specific set up. if (( BASH_VERSINFO[0] >= 4 )); then diff --git a/.gitconfig b/.gitconfig index efca39b..af3db86 100644 --- a/.gitconfig +++ b/.gitconfig @@ -11,6 +11,7 @@ ui = auto [credential] username = tadgy + helper = cache --timeout 2592000 [commit] verbose = 1 [push] @@ -29,8 +30,6 @@ [maintenance] repo = / repo = /root - repo = /data/slackware/repo.git - repo = /data/slackware/tagfiles.git - repo = /data/slackware/tools.git - repo = /data/tmp/slackbuilds.git - repo = /data/tmp/ponce-slackbuilds.git + repo = /etc/slackpkg/templates +[init] + defaultBranch = master diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000..2a9695e --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,3 @@ +enable=add-default-case,check-unassigned-uppercase,deprecate-which,quote-safe-variables,require-double-brackets +wiki-link-count=10 +external-sources=true diff --git a/.ssh/config b/.ssh/config index 1d77eae..20b1624 100644 --- a/.ssh/config +++ b/.ssh/config @@ -66,11 +66,6 @@ Host clone-* full-* ClearAllForwardings yes # Git services. -Host github.com +Host github.com git.rlworkman.net User git - ForwardAgent no - ClearAllForwardings yes - -Host git.rlworkman.net - ForwardAgent no ClearAllForwardings yes