Reorganise scripts
This commit is contained in:
parent
5ebf7f9b5c
commit
4ae0656da4
18 changed files with 196 additions and 104 deletions
33
.config/scripts/tool/aws-profile.sh
Executable file
33
.config/scripts/tool/aws-profile.sh
Executable file
|
@ -0,0 +1,33 @@
|
|||
function awsconfig {
|
||||
AWS_PROFILE=$(cat ~/.aws/credentials \
|
||||
| grep "\[" \
|
||||
| fzf \
|
||||
| tr -d "[" \
|
||||
| tr -d "]" \
|
||||
| xargs
|
||||
)
|
||||
|
||||
clear
|
||||
|
||||
vim /tmp/raw_keys.tmp
|
||||
|
||||
cat /tmp/raw_keys.tmp | grep -v "\[.*\]$" > /tmp/keys.tmp
|
||||
|
||||
export $(xargs < /tmp/keys.tmp)
|
||||
|
||||
rm /tmp/raw_keys.tmp /tmp/keys.tmp
|
||||
|
||||
aws configure set aws_access_key_id "${aws_access_key_id}" --profile "$AWS_PROFILE"
|
||||
aws configure set aws_secret_access_key "${aws_secret_access_key}" --profile "$AWS_PROFILE"
|
||||
aws configure set aws_session_token "${aws_session_token}" --profile "$AWS_PROFILE"
|
||||
|
||||
echo "Testing AWS Keys..."
|
||||
IAM_RESULT=$(aws sts get-caller-identity --query "Account" --output text --profile "$AWS_PROFILE")
|
||||
|
||||
if [ "$IAM_RESULT" ]; then
|
||||
echo "Credentials work!"
|
||||
else
|
||||
echo "AWS Keys did not work!"
|
||||
fi
|
||||
}
|
||||
|
19
.config/scripts/tool/encrypt.sh
Normal file
19
.config/scripts/tool/encrypt.sh
Normal file
|
@ -0,0 +1,19 @@
|
|||
function encrypt {
|
||||
FILE_EXTENSION=$(echo $1 | cut -f 2,3 -d '.')
|
||||
FILE_NAME=$(echo "$1" | cut -f 1 -d '.')
|
||||
|
||||
openssl enc -aes-256-cbc -salt -in "$*" -out "$FILE_NAME".enc
|
||||
echo "$GREEN_TEXT\nSend the follow command via Slack alongside the file:$DEFAULT_TEXT\n\`openssl enc -d -aes-256-cbc -in ~/Downloads/$FILE_NAME.enc >> $FILE_NAME.$FILE_EXTENSION"
|
||||
}
|
||||
|
||||
function salted-uuid {
|
||||
# Convert input into base64 string
|
||||
INPUT_AS_BASE64=$(echo -n "$1" | openssl dgst -binary -sha256 | openssl base64)
|
||||
BASE64_SANITIZED=$(echo -n "$INPUT_AS_BASE64" | sed 's/[=\/+-]//g')
|
||||
|
||||
# Add Delimiters to the string
|
||||
BASE_WITH_DELIM=$(echo -n "$BASE64_SANITIZED" | sed -E 's/./&-/32;s/./&-/20;s/./&-/16;s/./&-/12;s/./&-/8')
|
||||
|
||||
# Return with cruft removed
|
||||
echo "$BASE_WITH_DELIM" | cut -f1,2,3,4,5 -d"-"
|
||||
}
|
11
.config/scripts/tool/ezdig.sh
Executable file
11
.config/scripts/tool/ezdig.sh
Executable file
|
@ -0,0 +1,11 @@
|
|||
function ezdig() {
|
||||
CNAME="$(dig @1.1.1.1 $1 CNAME | sed -n -e '/ANSWER SECTION/,/;;/ p' | sed -n '/^[a-z]/p')"
|
||||
NS="$(dig @1.1.1.1 $1 NS | sed -n -e '/ANSWER SECTION/,/;;/ p' | sed -n '/^[a-z]/p')"
|
||||
A="$(dig @1.1.1.1 $1 A | sed -n -e '/ANSWER SECTION/,/;;/ p' | sed -n '/^[a-z]/p')"
|
||||
MX="$(dig @1.1.1.1 $1 MX | sed -n -e '/ANSWER SECTION/,/;;/ p' | sed -n '/^[a-z]/p')"
|
||||
|
||||
if [[ -z "${CNAME// }" ]] then; else; echo "$GREEN_TEXT\0CNAME:$DEFAULT_TEXT\n$CNAME\n\n"; fi;
|
||||
if [[ -z "${NS// }" ]] then; else; echo "$GREEN_TEXT\0NS:$DEFAULT_TEXT\n$NS\n\n"; fi;
|
||||
if [[ -z "${A// }" ]] then; else; echo "$GREEN_TEXT\0A:$DEFAULT_TEXT\n$A\n\n"; fi;
|
||||
if [[ -z "${MX// }" ]] then; else; echo "$GREEN_TEXT\0MX:$DEFAULT_TEXT\n$MX"; fi;
|
||||
}
|
57
.config/scripts/tool/git.sh
Normal file
57
.config/scripts/tool/git.sh
Normal file
|
@ -0,0 +1,57 @@
|
|||
function is_in_git_repo() {
|
||||
git rev-parse HEAD > /dev/null 2>&1
|
||||
}
|
||||
|
||||
function fzf-down() {
|
||||
fzf --height 50% "$@" --border
|
||||
}
|
||||
|
||||
function checkout() {
|
||||
is_in_git_repo || return
|
||||
BRANCH=$(git branch -a | sed -e 's/^ *//g' -e '/HEAD ->/d' -e 's/remotes\///g' | fzf --border --query "$1")
|
||||
case "$BRANCH" in
|
||||
*"origin"*) git checkout --track "$BRANCH" ;;
|
||||
*) git checkout "$BRANCH" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
function commit() {
|
||||
is_in_git_repo || return
|
||||
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD | cut -f1,2 -d - | cut -f2 -d /)
|
||||
|
||||
if git status | grep -q "serverless.yml"; then
|
||||
echo "$RED_TEXT\nAre you sure you want to commit serverless.yml?"
|
||||
select answer in "Yes" "No"; do
|
||||
case $answer in
|
||||
Yes ) break;;
|
||||
No ) return 1;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
if test "$BRANCH_NAME" != 'master' -a "$BRANCH_NAME" != 'main' -a "$BRANCH_NAME" != 'rnd'; then
|
||||
git commit -m "[$BRANCH_NAME] $*"
|
||||
else
|
||||
echo "$RED_TEXT\nAre you sure you want to commit directly to $BRANCH_NAME?$DEFAULT_TEXT"
|
||||
select answer in "Yes" "No"; do
|
||||
case $answer in
|
||||
Yes ) git commit -m "$*"; break;;
|
||||
No ) return 1;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function add() {
|
||||
is_in_git_repo || return
|
||||
git add $(git status | grep modified: | sed -e 's/ *.*: *//g' | tac | fzf -m)
|
||||
git status
|
||||
}
|
||||
|
||||
# Restore unstaged files
|
||||
function restore() {
|
||||
is_in_git_repo || return
|
||||
# TODO Adjust this to only list unstaged files!
|
||||
git restore --staged "$(git status | grep modified: | sed -e 's/ *.*: *//g' | tac | fzf -m)"
|
||||
git status
|
||||
}
|
7
.config/scripts/tool/kill.sh
Executable file
7
.config/scripts/tool/kill.sh
Executable file
|
@ -0,0 +1,7 @@
|
|||
kill-port() {
|
||||
sudo kill -9 $(lsof -t -i:"$1")
|
||||
}
|
||||
|
||||
kill-all() {
|
||||
sudo kill -9 $(pgrep "$1")
|
||||
}
|
45
.config/scripts/tool/scratch.sh
Executable file
45
.config/scripts/tool/scratch.sh
Executable file
|
@ -0,0 +1,45 @@
|
|||
function nscratch () {
|
||||
requestedDate=$(date +"%y-%m-%d")
|
||||
if [ ! -e ~/Documents/Scratchpad-now/$requestedDate-write.md ]; then
|
||||
touch ~/Documents/Scratchpad-now/$requestedDate-write.md
|
||||
echo "---" >> ~/Documents/Scratchpad-now/$requestedDate-write.md
|
||||
echo "title: " >> ~/Documents/Scratchpad-now/$requestedDate-write.md
|
||||
echo "---" >> ~/Documents/Scratchpad-now/$requestedDate-write.md
|
||||
echo "" >> ~/Documents/Scratchpad-now/$requestedDate-write.md
|
||||
echo "Today I " >> ~/Documents/Scratchpad-now/$requestedDate-write.md
|
||||
fi
|
||||
vim ~/Documents/Scratchpad-now/$requestedDate-write.md
|
||||
}
|
||||
|
||||
function codeScratch () {
|
||||
cd ~/Developer/Scratch/ || exit
|
||||
DATE=$(date +"%y-%m-%d")
|
||||
if test ! -d "$(pwd)/$DATE"; then
|
||||
mkdir "$(pwd)/$DATE";
|
||||
cd "$(pwd)/$DATE" || exit
|
||||
|
||||
# Setup project
|
||||
pnpm init
|
||||
pnpm install @types/node ts-node-dev typescript prettier -D
|
||||
if test ! $# -eq 0; then
|
||||
# shellcheck disable=SC2086
|
||||
pnpm install $*
|
||||
fi
|
||||
|
||||
# Essential files
|
||||
echo '{"compilerOptions": {"module": "commonjs","esModuleInterop": true,"target": "es6","moduleResolution": "node","sourceMap": true,"outDir": "dist"},"lib": ["es2015"]}' > tsconfig.json
|
||||
echo 'module.exports={semi: true,singleQuote: true,tabWidth: 2,trailingComma: "all",arrowParens: "always",printWidth: 80};' > .prettierrc.js
|
||||
echo 'console.log("hello world")' > scratch.ts
|
||||
jq '.scripts = { start: "ts-node-dev --respawn scratch.ts" }' package.json > tmp.json
|
||||
rm package.json
|
||||
mv tmp.json package.json
|
||||
else
|
||||
cd "$(pwd)/$DATE"
|
||||
fi
|
||||
# Start editor session
|
||||
# tmux new-session \; \
|
||||
# send-keys 'vim scratch.ts' C-m \; \
|
||||
# split-window -v \; \
|
||||
# send-keys 'yarn start' C-m \;
|
||||
}
|
||||
|
28
.config/scripts/tool/site-prep.sh
Executable file
28
.config/scripts/tool/site-prep.sh
Executable file
|
@ -0,0 +1,28 @@
|
|||
site-prep() {
|
||||
mkdir -p lg/;
|
||||
mkdir -p md/;
|
||||
mkdir -p sm/;
|
||||
|
||||
convert "$1" \
|
||||
-strip \
|
||||
-quality 85% \
|
||||
-interlace Plane \
|
||||
-resize 1800 "lg/${1%.*}.jpg"
|
||||
|
||||
convert "$1" \
|
||||
-strip \
|
||||
-interlace Plane \
|
||||
-gaussian-blur 0.05 \
|
||||
-quality 85% \
|
||||
-resize 720 "md/${1%.*}.jpg"
|
||||
|
||||
convert "$1" \
|
||||
-strip \
|
||||
-interlace Plane \
|
||||
-scale 10% \
|
||||
-blur 0x2.5 \
|
||||
-resize 1000% \
|
||||
-resize 180 "sm/${1%.*}.jpg"
|
||||
|
||||
echo "$1 is prepped"
|
||||
}
|
46
.config/scripts/tool/thumb.sh
Executable file
46
.config/scripts/tool/thumb.sh
Executable file
|
@ -0,0 +1,46 @@
|
|||
function thumb() {
|
||||
UUID=$(uuidgen)
|
||||
GRID_X=2
|
||||
GRID_Y=4
|
||||
TMP_FILE_LOCATION="./tmp_chapters_out_$UUID.mp4"
|
||||
|
||||
echo "Removing blank frames..."
|
||||
|
||||
ffmpeg \
|
||||
-hide_banner \
|
||||
-i "$1" \
|
||||
-c:a copy \
|
||||
-vaapi_device /dev/dri/renderD128 -vcodec h264_vaapi \
|
||||
-vf "blackframe=0,metadata=select:key=lavfi.blackframe.pblack:value=15:function=less,format=nv12|vaapi,hwupload" \
|
||||
"$TMP_FILE_LOCATION"
|
||||
|
||||
echo "Getting frame rate..."
|
||||
# Get frame rate
|
||||
FRAMES=$(ffprobe \
|
||||
-loglevel quiet \
|
||||
-select_streams v:0 \
|
||||
-count_packets \
|
||||
-show_entries stream=nb_read_packets \
|
||||
-of csv=p=0 "$TMP_FILE_LOCATION"
|
||||
)
|
||||
|
||||
echo "Total frames: $FRAMES"
|
||||
|
||||
GRID_TOTAL=$((GRID_X*GRID_Y))
|
||||
SPLICE=$(((FRAMES + GRID_TOTAL - 1) / GRID_TOTAL))
|
||||
echo "Splicing every: $SPLICE"
|
||||
|
||||
echo "Generating thumbnail grid..."
|
||||
# Generate for frame rate
|
||||
ffmpeg \
|
||||
-hide_banner \
|
||||
-loglevel quiet \
|
||||
-i "$TMP_FILE_LOCATION" \
|
||||
-vf "select=not(mod(n\,$SPLICE)),scale=800:-1,tile=$GRID_X\x$GRID_Y" \
|
||||
-vsync 0 \
|
||||
"chapters-$UUID-gpu.jpg"
|
||||
|
||||
rm "$TMP_FILE_LOCATION"
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue