diff --git a/README.md b/README.md index cff6059..1f6df86 100644 --- a/README.md +++ b/README.md @@ -76,10 +76,17 @@ will create the symbolic link for each script in the \ directory. - [doctools2man](doctools2man) converts doctool to man pages. - [robodoc2html](robodoc2html) converts a documentation in the robodoc format into html. -- [getignore](getignore) stores files with '+GITIGNORE' marks into .gitignore file. -- [forks](forks) shows the latest forks of github repository. - [utable](utable) shows a Unicode table. +### Git + +- [git-aliases](git-aliases) shows a commented list of all git aliases. +- [git-forks](git-forks) shows the latest forks of github repository. +- [git-graphviz](git-graphviz) creates dot-graph of a git repository. +- [git-ignore](git-ignore) gets specified gitignore settings from [https://gitignore.io/](https://gitignore.io/) website. +- [git-makeignore](git-makeignore) stores files with '+GITIGNORE' marks into .gitignore file. +- [git-top](git-top) shows the most edited files in current git repository. + ## WM - [calculator](calculator) computes mathematical expressions with variables and intermediate values. diff --git a/forks b/forks deleted file mode 100755 index 419c2ca..0000000 --- a/forks +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -#Создан: вт 15 окт 2019 11:15:12 -#Изменён: вт 15 окт 2019 21:31:41 - -API="https://api.github.com/repos/" - -last_forks() { - curl -sq "${API}${1}/forks?sort=stargazers&per_page=100" \ - | jq -r '.[] | "\(.updated_at) \(.full_name)"' 2>&- \ - | sed "s|^| |; s|T| |; s|Z | https://github.com/|" \ - | sort -r \ - | head -n "${2:-15}" -} - -repository="${1?"USAGE $(basename "$0") user/repository ?top?"}" - -last_forks "$repository" "$2" - diff --git a/git-aliases b/git-aliases new file mode 100755 index 0000000..71ccf6d --- /dev/null +++ b/git-aliases @@ -0,0 +1,42 @@ +#!/bin/bash + +#Создан: чт 14 ноя 2019 14:03:43 +#Изменён: чт 14 ноя 2019 17:34:38 + +# Список псевдонимов git + +# +# Формат: +# +# # Комментарий +# name = function +# +# Игнорирование в выводе: +# +# # noindex Комментарий +# или +# name = function #noindex +# + +green="\033[1;32m" +rstc="\033[00m" + +GITCONFIG=~/.gitconfig + +GIT_ALIASES=$(git config --get-regexp 'alias.*' | sed 's/alias.//' | sed 's/ .*//') + +while read -r alias; do + line=$(\grep -n -E "^\s*${alias}\s+" "$GITCONFIG") + + number=${line/:*} + full_alias=${line/*:} + + name=$(sed "s/^[[:space:]]*//; s/=.*$//g; ${number}q;d" $GITCONFIG) + + commentary=$(sed "s/[[:space:]]*# //; $((--number))q;d" $GITCONFIG) + + if [[ ! "$full_alias" =~ "noindex" ]] && [[ ! "$commentary" =~ "noindex" ]]; then + printf " • ${green}%-15s${rstc}- %s\n" "$name" "$commentary" + fi +done <<<"$GIT_ALIASES" + diff --git a/git-forks b/git-forks new file mode 100755 index 0000000..9d141a8 --- /dev/null +++ b/git-forks @@ -0,0 +1,26 @@ +#!/bin/bash + +#Создан: вт 15 окт 2019 11:15:12 +#Изменён: чт 14 ноя 2019 17:35:25 + +# Список форков репозитория на github.com, +# отсортированный на основе времени последних изменений + +API="https://api.github.com/repos/" + +last_forks() { + curl -sq "${API}${1}/forks?sort=stargazers&per_page=100" \ + | jq -r '.[] | "\(.updated_at) \(.full_name)"' 2>&- \ + | sed "s|^| |; s|T| |; s|Z | https://github.com/|" \ + | sort -r \ + | head -n "$2" +} + +if [ -z "$1" ]; then + repository=$(git url | grep github.com | sed -e 's|^.*github.com/||' | sed 's/.git.*$//') +else + repository="$1" +fi + +last_forks "$repository" "${2:-15}" + diff --git a/git-graphviz b/git-graphviz new file mode 100755 index 0000000..f617d53 --- /dev/null +++ b/git-graphviz @@ -0,0 +1,17 @@ +#!/bin/bash + +# Создание графа коммитов git-репозитория + +# This produces output that can be displayed using dotty, for example: +# $ git graphviz HEAD~100..HEAD~60 | dotty /dev/stdin +# $ git graphviz --first-parent master | dotty /dev/stdin +# Note how defining a function eliminates the need to use sh -c. + +make_graphviz() { + echo 'digraph git {' + git log --pretty='format: %h -> { %p }' "$@" | sed 's/[0-9a-f][0-9a-f]*/\"&\"/g' + echo '}' +} + +make_graphviz "$@" + diff --git a/git-ignore b/git-ignore new file mode 100755 index 0000000..402c769 --- /dev/null +++ b/git-ignore @@ -0,0 +1,43 @@ +#!/bin/bash + +# Получение шаблона gitignore с сайта gitignore.io + +ROOT=$(git root 2>&-) + +TYPES=() + +while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + -w|--write) + WRITE=1 + shift + ;; + *) + TYPES+=("$1") + shift + ;; + esac +done + +set -- "${TYPES[@]}" + +if [ "${#TYPES[@]}" -gt 0 ]; then + for t in "${TYPES[@]}"; do + if [ -n "$WRITE" ] && [ -n "$ROOT" ]; then + echo "# $t" + curl -sq "https://gitignore.io/api/${t}" >> "$(git root)/.gitignore" + else + curl -sq "https://gitignore.io/api/${t}" + fi + done + + if [ -n "$WRITE" ] && [ -n "$ROOT" ]; then + echo "Ignoring list saved to ${ROOT}/.gitignore file." + fi +else + echo "USAGE: $(basename "$0") [-w/--write] type1 type2 [...]" + exit 1 +fi + diff --git a/getignore b/git-makeignore similarity index 100% rename from getignore rename to git-makeignore diff --git a/git-top b/git-top new file mode 100755 index 0000000..1af6569 --- /dev/null +++ b/git-top @@ -0,0 +1,12 @@ +#!/bin/bash + +# Наиболее часто изменяемые файлы git-репозитория + +git log --all -M -C --name-only --format='format:' "$@" \ + | grep . \ + | sort \ + | uniq -c \ + | sort -rn \ + | head -n 20 \ + | sed -e 's/^ //' +