From 2bf4e928dd43f3a864a3a6637de3f1bba02bff47 Mon Sep 17 00:00:00 2001 From: Luke Tidd Date: Fri, 18 Nov 2022 16:45:01 -0500 Subject: [PATCH] detect project from leaf dir if no project specified --- gclone | 6 ++++-- gpull | 24 ++++++++++++------------ gpush | 26 +++++++++++++------------- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/gclone b/gclone index d16cd0f..a1fac87 100755 --- a/gclone +++ b/gclone @@ -8,9 +8,12 @@ fi project="$1" shift + token="$(pass show gitea/token/${project})" if [[ -z "$token" ]]; then - printf 'Failed to get token.\n' + printf 'Failed to get token for %s. ' "$project" >&2 + print 'Must be one of:\n\n' "$project" >&2 + pass show gitea/token >&2 exit 1 fi token_url="https://luke:${token}@git.drheck.dev/luke/${project}.git" @@ -37,4 +40,3 @@ else git remote remove origin git push --set-upstream "$url" main fi - diff --git a/gpull b/gpull index 88ea230..8eb8510 100755 --- a/gpull +++ b/gpull @@ -1,31 +1,31 @@ #!/bin/bash if [[ -z "$1" ]]; then - printf 'Need a project:\n\n' >&2 - pass show gitea/token >&2 - exit 1 + project="$(basename $(pwd))" +else + project="$1" + shift fi - -gpg_key='75D6600BEF4E8E8F' -git config user.signingkey "$gpg_key"! -git config commit.gpgsign true - -project="$1" -shift -unset token token="$(pass show gitea/token/${project})" if [[ -z "$token" ]]; then - printf 'Failed to get token.\n' + printf 'Failed to get token for %s. ' "$project" >&2 + print 'Must be one of:\n\n' "$project" >&2 + pass show gitea/token >&2 exit 1 fi url="https://luke:${token}@git.drheck.dev/luke/${project}.git" if [[ "$project" == 'pass' ]]; then + pass git config user.signingkey "$gpg_key"! + pass git config commit.gpgsign true if [[ -n "$@" ]]; then pass git pull "$@" "$url" else pass git pull "$url" fi else + gpg_key='75D6600BEF4E8E8F' + git config user.signingkey "$gpg_key"! + git config commit.gpgsign true if [[ -n "$@" ]]; then git pull "$@" "$url" else diff --git a/gpush b/gpush index a1adc02..361e3e0 100755 --- a/gpush +++ b/gpush @@ -1,31 +1,31 @@ #!/bin/bash if [[ -z "$1" ]]; then - printf 'Need a project:\n\n' >&2 + project="$(basename $(pwd))" +else + project="$1" + shift +fi +token="$(pass show gitea/token/${project})" +if [[ -z "$token" ]]; then + printf 'Failed to get token for %s. ' "$project" >&2 + print 'Must be one of:\n\n' "$project" >&2 pass show gitea/token >&2 exit 1 fi - -project="$1" -shift -unset token -token="$(pass show gitea/token/${project})" -if [[ -z "$token" ]]; then - printf 'Failed to get token.\n' - exit 1 -fi gpg_key='75D6600BEF4E8E8F' -git config user.signingkey "$gpg_key"! -git config commit.gpgsign true - url="https://luke:${token}@git.drheck.dev/luke/${project}.git" if [[ "$project" == 'pass' ]]; then + pass git config user.signingkey "$gpg_key"! + pass git config commit.gpgsign true if [[ -n "$@" ]]; then pass git push "$@" "$url" else pass git push "$url" fi else + git config user.signingkey "$gpg_key"! + git config commit.gpgsign true if [[ -n "$@" ]]; then git push "$@" "$url" else