summaryrefslogtreecommitdiff
path: root/shell-scripts
diff options
context:
space:
mode:
authorMike Vink <mike1994vink@gmail.com>2023-04-29 12:03:35 +0200
committerMike Vink <mike1994vink@gmail.com>2023-04-29 12:03:35 +0200
commited0ef3875d955462b66684862e158dda63f12aa6 (patch)
tree2ce65aa5b75c45d1bba51992c3b240a24010efef /shell-scripts
parent5ca979eab4f7f4c16adf03927f5bd45000a563c0 (diff)
add checkout
Diffstat (limited to 'shell-scripts')
-rw-r--r--shell-scripts/ansiblelint2
-rw-r--r--shell-scripts/azdo-throwaway-clone42
-rw-r--r--shell-scripts/checkout69
-rw-r--r--shell-scripts/fawx8
4 files changed, 69 insertions, 52 deletions
diff --git a/shell-scripts/ansiblelint b/shell-scripts/ansiblelint
deleted file mode 100644
index 759de49..0000000
--- a/shell-scripts/ansiblelint
+++ /dev/null
@@ -1,2 +0,0 @@
-#!@bash@/bin/bash
-ansible-lint --profile production --write=all -q --nocolor
diff --git a/shell-scripts/azdo-throwaway-clone b/shell-scripts/azdo-throwaway-clone
deleted file mode 100644
index 099829f..0000000
--- a/shell-scripts/azdo-throwaway-clone
+++ /dev/null
@@ -1,42 +0,0 @@
-#!@bash@/bin/bash
-eval "$(pass show work/shell-scripts/secrets)"
-
-LIST_PROJECTS="/_apis/projects?api-version=7.1-preview.4"
-AUTH_HEADER="Authorization: Basic $WORK_AZDO_GIT_AUTH"
-LIST_REPOSITORIES="/_apis/git/repositories?api-version=7.1-preview.1"
-DIR_THROWAWAY_REPOS="$HOME/ephemeral-projects/"
-if [ ! -d $DIR_THROWAWAY_REPOS ]; then
- mkdir -p $DIR_THROWAWAY_REPOS
-fi
-MAX_REPOS=20
-
-COUNT=$(find "$DIR_THROWAWAY_REPOS" -mindepth 1 -maxdepth 1 -type d | wc -l)
-if [ "$COUNT" -gt "$MAX_REPOS" ]
-then
- STALE=$(( COUNT - MAX_REPOS ))
- OLDEST=$(find "$DIR_THROWAWAY_REPOS" -mindepth 1 -maxdepth 1 -type d -printf '%T@ %p\n' 2>/dev/null \
- | sort -n | head -n$STALE | cut -d' ' -f2)
-
- for dir in $OLDEST
- do
- rm -i -r $dir
- done
-fi
-
-
-echo "curl -s -H \"$AUTH_HEADER\" $WORK_AZDO_GIT_ORG_URL$LIST_PROJECTS"
-curl -s -H "$AUTH_HEADER" $WORK_AZDO_GIT_ORG_URL$LIST_PROJECTS \
-| jq '
-.value[].name
-' \
-| xargs -I{} bash -c "
-curl -s -H '$AUTH_HEADER' $WORK_AZDO_GIT_ORG_URL/{}$LIST_REPOSITORIES \
-| jq '
-.value[].name
-' \
-| awk '{ gsub(/\"/, \"\", \$1); printf \"{}/_git/%s\\n\", \$1 }'
-" \
-| fzf \
-| xargs -I{} bash -c "
-git clone $WORK_AZDO_GIT_ORG_URL/{} \"$DIR_THROWAWAY_REPOS\$(echo '{}' | cut -d '/' -f3)\"
-"
diff --git a/shell-scripts/checkout b/shell-scripts/checkout
new file mode 100644
index 0000000..a1cc9ce
--- /dev/null
+++ b/shell-scripts/checkout
@@ -0,0 +1,69 @@
+#!/bin/bash
+error () {
+ echo "$1"
+ exit 1
+}
+
+eval "$(pass show personal/shell-scripts/secrets)"
+DEST_DIR=""
+case "${@}" in
+ "az "*)
+ shift
+ LIST_PROJECTS="/_apis/projects?api-version=7.1-preview.4"
+ AUTH_HEADER="Authorization: Basic $WORK_AZDO_GIT_AUTH"
+ LIST_REPOSITORIES="/_apis/git/repositories?api-version=7.1-preview.1"
+ GIT_DIR="$HOME/projects/"
+ if [ ! -d $GIT_DIR ]; then
+ mkdir -p $GIT_DIR
+ fi
+ MAX_REPOS=20
+
+ echo "curl -s -H \"$AUTH_HEADER\" $WORK_AZDO_GIT_ORG_URL$LIST_PROJECTS"
+ PROJECT=$(curl -s -H "$AUTH_HEADER" $WORK_AZDO_GIT_ORG_URL$LIST_PROJECTS \
+ | jq '
+ .value[].name
+ ' \
+ | xargs -I{} bash -c "
+ curl -s -H '$AUTH_HEADER' $WORK_AZDO_GIT_ORG_URL/{}$LIST_REPOSITORIES \
+ | jq '
+ .value[].name
+ ' \
+ | awk '{ gsub(/\"/, \"\", \$1); printf \"{}/_git/%s\\n\", \$1 }'
+ " \
+ | fzf)
+
+ DEST_DIR="$GIT_DIR/$(echo $PROJECT | cut -d '/' -f3)"
+ if [ ! -d $DEST_DIR ]
+ then
+ git clone --bare $WORK_AZDO_GIT_ORG_URL/$PROJECT $DEST_DIR
+ fi
+ ;;
+ "gh "*)
+ shift
+ repo=$(gh repo list --json owner,name -q '.[] | "\(.owner.login)/\(.name)"' | fzf --print-query -1)
+ GIT_DIR="$HOME/projects"
+ if [ ! -d $GIT_DIR ]; then
+ mkdir -p $GIT_DIR
+ fi
+
+ if [[ "$(echo "$repo" | wc -l)" -ne 1 ]]; then
+ echo "Fetching my repo"
+ repo="$(echo "$repo" | tail -n1)"
+ fi
+
+ DEST_DIR="$GIT_DIR/$(echo $repo | cut -d '/' -f2)"
+ if [ ! -d $DEST_DIR ]
+ then
+ gh repo clone $repo $DEST_DIR -- --bare
+ fi
+ ;;
+ *)
+ error "Don't know how to fetch this"
+ ;;
+esac
+
+if [[ $DEST_DIR -ne "" ]]; then
+ cd $DEST_DIR
+ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
+ $EDITOR
+fi
diff --git a/shell-scripts/fawx b/shell-scripts/fawx
deleted file mode 100644
index d7247bc..0000000
--- a/shell-scripts/fawx
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-# Removes ansi escape codes from ansible outputs
-error () {
- echo "$1"
- exit 1
-}
-command -v awx || error "awx cli not found"
-awx "$@" | filter-ansi