Tweak/add some helpers
Expand skeleton.sh to include some arg-parsing example work.
This commit is contained in:
parent
cffe18cb65
commit
bbc9e67475
10
copy.sh
10
copy.sh
|
@ -31,11 +31,6 @@ require git wget curl find jq
|
||||||
|
|
||||||
mkdir -p "$HOME/.tmp" || exit 1
|
mkdir -p "$HOME/.tmp" || exit 1
|
||||||
|
|
||||||
if command -v sudo &> /dev/null && ! command -v sofi &> /dev/null && ! test -f /usr/bin/sofi; then
|
|
||||||
echo -e '#!/bin/bash\n$HOME/.sofi.sh --launch' | sudo tee /usr/bin/sofi
|
|
||||||
sudo chmod +x /usr/bin/sofi
|
|
||||||
fi
|
|
||||||
|
|
||||||
git submodule init
|
git submodule init
|
||||||
git submodule update
|
git submodule update
|
||||||
|
|
||||||
|
@ -82,6 +77,11 @@ if [[ "$1" == "--files-only" ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if command -v sudo &> /dev/null && ! command -v sofi &> /dev/null && ! test -f /usr/bin/sofi; then
|
||||||
|
echo -e '#!/bin/bash\n$HOME/.sofi.sh --launch' | sudo tee /usr/bin/sofi
|
||||||
|
sudo chmod +x /usr/bin/sofi
|
||||||
|
fi
|
||||||
|
|
||||||
if ! command -v cargo &> /dev/null; then
|
if ! command -v cargo &> /dev/null; then
|
||||||
echo "Rust is not installed. Installing..."
|
echo "Rust is not installed. Installing..."
|
||||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
branch="$(git rev-parse --abbrev-ref HEAD)"
|
branch="$(git rev-parse --abbrev-ref HEAD)"
|
||||||
|
|
||||||
if [ "$branch" = "master" ]; then
|
if [ "$branch" = "master" ]; then
|
||||||
# I've assumed that personal repos (where I might care less about PRs and such) will use main instead of master
|
# I've assumed that personal repos (where I might care less about PRs and such) will use 'main' instead of 'master'
|
||||||
echo "You can't commit directly to master branch"
|
echo "You can't commit directly to master branch"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -44,3 +44,10 @@ command! QA action CloseAllUnmodifiedEditors
|
||||||
" Save with sudo
|
" Save with sudo
|
||||||
cnoremap w!! execute 'silent! write !sudo tee % >/dev/null' <bar> edit!
|
cnoremap w!! execute 'silent! write !sudo tee % >/dev/null' <bar> edit!
|
||||||
set ideajoin
|
set ideajoin
|
||||||
|
|
||||||
|
" Include entire beginning of block's first line
|
||||||
|
" Useful when using K&R (or adjacent) indentation schemes
|
||||||
|
vnoremap aa{ a{o0
|
||||||
|
vnoremap aa[ a[o0
|
||||||
|
vnoremap aa< a<o0
|
||||||
|
vnoremap aa( a(o0
|
||||||
|
|
|
@ -85,11 +85,26 @@ function cache-run {
|
||||||
|
|
||||||
alias cr='cache-run'
|
alias cr='cache-run'
|
||||||
|
|
||||||
|
function json-or-str {
|
||||||
|
echo "$1" | jq 2>/dev/null || echo "$1" | jq -R
|
||||||
|
}
|
||||||
|
|
||||||
function arr {
|
function arr {
|
||||||
local json="["
|
local json="["
|
||||||
for var in "$@"
|
for var in "$@"
|
||||||
do
|
do
|
||||||
json="$json$(echo "$var" | jq -R),"
|
json="$json$(json-or-str "$var"),"
|
||||||
|
done
|
||||||
|
json=${json:0:-1}
|
||||||
|
json="$json]"
|
||||||
|
echo "$json" | jq --indent 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function arrs {
|
||||||
|
local json="["
|
||||||
|
echo "$@" | sed 's/\s\+/\n/g' | while read -r var
|
||||||
|
do
|
||||||
|
json="$json$(json-or-str "$var"),"
|
||||||
done
|
done
|
||||||
json=${json:0:-1}
|
json=${json:0:-1}
|
||||||
json="$json]"
|
json="$json]"
|
||||||
|
@ -199,6 +214,24 @@ function kubetty {
|
||||||
kubectl exec "$(kube-pod-name $@)" -i -t -- bash
|
kubectl exec "$(kube-pod-name $@)" -i -t -- bash
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function kubejob {
|
||||||
|
if ishelp $1; then
|
||||||
|
echo 'Run and log the given job (cronjob/$1) in -n cronjob with a random hash-based name'
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
local id="$(shortuuid)"
|
||||||
|
local name="$1-$id"
|
||||||
|
kubectl create job -n cronjob --from="cronjob/$1" "$name" || exit $?
|
||||||
|
local pods=""
|
||||||
|
echo "Waiting for job to complete..."
|
||||||
|
while ! pods="$(kubectl get pods -n cronjob | grep "$name" | grep Completed)"; do
|
||||||
|
sleep 3
|
||||||
|
done
|
||||||
|
echo "Fetching job logs for $name..."
|
||||||
|
local podname="$(echo "$pods" | awk '{print $1}')" || exit $?
|
||||||
|
kubectl logs -n cronjob -f "pod/$podname"
|
||||||
|
}
|
||||||
|
|
||||||
function undelete {
|
function undelete {
|
||||||
local filename="$1"
|
local filename="$1"
|
||||||
if test -f "$filename"; then
|
if test -f "$filename"; then
|
||||||
|
@ -232,6 +265,7 @@ alias vin='curl -s "http://randomvin.com/getvin.php?type=real"'
|
||||||
alias diff='diff -u'
|
alias diff='diff -u'
|
||||||
|
|
||||||
alias tmux="tmux attach || tmux"
|
alias tmux="tmux attach || tmux"
|
||||||
|
alias shortuuid="uuidgen | sed 's/-.*//'"
|
||||||
|
|
||||||
alias caddyfile="sudo vim /etc/caddy/Caddyfile"
|
alias caddyfile="sudo vim /etc/caddy/Caddyfile"
|
||||||
alias cf="sudo vim /etc/caddy/Caddyfile"
|
alias cf="sudo vim /etc/caddy/Caddyfile"
|
||||||
|
@ -394,6 +428,10 @@ alias du='du -sh'
|
||||||
|
|
||||||
alias tags='ctags --exclude=node_modules -f newtags -R . && mv newtags tags'
|
alias tags='ctags --exclude=node_modules -f newtags -R . && mv newtags tags'
|
||||||
|
|
||||||
|
function js {
|
||||||
|
load_nvm; node -e "const stdin = process.openStdin(); let data = \"\"; stdin.on(\"data\", chunk => data += chunk); stdin.on(\"end\", () => console.log(JSON.stringify(($@)(data), null, 2)));"
|
||||||
|
}
|
||||||
|
|
||||||
function roll {
|
function roll {
|
||||||
local count=1
|
local count=1
|
||||||
if [[ "$2" != "" ]]; then
|
if [[ "$2" != "" ]]; then
|
||||||
|
@ -410,17 +448,6 @@ function roll {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function arr {
|
|
||||||
local json="["
|
|
||||||
for var in "$@"
|
|
||||||
do
|
|
||||||
json="$json$(echo "$var" | jq -R),"
|
|
||||||
done
|
|
||||||
json=${json:0:-1}
|
|
||||||
json="$json]"
|
|
||||||
echo "$json" | jq --indent 0
|
|
||||||
}
|
|
||||||
|
|
||||||
alias d4='roll 4'
|
alias d4='roll 4'
|
||||||
alias 4='roll 4'
|
alias 4='roll 4'
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,46 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo "Hello, world!"
|
FRIEND="world"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat <<- EOF
|
||||||
|
Usage: $0 [OPTION]...
|
||||||
|
Greets the given friend.
|
||||||
|
|
||||||
|
With no friend provided, prints "Hello, world!"
|
||||||
|
|
||||||
|
-f, --friend set the name of the friend to greet
|
||||||
|
-h, --help print this help text
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# parse argv variables
|
||||||
|
while [ "$#" -gt 0 ]; do
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
-f | --friend)
|
||||||
|
FRIEND="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
|
||||||
|
-f=* | --friend=*)
|
||||||
|
FRIEND="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
-h | --help)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Unrecognized argument ${1#*=}"
|
||||||
|
echo
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Hello, $FRIEND!"
|
||||||
|
|
|
@ -347,6 +347,7 @@ export nvm_loaded=false
|
||||||
|
|
||||||
alias nvm="load_nvm; nvm"
|
alias nvm="load_nvm; nvm"
|
||||||
alias npm="load_nvm; npm"
|
alias npm="load_nvm; npm"
|
||||||
|
alias npx="load_nvm; npx"
|
||||||
alias node="load_nvm; node"
|
alias node="load_nvm; node"
|
||||||
alias standard="load_nvm; standard"
|
alias standard="load_nvm; standard"
|
||||||
alias lf="load_nvm; standard --fix"
|
alias lf="load_nvm; standard --fix"
|
||||||
|
|
Loading…
Reference in New Issue