Debian Codegraph @

cmake/tribits/python_utils/gitdist-setup.sh

raw
1 #
2 # Bash setup gitdist and commandline completion
3 #
4 # Usage:
5 #
6 # source <base-dir>/gitdist-setup.sh
7 #
8 # First, this script, when sourced, will create an alias for gitdist to the
9 # gitdist script in the same directory where this script resides if 'gitdist'
10 # is not already in the path. (This just makes it easy to get 'gitdist' in
11 # your path.)
12 #
13 # Second, this script sets up commandline completion for the gitdist command
14 # the same as for the git command. So, if you have sourced the script
15 # git-completion.bash before sourcing this script, then gitdist will get all
16 # of the same commandline command and argument completions as the git command.
17 # In addition, it adds commandline completions for the additional gitdist
18 # commands and options (e.g. dist-repo-status, --dist-mod-only, --dist-repos,
19 # etc.).
20 #
21 # Third, this script sets up bash functions and alias for:
22 #
23 # gitdist-status Show repo status table
24 # gitdist-mod Run gitdist only on modified repos
25 # gitdist-mod-status Show status table for only modified repos
26 # gitdist-repo-versions Show repo version info (for --dist-version-file)
27 # gitdist-show-full-repo-state Full repo state (status table, versions, remotes)
28 #
29
30 # Assert this script is sourced, not run!
31 called=$_
32 if [ "$called" == "$0" ] ; then
33 echo "This script '$0' is being called. Instead, it must be sourced!"
34 exit 1
35 fi
36
37 # Get the base dir for the sourced script
38 SCRIPT_DIR=`echo $BASH_SOURCE | sed "s/\(.*\)\/.*\.sh/\1/g"`
39 #echo "SCRIPT_DIR = '$SCRIPT_DIR'"
40
41 existing_gitdist=`which gitdist 2> /dev/null`
42 if [[ "${existing_gitdist}" == "" ]] ; then
43 alias gitdist=${SCRIPT_DIR}/gitdist
44 fi
45
46 function gitdist_repo_versions {
47 gitdist "$@" --dist-no-color log --color=never -1 --pretty=format:"%H [%cd] <%ae>%n%s" | grep -v "^$"
48 }
49 export -f gitdist_repo_versions
50
51 function gitdist_show_full_repo_state {
52 echo
53 echo "Repo versions:"
54 echo
55 gitdist_repo_versions "$@"
56 echo
57 echo "Repo branch status:"
58 echo
59 gitdist dist-repo-status "$@" | grep -v "^$" | grep -v "(tip: to see a legend"
60 echo
61 echo "Repo remotes:"
62 echo
63 gitdist --dist-no-color "$@" remote -v | grep --color=never "\(Git Repo\|push\)"
64 }
65 export -f gitdist_show_full_repo_state
66
67 # Source this with bash to load useful env for using gitdist
68 alias gitdist-status="gitdist dist-repo-status"
69 alias gitdist-mod="gitdist --dist-mod-only"
70 alias gitdist-mod-status="gitdist --dist-mod-only dist-repo-status"
71 alias gitdist-repo-versions=gitdist_repo_versions
72 alias gitdist-show-full-repo-state=gitdist_show_full_repo_state
73
74 # Setup for completions for git command and gitdist options commands
75 complete -o default -o nospace -F _git \
76 -W "dist-repo-status --dist-help --dist-use-git --dist-repos --dist-not-repos --dist-version-file --dist-version-file2 --dist-no-color --dist-debug --dist-no-opt --dist-mod-only" \
77 gitdist gitdist-mod
78 complete -o default -o nospace \
79 -W "--dist-use-git --dist-repos --dist-not-repos --dist-mod-only" \
80 gitdist_repo_versions gitdist-repo-versions
81 complete -o default -o nospace \
82 -W "--dist-use-git --dist-repos --dist-not-repos --dist-mod-only" \
83 gitdist_show_full_repo_state gitdist-show-full-repo-state
84 complete -o default -o nospace \
85 -W "--dist-repos --dist-not-repos --dist-mod-only --dist-legend" \
86 gitdist-status