mirror of
https://github.com/nmasur/dotfiles
synced 2025-07-05 13:50:13 +00:00
hammerspoon and reorganize old files to legacy
This commit is contained in:
4
legacy/bin/biggest
Executable file
4
legacy/bin/biggest
Executable file
@ -0,0 +1,4 @@
|
||||
#!/usr/local/bin/nu
|
||||
|
||||
ls | sort-by size | reverse | keep 10
|
||||
|
3
legacy/bin/biggest-files
Executable file
3
legacy/bin/biggest-files
Executable file
@ -0,0 +1,3 @@
|
||||
#!/usr/local/bin/nu
|
||||
|
||||
ls **/* | where type == File | sort-by size | reverse | keep 10
|
16
legacy/bin/connect_aws/Dockerfile
Normal file
16
legacy/bin/connect_aws/Dockerfile
Normal file
@ -0,0 +1,16 @@
|
||||
FROM alpine:latest
|
||||
|
||||
COPY requirements.txt /
|
||||
|
||||
RUN apk update && \
|
||||
apk add \
|
||||
openssh \
|
||||
python \
|
||||
py-pip \
|
||||
&& \
|
||||
pip install -r requirements.txt
|
||||
|
||||
COPY connect_cloud.sh /
|
||||
COPY connect_cloud.py /
|
||||
|
||||
ENTRYPOINT ["/connect_cloud.sh"]
|
85
legacy/bin/connect_aws/connect_cloud.py
Executable file
85
legacy/bin/connect_aws/connect_cloud.py
Executable file
@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""Connect to Cloud instances"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
import boto3
|
||||
|
||||
# Initiate the parser
|
||||
parser = argparse.ArgumentParser("Type the name of the connection you want")
|
||||
parser.add_argument('profile', metavar='P', nargs='?',
|
||||
help='an account to use')
|
||||
parser.add_argument('environment', metavar='E', nargs='?',
|
||||
help='an environment to specify')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Get AWS credentials profile
|
||||
profile_map = {
|
||||
'gs' : {
|
||||
'profile': 'ghoststory',
|
||||
'prod': 'id_rsa_gstory_prod.pem',
|
||||
'dev': 'id_rsa_gstory_prod.pem',
|
||||
'username': 'centos',
|
||||
},
|
||||
'di' : {
|
||||
'profile': 't2indies',
|
||||
'prod': 'disintegration-prod.pem',
|
||||
'dev': 'disintegration-dev.pem',
|
||||
'username': 'centos',
|
||||
},
|
||||
'pd' : {
|
||||
'profile': 't2indies',
|
||||
'prod': 't2indies-prod.pem',
|
||||
'dev': 't2indies-dev.pem',
|
||||
'username': 'centos',
|
||||
},
|
||||
'corp' : {
|
||||
'profile': 't2corp',
|
||||
'prod': 'take2games-corp.pem',
|
||||
'dev': 'take2games-corp.pem',
|
||||
'username': 'ec2-user',
|
||||
},
|
||||
'ksp' : {
|
||||
'profile': 'kerbal',
|
||||
'prod': 'kerbal_prod_key.pem',
|
||||
'dev': 'kerbal_dev_key.pem',
|
||||
'username': 'centos',
|
||||
},
|
||||
}
|
||||
profile_dict = profile_map.get(args.profile)
|
||||
profile = profile_dict['profile']
|
||||
|
||||
# Connect to AWS
|
||||
session = boto3.Session(profile_name=profile)
|
||||
client = session.client('ec2', verify=False)
|
||||
|
||||
response = client.describe_instances()
|
||||
|
||||
print(len(response['Reservations']), "total instances\n")
|
||||
|
||||
matched_instances = []
|
||||
for instance_wrapper in response['Reservations']:
|
||||
instance = instance_wrapper['Instances'][0]
|
||||
is_matched_env = False
|
||||
is_matched_role = False
|
||||
for tag in instance.get('Tags', []):
|
||||
if tag['Key'] == "site_env" and args.environment in tag['Value']:
|
||||
is_matched_env = True
|
||||
if tag['Key'] == "role" and tag['Value'] == 'host':
|
||||
is_matched_role = True
|
||||
if tag['Key'] == "Name":
|
||||
instance['Name'] = tag['Value']
|
||||
if is_matched_env and is_matched_role:
|
||||
matched_instances.append(instance)
|
||||
|
||||
for instance in matched_instances:
|
||||
print(instance['Name'])
|
||||
print(instance['PublicIpAddress'])
|
||||
print("")
|
||||
|
||||
with open("aws_connect", 'w') as outfile:
|
||||
outfile.write("ssh-keyscan {} >> ~/.ssh/known_hosts\n".format(matched_instances[0]['PublicIpAddress']))
|
||||
outfile.write("ssh -i ~/.ssh/{} {}@{}".format(profile_dict[args.environment], profile_dict['username'], matched_instances[0]['PublicIpAddress']))
|
||||
os.chmod("aws_connect", 0o755)
|
5
legacy/bin/connect_aws/connect_cloud.sh
Executable file
5
legacy/bin/connect_aws/connect_cloud.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
python connect_cloud.py "$@"
|
||||
|
||||
/aws_connect
|
8
legacy/bin/connect_aws/requirements.txt
Normal file
8
legacy/bin/connect_aws/requirements.txt
Normal file
@ -0,0 +1,8 @@
|
||||
boto3==1.9.239
|
||||
botocore==1.12.239
|
||||
docutils==0.15.2
|
||||
jmespath==0.9.4
|
||||
python-dateutil==2.8.0
|
||||
s3transfer==0.2.1
|
||||
six==1.12.0
|
||||
urllib3==1.26.5
|
26
legacy/bin/docker_cleanup
Executable file
26
legacy/bin/docker_cleanup
Executable file
@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Stop all containers
|
||||
if [ "$(docker ps -a -q)" ]; then
|
||||
echo "Stopping docker containers..."
|
||||
docker stop "$(docker ps -a -q)"
|
||||
else
|
||||
echo "No running docker containers."
|
||||
fi
|
||||
|
||||
# Remove all stopped containers
|
||||
if [ "$(docker ps -a -q)" ]; then
|
||||
echo "Removing docker containers..."
|
||||
docker rm "$(docker ps -a -q)"
|
||||
else
|
||||
echo "No stopped docker containers."
|
||||
fi
|
||||
|
||||
# Remove all untagged images
|
||||
if [[ $(docker images | grep "^<none>") ]]; then
|
||||
docker rmi "$(docker images | grep "^<none>" | awk '{print $3}')"
|
||||
else
|
||||
echo "No untagged docker images."
|
||||
fi
|
||||
|
||||
echo "Cleaned up docker."
|
37
legacy/bin/gh-repos
Executable file
37
legacy/bin/gh-repos
Executable file
@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
|
||||
case $1 in
|
||||
t2) organization="take-two" ;;
|
||||
d2c) organization="take-two-t2gp" ;;
|
||||
t2gp) organization="take-two-t2gp" ;;
|
||||
pd) organization="private-division" ;;
|
||||
dots) organization="playdots" ;;
|
||||
*) organization="nmasur" ;;
|
||||
esac
|
||||
|
||||
selected=$(gh repo list "$organization" \
|
||||
--limit 50 \
|
||||
--no-archived \
|
||||
--json=name,description,isPrivate,updatedAt,primaryLanguage \
|
||||
| jq -r '.[] | .name + "," + if .description == "" then "-" else .description |= gsub(","; " ") | .description end + "," + .updatedAt + "," + .primaryLanguage.name' \
|
||||
| (echo "REPO,DESCRIPTION,UPDATED,LANGUAGE"; cat -) \
|
||||
| column -s , -t \
|
||||
| fzf \
|
||||
--header-lines=1 \
|
||||
--layout=reverse \
|
||||
--bind "ctrl-o:execute:gh repo view -w ${organization}/{1}" \
|
||||
--bind "shift-up:preview-half-page-up" \
|
||||
--bind "shift-down:preview-half-page-down" \
|
||||
--preview "GH_FORCE_TTY=49% gh repo view ${organization}/{1} | glow -" \
|
||||
--preview-window up
|
||||
)
|
||||
[ -n "${selected}" ] && {
|
||||
directory="$HOME/dev/work"
|
||||
if [ $organization = "nmasur" ]; then directory="$HOME/dev/personal"; fi
|
||||
repo=$(echo "${selected}" | awk '{print $1}')
|
||||
repo_full="${organization}/${repo}"
|
||||
if [ ! -d "${directory}/${repo}" ]; then
|
||||
gh repo clone "$repo_full" "${directory}/${repo}"
|
||||
fi
|
||||
echo "${directory}/${repo}"
|
||||
}
|
37
legacy/bin/jira-checkout
Executable file
37
legacy/bin/jira-checkout
Executable file
@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Adapted from: https://seb.jambor.dev/posts/improving-shell-workflows-with-fzf/
|
||||
# Requires the following variables to be set:
|
||||
# - ATLASSIAN_EMAIL
|
||||
# - ATLASSIAN_API_TOKEN
|
||||
# - JIRA_HOSTNAME
|
||||
# - JIRA_PROJECT
|
||||
|
||||
choose_issue() {
|
||||
jq_template='"\(.key): \(.fields.summary)"'
|
||||
query="project=$JIRA_PROJECT AND status not in (\"Done\") AND assignee=currentUser()"
|
||||
|
||||
branch_name=$(
|
||||
curl \
|
||||
--data-urlencode "jql=$query" \
|
||||
--get \
|
||||
--user "$ATLASSIAN_EMAIL:$ATLASSIAN_API_TOKEN" \
|
||||
--silent \
|
||||
--compressed \
|
||||
"https://$JIRA_HOSTNAME/rest/api/2/search" |
|
||||
jq ".issues[] | $jq_template" |
|
||||
sed -e 's/"\(.*\)"/\1/' |
|
||||
fzf \
|
||||
--preview='jira-details {1}' \
|
||||
--preview-window=top:wrap |
|
||||
sed -e 's/: /:/' -e 's/[^a-zA-Z0-9:]/-/g' |
|
||||
awk -F ":" '{printf "%s/%s", $1, tolower($2)}'
|
||||
)
|
||||
|
||||
echo "$branch_name"
|
||||
}
|
||||
|
||||
issue_branch=$(choose_issue)
|
||||
if [ -n "$issue_branch" ]; then
|
||||
echo "git checkout -b \"$issue_branch\""
|
||||
fi
|
38
legacy/bin/jira-details
Executable file
38
legacy/bin/jira-details
Executable file
@ -0,0 +1,38 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Adapted from: https://seb.jambor.dev/posts/improving-shell-workflows-with-fzf/
|
||||
# Requires the following variables to be set:
|
||||
# - ATLASSIAN_EMAIL
|
||||
# - ATLASSIAN_API_TOKEN
|
||||
# - JIRA_HOSTNAME
|
||||
# - JIRA_PROJECT (for other script)
|
||||
|
||||
issue_details() {
|
||||
jira_key=$(echo "$1" | cut -d":" -f1)
|
||||
jq_template='"'\
|
||||
'# \(.key): \(.fields.summary)\n'\
|
||||
'\n'\
|
||||
'*Created*: \(.fields.created)\n'\
|
||||
'*Status*: \(.fields.status.statusCategory.name)\n'\
|
||||
'*Reporter*: \(.fields.reporter.displayName)\n'\
|
||||
'*Priority*: \(.fields.priority.name)\n'\
|
||||
"*Epic*: https://$JIRA_HOSTNAME/browse/\(.fields.customfield_10014)\n"\
|
||||
'\n'\
|
||||
'## Link\n\n'\
|
||||
"https://$JIRA_HOSTNAME/browse/\(.key)\n"\
|
||||
'\n'\
|
||||
'## Description\n\n'\
|
||||
'\(.fields.description)'\
|
||||
'"'
|
||||
curl \
|
||||
--get \
|
||||
--user "$ATLASSIAN_EMAIL:$ATLASSIAN_API_TOKEN" \
|
||||
--silent \
|
||||
--compressed \
|
||||
"https://$JIRA_HOSTNAME/rest/api/2/issue/$jira_key" |
|
||||
jq "$jq_template" |
|
||||
xargs printf |
|
||||
bat -l md --color always --style plain
|
||||
}
|
||||
|
||||
issue_details "$1"
|
7
legacy/bin/kube-dashboard
Executable file
7
legacy/bin/kube-dashboard
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
kubectl -n kube-system get secret $(kubectl -n kube-system get secret | grep dashboard-admin | awk '{print $1}') -o json | jq -j --raw-output '.data.token' | base64 --decode | pbcopy
|
||||
|
||||
open http://localhost:8001/api/v1/namespaces/default/services/https:kubernetes-dashboard:https/proxy/#!/login
|
||||
|
||||
kubectl proxy
|
3
legacy/bin/newest
Executable file
3
legacy/bin/newest
Executable file
@ -0,0 +1,3 @@
|
||||
#!/usr/local/bin/nu
|
||||
|
||||
ls | sort-by modified | reverse | keep 5
|
67
legacy/bin/ocr
Executable file
67
legacy/bin/ocr
Executable file
@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Yoinked from https://github.com/JJGO/dotfiles
|
||||
# Adapted from https://github.com/sdushantha/bin
|
||||
|
||||
set -x
|
||||
TEXT_FILE="/tmp/ocr.txt"
|
||||
IMAGE_FILE="/tmp/ocr.png"
|
||||
|
||||
function notify-send() {
|
||||
osascript -e "display notification \"$2\" with title \"OCR\""
|
||||
}
|
||||
|
||||
PATH="/usr/local/bin/:$PATH"
|
||||
|
||||
# Check if the needed dependencies are installed
|
||||
dependencies=(tesseract)
|
||||
for dependency in "${dependencies[@]}"; do
|
||||
type -p "$dependency" &>/dev/null || {
|
||||
# The reason why we are sending the error as a notification is because
|
||||
# user is most likely going to run this script by binding it to their
|
||||
# keyboard, therefor they cant see any text that is outputed using echo
|
||||
notify-send "ocr" "Could not find '${dependency}', is it installed?"
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
|
||||
# Take screenshot by selecting the area
|
||||
screencapture -i "$IMAGE_FILE"
|
||||
|
||||
# Get the exit code of the previous command.
|
||||
# So in this case, it is the screenshot command. If it did not exit with an
|
||||
# exit code 0, then it means the user canceled the process of taking a
|
||||
# screenshot by doing something like pressing the escape key
|
||||
STATUS=$?
|
||||
|
||||
# If the user pressed the escape key or did something to terminate the proccess
|
||||
# taking a screenshot, then just exit
|
||||
[ $STATUS -ne 0 ] && exit 1
|
||||
|
||||
# Do the magic (∩^o^)⊃━☆゚.*・。゚
|
||||
# Notice how I have removing the extension .txt from the file path. This is
|
||||
# because tesseract adds .txt to the given file path anyways. So if we were to
|
||||
# specify /tmp/ocr.txt as the file path, tesseract would out the text to
|
||||
# /tmp/ocr.txt.txt
|
||||
tesseract "$IMAGE_FILE" "${TEXT_FILE//\.txt/}"
|
||||
|
||||
# Check if the text was detected by checking number
|
||||
# of lines in the file
|
||||
LINES=$(wc -l < $TEXT_FILE)
|
||||
if [ "$LINES" -eq 0 ]; then
|
||||
notify-send "ocr" "no text was detected"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Copy text to clipboard
|
||||
# xclip -selection clip < "$TEXT_FILE"
|
||||
pbcopy < "$TEXT_FILE"
|
||||
|
||||
# Send a notification with the text that was grabbed using OCR
|
||||
# notify-send "ocr" "$(cat $TEXT_FILE)"
|
||||
|
||||
# Clean up
|
||||
# "Always leave the area better than you found it"
|
||||
# - My first grade teacher
|
||||
rm "$TEXT_FILE"
|
||||
rm "$IMAGE_FILE"
|
3
legacy/bin/oldest
Executable file
3
legacy/bin/oldest
Executable file
@ -0,0 +1,3 @@
|
||||
#!/usr/local/bin/nu
|
||||
|
||||
ls | sort-by modified | keep 5
|
16
legacy/bin/pod
Executable file
16
legacy/bin/pod
Executable file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Credit: https://github.com/junegunn/fzf/blob/master/ADVANCED.md
|
||||
|
||||
read -ra tokens < <(
|
||||
kubectl get pods --all-namespaces |
|
||||
fzf --info=inline --layout=reverse --header-lines=1 --border \
|
||||
--prompt "$(kubectl config current-context | sed 's/-context$//')> " \
|
||||
--header $'Press CTRL-O to open log in editor\n\n' \
|
||||
--bind ctrl-/:toggle-preview \
|
||||
--bind "ctrl-o:execute:${EDITOR:-vim} <(kubectl logs --namespace {1} {2}) > /dev/tty" \
|
||||
--preview-window up,follow \
|
||||
--preview 'kubectl logs --follow --tail=100000 --namespace {1} {2}' "$@"
|
||||
)
|
||||
[ ${#tokens} -gt 1 ] &&
|
||||
kubectl exec -it --namespace "${tokens[0]}" "${tokens[1]}" -- /bin/sh
|
25
legacy/bin/quick-edit
Executable file
25
legacy/bin/quick-edit
Executable file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Credit: https://github.com/junegunn/fzf/blob/master/ADVANCED.md
|
||||
# Requires bash.
|
||||
|
||||
# 1. Search for text in files using Ripgrep
|
||||
# 2. Interactively narrow down the list using fzf
|
||||
# 3. Open the file in Vim
|
||||
IFS=: read -ra selected < <(
|
||||
rg \
|
||||
--color=always \
|
||||
--line-number \
|
||||
--no-heading \
|
||||
--smart-case \
|
||||
--iglob !/Library/** \
|
||||
--iglob !/System/** \
|
||||
--iglob "!Users/$HOME/Library/*" \
|
||||
"${*:-}" |
|
||||
fzf --ansi \
|
||||
--color "hl:-1:underline,hl+:-1:underline:reverse" \
|
||||
--delimiter : \
|
||||
--preview 'bat --color=always {1} --highlight-line {2}' \
|
||||
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3'
|
||||
)
|
||||
[ -n "${selected[0]}" ] && nvim "${selected[0]}" "+${selected[1]}"
|
3
legacy/bin/symlinks
Executable file
3
legacy/bin/symlinks
Executable file
@ -0,0 +1,3 @@
|
||||
#!/usr/local/bin/nu
|
||||
|
||||
ls -al | where type == Symlink | select name target
|
5
legacy/bin/uplink-delete-bucket
Executable file
5
legacy/bin/uplink-delete-bucket
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
bucket="$1"
|
||||
access="$2"
|
||||
uplink ls ${access:+--access "$access"} "sj://$bucket/" | awk '{print $NF}' | xargs -I {} uplink rm ${access:+--access "$access"} "sj://$bucket/{}"
|
5
legacy/bin/url-decode
Executable file
5
legacy/bin/url-decode
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
|
||||
|
||||
urldecode "$@"
|
16
legacy/bin/weather_cached
Executable file
16
legacy/bin/weather_cached
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
|
||||
CACHE_FILE="$HOME/.cache/weather_cache"
|
||||
|
||||
if [ "$1" = "clear" ]; then
|
||||
rm -f "$CACHE_FILE"
|
||||
fi
|
||||
|
||||
CACHE_TIME="$(stat -f %m "$CACHE_FILE" 2>/dev/null)"
|
||||
NOW_TIME=$(date +%s)
|
||||
TIME_PASSED=$((NOW_TIME-CACHE_TIME))
|
||||
if [ "$TIME_PASSED" -gt "1200" ]
|
||||
then
|
||||
curl -m 2 -s "wttr.in/$WEATHER_CITY?format=%c%t" > "$CACHE_FILE"
|
||||
fi
|
||||
cat "$CACHE_FILE"
|
Reference in New Issue
Block a user