diff --git a/config.example.sh b/config.example.sh index 7429968..7e4f078 100644 --- a/config.example.sh +++ b/config.example.sh @@ -27,7 +27,3 @@ DISCORD_SERVER_NAME="" DISCORD_GENERAL_HOOK="?wait=true" -DISCORD_RESTAKE_HOOK="?wait=true" - -DISCORD_STORAGE_HOOK="?wait=true" - diff --git a/fetch-all.sh b/fetch-all.sh index 7bf37e1..d6bd9fa 100755 --- a/fetch-all.sh +++ b/fetch-all.sh @@ -26,10 +26,10 @@ fi # function to process each location function process_git_fetch () { startedIn=`pwd` - location=$(dirname "$@") - echo -n "----- git fetch $location " - printf "%*.*s" 0 $((40 - ${#location} )) "----------------------------------------" - echo "-----" + location=$(realpath $(dirname "$@")) + line="--- --- --- --- --- --- --- --- --- ---" + # use "--" to tell printf there are no more commands, only strings to print + printf -- "--- git fetch %s %s ---\n" "$location" "${line:${#location}}" cd "$location" git fetch --tags --prune cd "$startedIn" diff --git a/list-all.sh b/list-all.sh index e4a1ea9..80901d3 100755 --- a/list-all.sh +++ b/list-all.sh @@ -26,10 +26,10 @@ fi # function to process each location function process_git_list () { startedIn=`pwd` - location=$(dirname "$@") - echo -n "----- git remote $location " - printf "%*.*s" 0 $((40 - ${#location} )) "----------------------------------------" - echo "-----" + location=$(realpath $(dirname "$@")) + line="--- --- --- --- --- --- --- --- --- ---" + # use "--" to tell printf there are no more commands, only strings to print + printf -- "--- git remote %s %s ---\n" "$location" "${line:${#location}}" cd "$location" git remote -vv cd "$startedIn" diff --git a/one-time-stuff/basic-settings.sh b/one-time-stuff/basic-settings.sh index 85595ca..8eb3c9b 100755 --- a/one-time-stuff/basic-settings.sh +++ b/one-time-stuff/basic-settings.sh @@ -85,6 +85,27 @@ esac # ---------------------------------------------------------- +echo "----- Set 'cd' to use physical directory structure -----" +read -p 'Add ``alias cd="cd -P"`` in ~/.bashrc? [y/N]: ' add_cd_alias +case $add_cd_alias in + [Yy]* ) + echo 'Appending ~/.bashrc' + ( + cat << 'TERM' + +# ABS when changing directory through a symlink, resolve real location +alias cd='cd -P' + +TERM +) >> "$HOME/.bashrc" + ;; + * ) + echo 'Skipping' + ;; +esac + +# ---------------------------------------------------------- + echo "----- Add symlink for ssh-ident as ssh --------------" read -p 'Add "ssh alias for ssh-ident"? (REQUIRES python) [y/N]: ' add_ident case $add_ident in diff --git a/pull-all.sh b/pull-all.sh index b57c994..a73b01c 100755 --- a/pull-all.sh +++ b/pull-all.sh @@ -26,10 +26,10 @@ fi # function to process each location function process_git_pull () { startedIn=`pwd` - location=$(dirname "$@") - echo -n "----- git pull $location " - printf "%*.*s" 0 $((40 - ${#location} )) "----------------------------------------" - echo "-----" + location=$(realpath $(dirname "$@")) + line="--- --- --- --- --- --- --- --- --- ---" + # use "--" to tell printf there are no more commands, only strings to print + printf -- "--- git pull %s %s ---\n" "$location" "${line:${#location}}" cd "$location" git pull --ff-only cd "$startedIn" diff --git a/status-all.sh b/status-all.sh new file mode 100755 index 0000000..c25d56b --- /dev/null +++ b/status-all.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# perform a "git status" on each location specified (recursively), or current location if none specified. +# git will quietly ignore any git repo stored in a folder you lack permission on. +# just listing current status of repos, +# +# will only search symbolic links when passed "-l" option, must be before any locations +# status-all.sh [-l] # current location implied +# status-all.sh [-l] ~/my-projects /var/group-projects + +# check for "-l" in command prompt +followLinks="-H" +while getopts "l" option; do + case $option in + l) + followLinks="-L" + ;; + esac +done +shift "$((OPTIND-1))" + +if [[ "-H" == "$followLinks" ]]; then + echo "use -l to follow symbolic links" +fi + +# function to process each location +function process_git_list () { + startedIn=$(pwd) + location=$(realpath $(dirname "$@")) + line="--- --- --- --- --- --- --- --- --- ---" + # use "--" to tell printf there are no more commands, only strings to print + printf -- "--- git status %s %s ---\n" "$location" "${line:${#location}}" + cd "$location" + output="" + info=$(git -c color.status=always status) + remote=$(git remote -vv) + upstream=$(git for-each-ref --format='%(upstream)' $(cat .git/HEAD)) + # 33 is yellow text + + # display any tracking issue, 43 is yellow background + if [[ "$remote" == "" ]]; then + output="$output\n *  no upstream repo " + elif [[ "$info" == *"HEAD detached at"* ]]; then + output="$output\n *  on detached head " + elif [[ "$upstream" == "" ]]; then + output="$output\n *  on untracked branch " + fi + + # various file statuses + if [[ "$info" == *"Changes to be committed"* ]]; then + # 42 is green background + output="$output\n *  has staged changes " + fi + if [[ "$info" == *"Changes not staged for commit"* ]]; then + # 41 is red background + output="$output\n *  has unstaged changes " + fi + if [[ "$info" == *"Untracked files"* ]]; then + # 31 is red text + output="$output\n *  has new files " + fi + + # various branch statuses + if [[ "$info" == *"branch is behind"* ]]; then + # 45 is magenta background + output="$output\n *  branch is behind " + fi + if [[ "$info" == *"branch is ahead"* ]]; then + # 46 is cyan background + output="$output\n *  branch is ahead " + fi + if [[ "$info" == *"nothing to commit, working tree clean"* ]]; then + # 90 is gray text + output="$output\n *  nothing to commit, working tree clean " + fi + + # fallback to displaying the full message + if [[ "$output" == "" ]]; then + output="\n$info" + fi + + # output is prefixed with "\n", skip it + printf "${output:2}\n" + cd "$startedIn" +} + +# find all folders named ".git" under given locations, +# and call process_git_list on each location that was found. +# we then work on the folder that contained the ".git" folder. + +find "$followLinks" "$@" -type d -name ".git" | while read -r file; do process_git_list "$file"; done +