Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions src/core/log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ clr () {
lower () {

local s="${1:-}"
printf '%s' "${s}" | tr '[:upper:]' '[:lower:]'
printf '%s' "${s,,}"

}
upper () {

local s="${1:-}"
printf '%s' "${s}" | tr '[:lower:]' '[:upper:]'
printf '%s' "${s^^}"

}
cap () {

local s="${1:-}"
printf '%s%s' "$(printf '%s' "${s:0:1}" | tr '[:lower:]' '[:upper:]')" "${s:1}"
printf '%s' "${s^}"

}

Expand All @@ -40,39 +40,36 @@ log () {
return 0

}
info () {
tint () {

local code="${1:-}" tag="${2:-}"
shift 2 >/dev/null 2>&1 || true

if clr; then printf '\033[96m[*]\033[0m %b\n' "$*" >&2
else printf '[*] %b\n' "$*" >&2
if clr; then printf '\033[%sm%s\033[0m %b\n' "${code}" "${tag}" "$*" >&2
else printf '%s %b\n' "${tag}" "$*" >&2
fi

return 0

}
succ () {
info () {

if clr; then printf '\033[32m[+]\033[0m %b\n' "$*" >&2
else printf '[+] %b\n' "$*" >&2
fi
tint 96 '[*]' "$*"

return 0
}
succ () {

tint 32 '[+]' "$*"

}
warn () {

if clr; then printf '\033[33m[!]\033[0m %b\n' "$*" >&2
else printf '[!] %b\n' "$*" >&2
fi

return 0
tint 33 '[!]' "$*"

}
err () {

if clr; then printf '\033[31m[-]\033[0m %b\n' "$*" >&2
else printf '[-] %b\n' "$*" >&2
fi

tint 31 '[-]' "$*"
return 1

}
Expand Down
4 changes: 2 additions & 2 deletions src/core/sys.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

has () {

[[ -n "${1:-}" ]] || { err "Missing binary name"; return; }
[[ -n "${1:-}" ]] || return 1

command -v "${1}" >/dev/null 2>&1
command -v -- "${1}" >/dev/null 2>&1

}
need () {
Expand Down
10 changes: 5 additions & 5 deletions src/mod/github/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ repo () {

[[ "${name}" == */* ]] && { out "${name}"; return; }

login="$(gh api user -q .login 2>/dev/null)" || { err "Failed to detect Github user"; return; }
login="$(gh api user -q .login 2>/dev/null)" \
|| { err "Failed to detect GitHub user"; return; }

[[ -n "${login}" ]] || { err "Failed to detect Github user"; return; }
[[ -n "${login}" ]] || { err "Failed to detect GitHub user"; return; }

out "${login}/${name}"

Expand Down Expand Up @@ -93,10 +94,9 @@ diffs () {
need git || return

isrepo || { err "Not a git repository"; return; }
local target="${1:-}" mode="${2:-}"
local target="${1:-}"

shift >/dev/null 2>&1 || true
[[ "${mode}" == --* ]] && { shift >/dev/null 2>&1 || true; }

case "${target}" in
""|work|working|unstaged) git diff "$@" ;;
Expand All @@ -120,7 +120,7 @@ owner () {
name="$(repo "${name}")" || return
owner="${name%%/*}"
else
owner="$(gh api user -q .login 2>/dev/null)" || { err "Failed to detect GitHub user"; return; }
owner="$(gh api user -q .login 2>/dev/null)" || { err "Failed to detect GitHub owner"; return; }
fi

[[ -n "${owner}" ]] || owner="${GITHUB_OWNER:-}"
Expand Down
14 changes: 7 additions & 7 deletions src/mod/github/branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ del-branch () {

need git || return

local name="${1:-}" force="${2:-0}" current=""
local name="${1:-}" force="${2:-0}" current="" local_ok=0 remote_ok=0

shift >/dev/null 2>&1 || true
[[ $# -gt 0 ]] && { shift >/dev/null 2>&1 || true; }
Expand All @@ -77,11 +77,13 @@ del-branch () {

[[ "${name}" != "${current}" ]] || { err "Cannot delete current branch: ${name}"; return; }

if bool "${force}" force f; then git branch -D "${name}" >/dev/null 2>&1 || true
else git branch -d "${name}" >/dev/null 2>&1 || true
if bool "${force}" force f; then git branch -D "${name}" >/dev/null 2>&1 && local_ok=1
else git branch -d "${name}" >/dev/null 2>&1 && local_ok=1
fi

git push origin --delete "${name}" "$@" >/dev/null 2>&1 || true
git push origin --delete "${name}" "$@" >/dev/null 2>&1 && remote_ok=1

(( local_ok || remote_ok )) || { err "Branch not found: ${name}"; return; }

succ "Branch deleted -> ${name}"

Expand All @@ -90,9 +92,7 @@ del-branch () {
current-branch () {

need git || return

git branch --show-current "$@" 2>/dev/null \
|| { err "Failed to detect current branch"; return; }
git branch --show-current "$@" 2>/dev/null || { err "Failed to detect current branch"; return; }

}
default-branch () {
Expand Down
8 changes: 4 additions & 4 deletions src/mod/github/cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ clear-cache () {

need gh || return

local id="" out=""
local id="" caches=""
local -a ids=()

out="$(gh cache list --limit 1000 --json id -q '.[].id' "$@")" \
caches="$(gh cache list --limit 1000 --json id -q '.[].id' "$@")" \
|| { err "Failed to list caches"; return; }

[[ -n "${out}" ]] || { warn "No caches found"; return; }
[[ -n "${caches}" ]] || { warn "No caches found"; return; }

mapfile -t ids <<< "${out}"
mapfile -t ids <<< "${caches}"

for id in "${ids[@]}"; do

Expand Down
8 changes: 4 additions & 4 deletions src/mod/github/gist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ gists () {
local limit="100"

if [[ "${1:-}" =~ ^[0-9]+$ ]]; then

limit="${1}"
shift

fi

gh gist list --limit "${limit}" "$@" | sed '/^[[:space:]]*$/d' | wc -l | tr -d ' '
gh gist list --limit "${limit}" --json id -q 'length' "$@"

}

gist-new () {

need gh || return

[[ $# -gt 0 ]] || { err "Missing gist file or content"; return; }

gh gist create "$@" \
|| { err "Failed to create gist"; return; }
gh gist create "$@" || { err "Failed to create gist"; return; }

}
gist-open () {
Expand Down
43 changes: 19 additions & 24 deletions src/mod/github/info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,29 @@ repo-info () {

need gh || return

local name="${1:-}"
local name="${1:-}" fields=""
shift >/dev/null 2>&1 || true

name="$(repo "${name}")" || return

gh repo view "${name}" \
--json \
nameWithOwner,description,url,visibility,isPrivate,isFork,isArchived,stargazerCount,forkCount,\
openGraphImageUrl,createdAt,updatedAt,pushedAt,defaultBranchRef,licenseInfo \
"$@" 2>/dev/null \
fields="nameWithOwner,description,url,visibility,isPrivate,isFork,isArchived,stargazerCount,forkCount,openGraphImageUrl,createdAt,updatedAt,pushedAt,defaultBranchRef,licenseInfo"

gh repo view "${name}" --json "${fields}" "$@" 2>/dev/null \
|| { err "Failed to get repository info: ${name}"; return; }

}
repo-health () {

need gh || return

local name="${1:-}"
local name="${1:-}" fields=""
shift >/dev/null 2>&1 || true

name="$(repo "${name}")" || return

gh repo view "${name}" \
--json \
nameWithOwner,description,url,visibility,isPrivate,isFork,\
isArchived,stargazerCount,forkCount,\
createdAt,updatedAt,pushedAt,defaultBranchRef,licenseInfo \
"$@" 2>/dev/null \
fields="nameWithOwner,description,url,visibility,isPrivate,isFork,isArchived,stargazerCount,forkCount,createdAt,updatedAt,pushedAt,defaultBranchRef,licenseInfo"

gh repo view "${name}" --json "${fields}" "$@" 2>/dev/null \
|| { err "Failed to get repository health: ${name}"; return; }

}
Expand Down Expand Up @@ -222,18 +217,18 @@ discs () {
}
collabs () {

local out=""
local collab_items=""

out="$(collab-list "$@")" || return
printf '%s\n' "${out}" | sed '/^[[:space:]]*$/d' | wc -l | tr -d ' '
collab_items="$(collab-list "$@")" || return
printf '%s\n' "${collab_items}" | sed '/^[[:space:]]*$/d' | wc -l | tr -d ' '

}
contribs () {

local out=""
local contrib_items=""

out="$(contrib-list "$@")" || return
printf '%s\n' "${out}" | sed '/^[[:space:]]*$/d' | wc -l | tr -d ' '
contrib_items="$(contrib-list "$@")" || return
printf '%s\n' "${contrib_items}" | sed '/^[[:space:]]*$/d' | wc -l | tr -d ' '

}
languages () {
Expand All @@ -243,12 +238,12 @@ languages () {
}
topics () {

local out=""
local topic_items=""

out="$(topic-list "$@")" || return
[[ -n "${out}" ]] || { out 0; return; }
topic_items="$(topic-list "$@")" || return
[[ -n "${topic_items}" ]] || { out 0; return; }

printf '%s\n' "${out}" | wc -l | tr -d ' '
printf '%s\n' "${topic_items}" | wc -l | tr -d ' '

}
stars () {
Expand All @@ -264,6 +259,6 @@ stars () {
}
views () {

view-list "$@" --jq '.count'
view-list "" --jq '.count' "$@"

}
26 changes: 23 additions & 3 deletions src/mod/github/issue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ issue-list () {
if [[ -n "${name}" && "${name}" != --* && "${name}" != [0-9]* ]]; then

shift >/dev/null 2>&1 || true
[[ "${state}" == --* ]] && state="open" || shift >/dev/null 2>&1 || true

if [[ "${state}" == --* ]]; then state="open"
else shift >/dev/null 2>&1 || true
fi

name="$(repo "${name}")" || return
gh issue list --repo "${name}" --state "${state}" "$@"
Expand All @@ -29,7 +32,10 @@ issues () {
if [[ -n "${name}" && "${name}" != --* && "${name}" != [0-9]* ]]; then

shift >/dev/null 2>&1 || true
[[ "${state}" == --* ]] && state="open" || shift >/dev/null 2>&1 || true

if [[ "${state}" == --* ]]; then state="open"
else shift >/dev/null 2>&1 || true
fi

name="$(repo "${name}")" || return
gh issue list --repo "${name}" --state "${state}" --json number -q 'length' "$@"
Expand All @@ -41,7 +47,6 @@ issues () {
gh issue list --json number -q 'length' "$@"

}

issue-open () {

need gh || return
Expand Down Expand Up @@ -122,3 +127,18 @@ issue-comment () {
succ "Issue commented: ${id}"

}
issue-delete () {

need gh || return

local id="${1:-}"
shift >/dev/null 2>&1 || true

[[ -n "${id}" ]] || { err "Missing issue number or url"; return; }

gh issue delete "${id}" "$@" \
|| { err "Failed to delete issue: ${id}"; return; }

succ "Issue deleted: ${id}"

}
11 changes: 8 additions & 3 deletions src/mod/github/prs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ pr-list () {
if [[ -n "${name}" && "${name}" != --* && "${name}" != [0-9]* ]]; then

shift >/dev/null 2>&1 || true
[[ "${state}" == --* ]] && state="open" || shift >/dev/null 2>&1 || true

if [[ "${state}" == --* ]]; then state="open"
else shift >/dev/null 2>&1 || true
fi

name="$(repo "${name}")" || return
gh pr list --repo "${name}" --state "${state}" "$@"
Expand All @@ -29,7 +32,10 @@ prs () {
if [[ -n "${name}" && "${name}" != --* && "${name}" != [0-9]* ]]; then

shift >/dev/null 2>&1 || true
[[ "${state}" == --* ]] && state="open" || shift >/dev/null 2>&1 || true

if [[ "${state}" == --* ]]; then state="open"
else shift >/dev/null 2>&1 || true
fi

name="$(repo "${name}")" || return
gh pr list --repo "${name}" --state "${state}" --json number -q 'length' "$@"
Expand All @@ -41,7 +47,6 @@ prs () {
gh pr list --json number -q 'length' "$@"

}

pr-open () {

need gh || return
Expand Down
Loading