diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/common/gt | 138 | ||||
-rwxr-xr-x | bin/guiscripts/stplumb | 29 | ||||
-rwxr-xr-x | bin/guiscripts/sturl | 11 |
3 files changed, 103 insertions, 75 deletions
diff --git a/bin/common/gt b/bin/common/gt index ceb58a8..b86ccc6 100755 --- a/bin/common/gt +++ b/bin/common/gt @@ -4,14 +4,14 @@ # dependencies: # - git -# - $EDITOR: -e +# - $EDITOR: -e repos=$HOME/sync/share/git-track.txt # prevent file not found errors touch "$repos" help() { - >&2 cat <<EOF + cat >&2 <<EOF usage: gt [OPTION] -a PATH add repo -s update and show status of each repo @@ -25,97 +25,107 @@ EOF # fetch repository prettily, outputs nothing if failed fetch() { # fetch with one-line printing of progress - git fetch --progress 2>/dev/null | while read -r line - # \r\033[0K : clear current line - do >&2 printf '\r\033[0K%s' "$line" - done + git fetch --progress 2>/dev/null | while read -r line; do # \r\033[0K : clear current line + printf >&2 '\r\033[0K%s' "$line" + done } # Print repositories prettily # This function function prints animations (eg. clearing the line) # to stderr and the final status line is outputted to stdout. status() { - while read -r repo - do - repo_pretty="$(printf '%s' "$repo" | sed "s@$HOME@~@" )" + while read -r repo; do + repo_pretty="$(printf '%s' "$repo" | sed "s@$HOME@~@")" - # absolute path - cd "$repo" + if [ ! -d "$repo" ]; then + printf '%s missing\n' "$repo_pretty" + continue + fi - # replace line with status - >&2 printf '\r\033[0K' + # absolute path + cd "$repo" - status="$(git status --porcelain 2> /dev/null | awk '{print $1}' | uniq | tr -d '\n')" - remote="$(git branch -v 2>/dev/null | - sed '/^*/!d;s/ahead/↑/;s/behind/↓/;s/[^↓↑]*//g')" + # replace line with status + printf >&2 '\r\033[0K' - printf '%s %s %s\n' "$repo_pretty" "$status" "$remote" - done < "$repos" + status="$(git status --porcelain 2>/dev/null | + awk '{print $1}' | + sort | uniq | tr -s '?' | + tr -d '\n')" + remote="$(git branch -v 2>/dev/null | + sed '/^*/!d;s/ahead/↑/;s/behind/↓/;s/[^↓↑]*//g')" + + printf '%s %s %s\n' "$repo_pretty" "$status" "$remote" + done <"$repos" } # run git command in each repo # $1: command repos_cmd() { - while read -r repo - do - repo_pretty="$(printf '%s' "$repo" | sed "s@$HOME@~@" )" - printf ''\''%s'\'' in %s' "$1" "$repo_pretty" - ( - cd "$repo" - git "$1" > /dev/null 2>&1 - [ $? -gt 0 ] && s="x" || s="o" - printf '\r\033[0K%s: %s\n' "$repo_pretty" "$s" - ) - done < "$repos" + while read -r repo; do + repo_pretty="$(printf '%s' "$repo" | sed "s@$HOME@~@")" + printf ''\''%s'\'' in %s' "$1" "$repo_pretty" + ( + cd "$repo" + git "$1" >/dev/null 2>&1 + [ $? -gt 0 ] && s="x" || s="o" + printf '\r\033[0K%s: %s\n' "$repo_pretty" "$s" + ) + done <"$repos" } # no options -if [ -z "$1" ] -then - help - exit 1 +if [ -z "$1" ]; then + help + exit 1 fi -while getopts ":a:c:f:lshe" opt -do +while getopts ":a:c:f:lshe" opt; do case "$opt" in - a) - cd "$OPTARG" || exit 1 - r="$(git rev-parse --show-toplevel)" - [ "$r" ] || exit 2 - - if grep "$r" "$repos" > /dev/null 2>&1 - then - >&2 printf 'added already.\n' - exit 2 - fi - - printf '%s\n' "$r" >> "$repos" - - >&2 printf 'added.\n' ;; - c) f_command=1; f_arg="$OPTARG" ;; - s) f_status=1 ;; - l) cat "$repos" ;; - e) $EDITOR "$repos" ;; - f) repos="$OPTARG" ;; - h) help ;; - :) >&2 printf -- '-%s requires argument\n' "$OPTARG"; exit 1 ;; - ?) >&2 printf -- 'Invalid option: -%s\n' "$OPTARG"; exit 1 ;; + a) + cd "$OPTARG" || exit 1 + r="$(git rev-parse --show-toplevel)" + [ "$r" ] || exit 2 + + if grep "$r" "$repos" >/dev/null 2>&1; then + printf >&2 'added already.\n' + exit 2 + fi + + printf '%s\n' "$r" >>"$repos" + + printf >&2 'added.\n' + ;; + c) + f_command=1 + f_arg="$OPTARG" + ;; + s) f_status=1 ;; + l) cat "$repos" ;; + e) $EDITOR "$repos" ;; + f) repos="$OPTARG" ;; + h) help ;; + :) + printf >&2 -- '-%s requires argument\n' "$OPTARG" + exit 1 + ;; + ?) + printf >&2 -- 'Invalid option: -%s\n' "$OPTARG" + exit 1 + ;; esac done # commands hereafter must happen in order -[ "$(wc -l < "$repos")" -gt 0 ] || exit 0 +[ "$(wc -l <"$repos")" -gt 0 ] || exit 0 -if [ "$f_command" ] -then +if [ "$f_command" ]; then repos_cmd "$f_arg" -fi +fi -if [ "$f_status" ] -then - status +if [ "$f_status" ]; then + status fi # eval "herbe $(status | sed 's/"/\"/g;s/.*/"&"/' | tr '\n' ' ')" diff --git a/bin/guiscripts/stplumb b/bin/guiscripts/stplumb new file mode 100755 index 0000000..1898bd1 --- /dev/null +++ b/bin/guiscripts/stplumb @@ -0,0 +1,29 @@ +#!/bin/sh + +select_link() { + regex='(((file|https?|gopher|gemini|ftps?|git)://|www\.)[a-zA-Z0-9.]*[:;!a-zA-Z0-9./+@$&%?$\#=_~-]*)|(magnet:\?xt=urn:btih:[a-zA-Z0-9]*)' + tr -d '\n' | grep -Eo "$regex" | dmenu -n -x -c +} + +case $1 in +'copylink') + url="$(select_link)" + [ "$url" ] || exit 1 + printf '%s' "$url" | clipp + ;; +'open') + url="$(select_link)" + [ "$url" ] || exit 1 + lh "$url" + ;; +'copypath') + path="$(grep -Eo -e '/([^/ ](/?)+)+' -e '[^ /]+/+([^ /]+(/?)+)*' | + sort | uniq | dmenu -n -x -c)" + [ "$path" ] || exit 1 + printf '%s' "$path" | clipp + ;; +*) + echo "no option" + exit 1 + ;; +esac diff --git a/bin/guiscripts/sturl b/bin/guiscripts/sturl deleted file mode 100755 index 2712d92..0000000 --- a/bin/guiscripts/sturl +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -regex='(((file|https?|gopher|gemini|ftps?|git)://|www\.)[a-zA-Z0-9.]*[:;!a-zA-Z0-9./+@$&%?$\#=_~-]*)|(magnet:\?xt=urn:btih:[a-zA-Z0-9]*)' -url="$(tr -d '\n' | grep -Eo "$regex" | commander -xcl)" -[ -z "$url" ] && exit 1 - -case $1 in - 'c') printf '%s' "$url" | clipp ;; - 'o') lh "$url" ;; - *) echo "no option" ;; -esac |