diff options
-rwxr-xr-x | bin/common/askpass | 5 | ||||
-rwxr-xr-x | bin/common/gt | 16 | ||||
-rwxr-xr-x | bin/common/gt-cmd | 16 | ||||
-rwxr-xr-x | bin/common/gt-st | 3 | ||||
-rw-r--r-- | config/essentials/shell/functions.sh | 16 | ||||
-rw-r--r-- | config/extra/mutt/muttrc | 1 |
6 files changed, 43 insertions, 14 deletions
diff --git a/bin/common/askpass b/bin/common/askpass index c7d2249..ebd833c 100755 --- a/bin/common/askpass +++ b/bin/common/askpass @@ -12,6 +12,5 @@ key="$(printf '%s\n' "$1" | pass="keys/$(hostname)/ssh/$key" # optional: add key to running ssh-agent -keyadd "$key" & - -pass show "$pass" | head -n 1 +keyadd "$key" && + pass show "$pass" | head -n 1 diff --git a/bin/common/gt b/bin/common/gt index 8df4947..d2ae3e5 100755 --- a/bin/common/gt +++ b/bin/common/gt @@ -8,9 +8,9 @@ # - parallel: optional, if installed will run the commands on all repos with parallel # - gt-cmd, gt-st -repos=$HOME/sync/share/git-track.txt +export REPOS=$HOME/sync/share/git-track.txt # prevent file not found errors -touch "$repos" || exit 1 +touch "$REPOS" || exit 1 which parallel >/dev/null 2>&1 && parallel=1 @@ -28,7 +28,7 @@ usage: gt [OPTION] EOF } -list_repos() { cut -f 1 -d ' ' "$repos"; } +list_repos() { cut -f 1 -d ' ' "$REPOS"; } # fetch repository prettily, outputs nothing if failed fetch() { @@ -44,7 +44,7 @@ if [ -z "$1" ]; then exit 1 fi -[ "$(wc -l <"$repos")" -gt 0 ] || exit 0 +[ "$(wc -l <"$REPOS")" -gt 0 ] || exit 0 while getopts ":a:c:f:lsheu" opt; do case "$opt" in @@ -57,12 +57,12 @@ while getopts ":a:c:f:lsheu" opt; do repo="$(git rev-parse --show-toplevel)" remote_url="$(git remote show -n origin | awk '/^ Fetch/ {print $NF}')" - if grep "^$repo " "$repos" >/dev/null 2>&1; then + if grep "^$repo " "$REPOS" >/dev/null 2>&1; then printf >&2 'added already.\n' exit 3 fi - printf '%s %s\n' "$repo" "$remote_url" >>"$repos" + printf '%s %s\n' "$repo" "$remote_url" >>"$REPOS" printf >&2 'added.\n' ;; @@ -76,8 +76,8 @@ while getopts ":a:c:f:lsheu" opt; do ;; s) list_repos | xargs -I{} gt-st {} ;; l) list_repos ;; - e) $EDITOR "$repos" ;; - f) repos="$OPTARG" ;; + e) $EDITOR "$REPOS" ;; + f) REPOS="$OPTARG" ;; u) >&2 printf 'pull:\n' if [ "$parallel" ]; then diff --git a/bin/common/gt-cmd b/bin/common/gt-cmd index faa743a..bc5c9c9 100755 --- a/bin/common/gt-cmd +++ b/bin/common/gt-cmd @@ -11,10 +11,24 @@ args="$*" repo_pretty="$(printf '%s' "$repo" | sed "s@^$HOME@~@")" if [ ! -d "$repo" ]; then - printf '%s missing\n' "$repo_pretty" + printf '%s: missing\n' "$repo_pretty" exit 1 fi +# Check if repo's remote's key is in ssh-agent +# If key is not registered and command is push/pull we exit with error +r="$(grep "$repo" "$REPOS" | cut -f 2 -d ' ' | cut -f 2 -d '@' | cut -f 1 -d ':')" +if { [ "$command" = "push" ] || [ "$command" = "pull" ]; } && + # In my ssh config every Host has the same name as its private key. This means remotes in + # "$REPOS" (here "$r") + .pub is the public key, so we convert the name to what would be the + # public key's name and check if its contents are registered in the ssh-agent. + [ -r "$HOME/.ssh/$r.pub" ] && + ! ssh-add -L | grep "$(cat "$HOME/.ssh/$r.pub")" > /dev/null +then + printf '%s: key not added\n' "$repo_pretty" + exit 1 +fi + git -C "$repo" "$command" $args >/dev/null 2>&1 [ $? -gt 0 ] && s="x" || s="o" printf '%s: %s\n' "$repo_pretty" "$s" diff --git a/bin/common/gt-st b/bin/common/gt-st index 43443cd..e4bd59e 100755 --- a/bin/common/gt-st +++ b/bin/common/gt-st @@ -1,8 +1,9 @@ #!/bin/sh +# gt-st # Print status of the repo locally +# $1: path to repo -# path to repo repo="$1" [ "$1" ] || exit 1 diff --git a/config/essentials/shell/functions.sh b/config/essentials/shell/functions.sh index d18a188..1413fd8 100644 --- a/config/essentials/shell/functions.sh +++ b/config/essentials/shell/functions.sh @@ -350,7 +350,7 @@ nvim_bindings() { prj () { pfx="$HOME/proj" d="$(find "$pfx" -mindepth 1 -maxdepth 1 -type d | sed "s@$pfx/@@" |fzf)" - [ -d "$pfx/$d" ] || exit 1 + [ -d "$pfx/$d" ] || return 1 cd "$pfx/$d" } @@ -360,3 +360,17 @@ edit_git_file () { [ "$f" ] || return 2 $EDITOR "$1"/"$f" } + +# Wrapper to automatically add the key +# could have been alias='SSH_ASKPASS=askpass SSH_ASKPASS_REQUIRE=prefer ssh' +# but this option is very slow for some reason +ssh() { + for arg in $@; do + if grep "Host $arg\s*\$" ~/.ssh/config > /dev/null 2>&1 ; + then + keyadd "$arg" 2> /dev/null + break + fi + done + /usr/bin/ssh $@ +} diff --git a/config/extra/mutt/muttrc b/config/extra/mutt/muttrc new file mode 100644 index 0000000..6554188 --- /dev/null +++ b/config/extra/mutt/muttrc @@ -0,0 +1 @@ +source /home/aluc/.config/mutt/configs/luca@spacehb.net.muttrc |