hammerspoon and reorganize old files to legacy

This commit is contained in:
Noah Masur
2022-06-14 07:32:27 -04:00
parent c048b7244f
commit df59e376f2
52 changed files with 2 additions and 0 deletions

4
legacy/bin/biggest Executable file
View File

@ -0,0 +1,4 @@
#!/usr/local/bin/nu
ls | sort-by size | reverse | keep 10

3
legacy/bin/biggest-files Executable file
View File

@ -0,0 +1,3 @@
#!/usr/local/bin/nu
ls **/* | where type == File | sort-by size | reverse | keep 10

View 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"]

View 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)

View File

@ -0,0 +1,5 @@
#!/bin/sh
python connect_cloud.py "$@"
/aws_connect

View 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
View 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
View 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
View 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
View 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
View 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
View File

@ -0,0 +1,3 @@
#!/usr/local/bin/nu
ls | sort-by modified | reverse | keep 5

67
legacy/bin/ocr Executable file
View 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
View File

@ -0,0 +1,3 @@
#!/usr/local/bin/nu
ls | sort-by modified | keep 5

16
legacy/bin/pod Executable file
View 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
View 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
View File

@ -0,0 +1,3 @@
#!/usr/local/bin/nu
ls -al | where type == Symlink | select name target

View 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
View File

@ -0,0 +1,5 @@
#!/bin/bash
function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
urldecode "$@"

16
legacy/bin/weather_cached Executable file
View 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"

38
legacy/homebrew/Caskfile Normal file
View File

@ -0,0 +1,38 @@
tap "homebrew/cask"
# Core Applications
cask "alacritty" # Terminal
cask "firefox" # Browser
#cask "slack" # Chat
#cask "zoomus" # Video conference
cask "1password" # Passwords
cask "dropbox" # File sync
#cask "docker" # Containers
# Helpful Applications
cask "obsidian" # Notes
# Auxiliary Tools
cask "scroll-reverser" # Mouse vs. trackpad
cask "meetingbar" # Scheduling
cask "gitify" # GitHub notifications
# cask "basictex" # Small LaTeX distribution
cask "hammerspoon"
tap "homebrew/cask-drivers"
cask "logitech-g-hub" # Hardware drivers
# Fonts
tap "homebrew/cask-fonts"
cask "font-fira-mono-nerd-font"
# Personal
cask "keybase" # Encryption
cask "discord" # Chat
#cask "steam" # Games
#cask "epic-games" # Games
#cask "calibre" # E-Books
#cask "signal" # Messaging
# Maybe
#cask "jira-client" # Project Management

View File

@ -0,0 +1,17 @@
# Core Packages
brew "fish" # Shell
brew "neovim" # Editor
brew "tmux" # Terminal panes and windows
brew "starship" # Shell prompt
brew "git" # Latest git
brew "ripgrep" # Faster, better grep
brew "fd" # Faster, better find
brew "sd" # Faster, better sed
brew "zoxide" # Faster, better autojump
brew "exa" # Better ls
brew "bat" # Better cat
brew "fzf" # Fuzzy finder
brew "tealdeer" # Mini man page
brew "direnv" # Environment variables
brew "glow" # Markdown previews

View File

@ -0,0 +1,14 @@
# DevOps Packages
tap "nmasur/repo"
tap "hashicorp/tap"
brew "ansible" # Deploy to local server
brew "terraform" # Deploy cloud infra
brew "packer" # Build deployment images
brew "awscli" # AWS API tools
brew "kubectl" # Kubernetes CLI
brew "k9s" # Kubernetes TUI
brew "nmasur/repo/drips" # Retrieve AWS IPs
brew "hashicorp/tap/terraform-ls"
brew "tflint"

View File

@ -0,0 +1,8 @@
# Fun / Unnecessary Packages
#tap "nmasur/repo"
#tap "tarkah/tickrs"
#brew "ffmpeg" # Convert videos
#brew "nmasur/repo/bee" # Cheat on NYTimes Spelling Bee
#brew "tarkah/tickrs/tickrs" # Interactive stock tickers

View File

@ -0,0 +1,17 @@
# Still Learning Tools
tap "superfly/tap"
tap "nmasur/repo"
tap "cjbassi/ytop"
#brew "superfly/tap/flyctl" # Fly.io CLI
#brew "ghc" # Haskell
#brew "xsv" # CSV manipulation
#brew "gron" # JSON grep
#brew "nushell" # Data manipulation shell
#brew "tectonic" # Minimal LaTeX compiler
brew "noti" # Create system notifications
#brew "b2-tools" # BackBlaze B2 storage
#brew "cjbassi/ytop/ytop" # Fancy system performance
#brew "nmasur/repo/update-ssh-config" # Update .ssh/config
brew "awslogs" # View AWS log streams

View File

@ -0,0 +1,10 @@
# Programming Packages
brew "shellcheck" # Lint for bash
brew "shfmt" # Formatter for bash
brew "stylua" # Formatter for lua
brew "python" # Latest version of Python
brew "ipython" # Better interactive Python shell
brew "poetry" # Project-based Python dependencies
brew "ruby" # Newer than default ruby
brew "node" # NodeJS

View File

@ -0,0 +1,20 @@
# Utility Packages
tap "saulpw/vd"
brew "jq" # JSON manipulation
brew "dos2unix" # File conversion
brew "tree" # Display directory trees
brew "trash" # Delete to trash
brew "wget" # Not quite curl
brew "telnet" # Check networking
brew "prettyping" # Better ping
brew "httpie" # Better curl
brew "gpg" # Encryption
brew "qrencode" # Make a QR code
brew "mpv" # Video player
brew "youtube-dl" # Download YouTube videos
brew "gh" # GitHub commands
brew "pandoc" # Document converter
brew "saulpw/vd/visidata" # Spreadsheet manipulation
brew "mdp" # Terminal slideshows

View File

@ -0,0 +1,2 @@
# Run backup of mail folder, requires rclone (and uplink, with proper setup)
@hourly root rclone sync /home/noah/Mail/ mail-backup:mail/

17
legacy/mail/backup/setup_uplink Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
# First Uplink
curl -L https://github.com/storj/storj/releases/latest/download/uplink_linux_amd64.zip -o uplink_linux_amd64.zip
if ! (which unzip > /dev/null)
then
apt install -y unzip
fi
unzip -o uplink_linux_amd64.zip
rm uplink_linux_amd64.zip
chmod 755 uplink
sudo mv uplink /usr/local/bin/uplink
# Then rclone
curl https://rclone.org/install.sh | sudo bash
echo "\n\nNow setup rclone with: rclone config\n"

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.noah.newsboat</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/newsboat -x reload</string>
</array>
<key>Nice</key>
<integer>1</integer>
<key>StartInterval</key>
<integer>1800</integer>
<key>RunAtLoad</key>
<false/>
<key>StandardErrorPath</key>
<string>/tmp/newsboat.err</string>
<key>StandardOutPath</key>
<string>/tmp/newsboat.out</string>
</dict>
</plist>

40
legacy/newsboat/config Normal file
View File

@ -0,0 +1,40 @@
browser "$BROWSER %u"
prepopulate-query-feeds yes
feed-sort-order lastupdated
reload-only-visible-feeds yes
text-width 72
bind-key j down
bind-key k up
bind-key j next articlelist
bind-key k prev articlelist
bind-key G end
bind-key g home
bind-key d pagedown
bind-key u pageup
bind-key n next-unread
bind-key p prev-unread
bind-key ; macro-prefix
bind-key B bookmark
bind-key f edit-flags
macro v set browser "mpv %u"; open-in-browser; set browser "$BROWSER %u"
macro p set browser "echo %u"; one; set browser "$BROWSER %u"
macro H set browser "clx view $(echo %u | cut -d '=' -f2)"; one; set browser "$BROWSER %u"
macro h set browser "clx view $(echo %u | cut -d '=' -f2)"; two; set browser "$BROWSER %u"
macro w set browser "w3m -o confirm_qq=false %u"; open-in-browser; set browser "$BROWSER %u"
macro r set browser "url-markdown %u | glow -p -w 72 -"; open-in-browser; set browser "$BROWSER %u"
macro d set browser "youtube-dl -o ~/Downloads/%(title)s.%(ext)s %u &"; open-in-browser-noninteractively; set browser "$BROWSER %u"
macro n set-tag News; reload-all
macro a set-tag All
macro e set-tag Reddit; reload-all
macro y set-tag YouTube; reload-all
bookmark-cmd "bookmark"
highlight article "^(Feed|Title|Author|Link|Date):.*" color243 default
highlight article "^(Links):.*" color243 default
highlight article "^(\\[[0-9]+\\]):.*" color243 default
highlight article "^(\\[[0-9]+\\])" color243 default
highlight article "^\\[.*\\]$" color243 default
highlight article "^(Title:).*" color249 default

137
legacy/nix-env.fish Normal file
View File

@ -0,0 +1,137 @@
# Setup Nix
# We need to distinguish between single-user and multi-user installs.
# This is difficult because there's no official way to do this.
# We could look for the presence of /nix/var/nix/daemon-socket/socket but this will fail if the
# daemon hasn't started yet. /nix/var/nix/daemon-socket will exist if the daemon has ever run, but
# I don't think there's any protection against accidentally running `nix-daemon` as a user.
# We also can't just look for /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh because
# older single-user installs used the default profile instead of a per-user profile.
# We can still check for it first, because all multi-user installs should have it, and so if it's
# not present that's a pretty big indicator that this is a single-user install. If it does exist,
# we still need to verify the install type. To that end we'll look for a root owner and sticky bit
# on /nix/store. Multi-user installs set both, single-user installs don't. It's certainly possible
# someone could do a single-user install as root and then manually set the sticky bit but that
# would be extremely unusual.
set -l nix_profile_path /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
set -l single_user_profile_path ~/.nix-profile/etc/profile.d/nix.sh
if test -e $nix_profile_path
# The path exists. Double-check that this is a multi-user install.
# We can't just check for ~/.nix-profile/… because this may be a single-user install running as
# the wrong user.
# stat is not portable. Splitting the output of ls -nd is reliable on most platforms.
set -l owner (string split -n ' ' (command ls -nd /nix/store 2>/dev/null))[3]
if not test -k /nix/store -a $owner -eq 0
# /nix/store is either not owned by root or not sticky. Assume single-user.
set nix_profile_path $single_user_profile_path
end
else
# The path doesn't exist. Assume single-user
set nix_profile_path $single_user_profile_path
end
if test -e $nix_profile_path
# Source the nix setup script
# We're going to run the regular Nix profile under bash and then print out a few variables
for line in (command env -u BASH_ENV bash -c '. "$0"; for name in PATH "${!NIX_@}"; do printf "%s=%s\0" "$name" "${!name}"; done' $nix_profile_path | string split0)
set -xg (string split -m 1 = $line)
end
# Insert Nix's fish share directories into fish's special variables.
# nixpkgs-installed fish tries to set these up already if NIX_PROFILES is defined, which won't
# be the case when sourcing $__fish_data_dir/share/config.fish normally, but might be for a
# recursive invocation. To guard against that, we'll only insert paths that don't already exit.
# Furthermore, for the vendor_conf.d sourcing, we'll use the pre-existing presence of a path in
# $fish_function_path to determine whether we want to source the relevant vendor_conf.d folder.
# To start, let's locally define NIX_PROFILES if it doesn't already exist.
set -al NIX_PROFILES
if test (count $NIX_PROFILES) -eq 0
set -a NIX_PROFILES $HOME/.nix-profile
end
# Replicate the logic from nixpkgs version of $__fish_data_dir/__fish_build_paths.fish.
set -l __nix_profile_paths (string split ' ' -- $NIX_PROFILES)[-1..1]
set -l __extra_completionsdir \
$__nix_profile_paths/etc/fish/completions \
$__nix_profile_paths/share/fish/vendor_completions.d
set -l __extra_functionsdir \
$__nix_profile_paths/etc/fish/functions \
$__nix_profile_paths/share/fish/vendor_functions.d
set -l __extra_confdir \
$__nix_profile_paths/etc/fish/conf.d \
$__nix_profile_paths/share/fish/vendor_conf.d
### Configure fish_function_path ###
# Remove any of our extra paths that may already exist.
# Record the equivalent __extra_confdir path for any function path that exists.
set -l existing_conf_paths
for path in $__extra_functionsdir
if set -l idx (contains --index -- $path $fish_function_path)
set -e fish_function_path[$idx]
set -a existing_conf_paths $__extra_confdir[(contains --index -- $path $__extra_functionsdir)]
end
end
# Insert the paths before $__fish_data_dir.
if set -l idx (contains --index -- $__fish_data_dir/functions $fish_function_path)
# Fish has no way to simply insert into the middle of an array.
set -l new_path $fish_function_path[1..$idx]
set -e new_path[$idx]
set -a new_path $__extra_functionsdir
set fish_function_path $new_path $fish_function_path[$idx..-1]
else
set -a fish_function_path $__extra_functionsdir
end
### Configure fish_complete_path ###
# Remove any of our extra paths that may already exist.
for path in $__extra_completionsdir
if set -l idx (contains --index -- $path $fish_complete_path)
set -e fish_complete_path[$idx]
end
end
# Insert the paths before $__fish_data_dir.
if set -l idx (contains --index -- $__fish_data_dir/completions $fish_complete_path)
set -l new_path $fish_complete_path[1..$idx]
set -e new_path[$idx]
set -a new_path $__extra_completionsdir
set fish_complete_path $new_path $fish_complete_path[$idx..-1]
else
set -a fish_complete_path $__extra_completionsdir
end
### Source conf directories ###
# The built-in directories were already sourced during shell initialization.
# Any __extra_confdir that came from $__fish_data_dir/__fish_build_paths.fish was also sourced.
# As explained above, we're using the presence of pre-existing paths in $fish_function_path as a
# signal that the corresponding conf dir has also already been sourced.
# In order to simulate this, we'll run through the same algorithm as found in
# $__fish_data_dir/config.fish except we'll avoid sourcing the file if it comes from an
# already-sourced location.
# Caveats:
# * Files will be sourced in a different order than we'd ideally do (because we're coming in
# after the fact to source them).
# * If there are existing extra conf paths, files in them may have been sourced that should have
# been suppressed by paths we're inserting in front.
# * Similarly any files in $__fish_data_dir/vendor_conf.d that should have been suppressed won't
# have been.
set -l sourcelist
for file in $__fish_config_dir/conf.d/*.fish $__fish_sysconf_dir/conf.d/*.fish
# We know these paths were sourced already. Just record them.
set -l basename (string replace -r '^.*/' '' -- $file)
contains -- $basename $sourcelist
or set -a sourcelist $basename
end
for root in $__extra_confdir
for file in $root/*.fish
set -l basename (string replace -r '^.*/' '' -- $file)
contains -- $basename $sourcelist
and continue
set -a sourcelist $basename
contains -- $root $existing_conf_paths
and continue # this is a pre-existing path, it will have been sourced already
[ -f $file -a -r $file ]
and source $file
end
end
end

79
legacy/scripts/bootstrap Executable file
View File

@ -0,0 +1,79 @@
#!/bin/sh
DOTS=$(dirname "$0")/..
cd "$DOTS" || (echo "Directory not found: $DOTS"; exit 1)
DOTS="$PWD"
install_xcode() {
if [ "$(uname)" = "Darwin" ]
then
if ! (xcode-select --version > /dev/null 2>&1)
then
xcode-select --install
fi
echo "xcode ✓"
fi
}
install_homebrew() {
if ! (which /usr/local/bin/brew > /dev/null)
then
printf "homebrew ✕\n\n"
printf "\ninstalling homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
echo ""
fi
echo "homebrew ✓"
}
install_brews() {
brewfile=$DOTS/homebrew/core.Brewfile
if ! (/usr/local/bin/brew bundle check --file "$brewfile" > /dev/null)
then
/usr/local/bin/brew bundle --file "$brewfile"
fi
echo "brews installed ✓"
}
use_fish_shell() {
if ! (which fish > /dev/null)
then
echo "Install fish before continuing"
echo "You can do: brew install fish"
echo "Or add fish to homebrew/Brewfile and rerun"
exit 1
fi
FISH_SHELL=$(which fish)
if ! (grep "$FISH_SHELL" /etc/shells > /dev/null)
then
echo "Modifying /etc/shells"
echo "Requires sudo password"
echo "$FISH_SHELL" | sudo tee -a /etc/shells
fi
if ! (echo "$SHELL" | grep fish > /dev/null)
then
echo "Changing default shell to fish"
echo "Requires sudo password"
sudo chsh -s "$FISH_SHELL"
fi
echo "fish ✓"
}
printf "\nbootstrapping...\n\n"
install_xcode
install_homebrew
install_brews
use_fish_shell
("$DOTS/scripts/setup_symlinks")
echo ""
echo "consider running other scripts:"
echo " - brews"
echo " - casks"
echo " - configure_macos"
echo " - rust"
echo " - cargos"
echo ""

15
legacy/scripts/brews Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh
DOTS=$(dirname "$0")/..
cd "$DOTS" || (echo "Directory not found: $DOTS"; exit 1)
DOTS="$PWD"
all_brews() {
find "$DOTS/homebrew" \
-iname "*.Brewfile" \
-exec \
/usr/local/bin/brew bundle install --file "{}" \;
echo "all brews installed ✓"
}
all_brews

26
legacy/scripts/cargos Executable file
View File

@ -0,0 +1,26 @@
#!/bin/sh
DOTS=$(dirname "$0")/..
cd "$DOTS" || (echo "Directory not found: $DOTS"; exit 1)
DOTS="$PWD"
check_rust() {
if ! (which ~/.cargo/bin/rustup > /dev/null)
then
echo "Install rust (cargo) before continuing"
echo "Run the rust script before this one"
exit 1
fi
}
all_cargos() {
cargofile=$DOTS/cargo/Cargofile
sed 's/#.*$//g;/^$/d' "$cargofile" | while read -r line
do
cargo install "$line"
done \
&& echo "all cargos installed ✓"
}
check_rust
all_cargos

11
legacy/scripts/casks Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
install_casks() {
brewfile=$DOTS/homebrew/Caskfile
if ! (/usr/local/bin/brew bundle check --file "$brewfile" > /dev/null)
then
/usr/local/bin/brew bundle --file "$brewfile"
fi
echo "casks installed ✓"
}

168
legacy/scripts/configure_macos Executable file
View File

@ -0,0 +1,168 @@
#!/bin/sh
echo "Enable full keyboard access for all controls (e.g. enable Tab in modal dialogs)"
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
echo "Automatically show and hide the dock"
defaults write com.apple.dock autohide -bool true
echo "Automatically show and hide the menu bar"
defaults write NSGlobalDomain _HIHideMenuBar -bool true
echo "Make Dock icons of hidden applications translucent"
defaults write com.apple.dock showhidden -bool true
echo "Use current directory as default search scope in Finder"
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
echo "Expand save panel by default"
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
echo "Expand print panel by default"
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
echo "Disable the \"Are you sure you want to open this application?\" dialog"
defaults write com.apple.LaunchServices LSQuarantine -bool false
echo "Enable highlight hover effect for the grid view of a stack (Dock)"
defaults write com.apple.dock mouse-over-hilte-stack -bool true
echo "Enable spring loading for all Dock items"
defaults write enable-spring-load-actions-on-all-items -bool true
echo "Disable press-and-hold for keys in favor of key repeat"
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
defaults write -g ApplePressAndHoldEnabled -bool false
echo "Set a blazingly fast keyboard repeat rate"
defaults write NSGlobalDomain KeyRepeat -int 2
echo "Set a shorter Delay until key repeat"
defaults write NSGlobalDomain InitialKeyRepeat -int 12
echo "Disable disk image verification"
defaults write com.apple.frameworks.diskimages skip-verify -bool true
defaults write com.apple.frameworks.diskimages skip-verify-locked -bool true
defaults write com.apple.frameworks.diskimages skip-verify-remote -bool true
echo "Avoid creating .DS_Store files on network volumes"
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
echo "Disable the warning when changing a file extension"
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# echo "Enable snap-to-grid for desktop icons"
# /usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
echo "Disable the warning before emptying the Trash"
defaults write com.apple.finder WarnOnEmptyTrash -bool false
echo "Disable tap to click (Trackpad)"
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool false
echo "Enable Safaris debug menu"
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
echo "Make Safaris search banners default to Contains instead of Starts With"
defaults write com.apple.Safari FindOnPageMatchesWordStartsOnly -bool false
echo "Add a context menu item for showing the Web Inspector in web views"
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
echo "Save to disk (not to iCloud) by default"
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
echo "Disable automatic capitalization as its annoying when typing code"
defaults write NSGlobalDomain NSAutomaticCapitalizationEnabled -bool false
echo "Disable smart dashes as theyre annoying when typing code"
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
echo "Disable automatic period substitution as its annoying when typing code"
defaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool false
echo "Disable smart quotes as theyre annoying when typing code"
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
echo "Disable auto-correct"
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
echo "Use scroll gesture with the Ctrl (^) modifier key to zoom"
defaults write com.apple.universalaccess closeViewScrollWheelToggle -bool true
defaults write com.apple.universalaccess HIDScrollZoomModifierMask -int 262144
echo "Follow the keyboard focus while zoomed in"
defaults write com.apple.universalaccess closeViewZoomFollowsFocus -bool true
echo "Require password immediately after sleep or screen saver begins"
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0
echo "Save screenshots to downloads"
defaults write com.apple.screencapture location -string "${HOME}/Downloads"
echo "Finder: allow quitting via ⌘ + Q; doing so will also hide desktop icons"
defaults write com.apple.finder QuitMenuItem -bool true
echo "Show the ~/Library folder"
chflags nohidden ~/Library && xattr -d com.apple.FinderInfo ~/Library
# Noah Prefs
echo "Enable dock magnification"
defaults write com.apple.dock magnification -bool true
echo "Set dock size"
defaults write com.apple.dock largesize -int 48
defaults write com.apple.dock tilesize -int 44
echo "Choose and order dock icons"
__dock_item() {
printf '%s%s%s%s%s' \
'<dict><key>tile-data</key><dict><key>file-data</key><dict>' \
'<key>_CFURLString</key><string>' \
"$1" \
'</string><key>_CFURLStringType</key><integer>0</integer>' \
'</dict></dict></dict>'
}
defaults write com.apple.dock persistent-apps -array \
"$(__dock_item /Applications/1Password\ 7.app)" \
"$(__dock_item /Applications/Slack.app)" \
"$(__dock_item /System/Applications/Calendar.app)" \
"$(__dock_item /Applications/Firefox.app)" \
"$(__dock_item /System/Applications/Messages.app)" \
"$(__dock_item /System/Applications/Mail.app)" \
"$(__dock_item /Applications/Mimestream.app)" \
"$(__dock_item /Applications/zoom.us.app)" \
"$(__dock_item /Applications/Obsidian.app)" \
"$(__dock_item /Applications/Alacritty.app)" \
"$(__dock_item /System/Applications/System\ Preferences.app)"
echo "No recent items in dock"
defaults write com.apple.dock show-recents -bool FALSE
echo "Switch to dark mode"
defaults write "Apple Global Domain" "AppleInterfaceStyle" "Dark"
echo "Turn on Scroll Reverser"
open /Applications/Scroll\ Reverser.app
osascript -e 'tell application "System Events" to make login item at end with properties {path:"/Applications/Scroll Reverser.app", hidden:false}'
echo "Allow apps from anywhere"
SPCTL=$(spctl --status)
if ! [ "$SPCTL" = "assessments disabled" ]
then
sudo spctl --master-disable
fi
# ---
echo "Reset Launchpad"
# [ -e ~/Library/Application\ Support/Dock/*.db ] && rm ~/Library/Application\ Support/Dock/*.db
rm ~/Library/Application\ Support/Dock/*.db
echo "Show the ~/Library folder"
chflags nohidden ~/Library
# Clean up
echo "Kill affected applications"
for app in Safari Finder Dock Mail SystemUIServer; do killall "$app" >/dev/null 2>&1; done

5
legacy/scripts/npm Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
npm update -g
npm install -g pyright
npm install -g diagnostic-languageserver

48
legacy/scripts/rust Executable file
View File

@ -0,0 +1,48 @@
#!/bin/sh
install_rust() {
if ! (which ~/.cargo/bin/rustup > /dev/null)
then
echo "installing rustup"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
fi
echo "rustup ✓"
}
update_rust() {
~/.cargo/bin/rustup update > /dev/null 2>&1
rust_version=$(~/.cargo/bin/rustc --version | awk '{print $2}')
echo "latest rust: $rust_version ✓"
}
download_rust_analyzer() {
if ! (which rust-analyzer > /dev/null)
then
echo "downloading rust analyzer"
rust_analyzer_bin=/usr/local/bin/rust-analyzer
curl -s -L https://github.com/rust-analyzer/rust-analyzer/releases/latest/download/rust-analyzer-mac -o $rust_analyzer_bin
chmod +x $rust_analyzer_bin
fi
echo "rust-analyzer ✓"
}
# cargo-edit: quickly add and remove packages
# whatfeatures: see optional features for a package
install_cargos() {
set -- \
'cargo-edit' \
'cargo-whatfeatures'
for program do
cargo install "$program"
done
echo "cargos ✓"
}
install_rust
update_rust
download_rust_analyzer
install_cargos

View File

@ -0,0 +1,6 @@
#!/bin/sh
echo "downloading cheatsheet"
curl https://cht.sh/:cht.sh > ~/.local/bin/cheat
chmod 755 ~/.local/bin/cheat
echo "cheatsheet ✓"

46
legacy/scripts/setup_fish Executable file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env fish
set -U FISH_DIR (readlink ~/.config/fish) # Used for getting to this repo
set -Ux DOTS (dirname $FISH_DIR) # Directory of this config repo
set -U CDPATH . $HOME # Directories available for immediate cd
set -Ux EDITOR nvim # Preferred text editor
set -U PROJ $HOME/dev/work # Projects directory
set -Ux NOTES_PATH "$HOME/dev/personal/notes" # Notes directory
set -Ux MANPAGER "nvim +Man!" # Used for reading man pages
set -Ux DIRENV_LOG_FORMAT "" # Disable direnv output
set -Ux BROWSER "/Applications/Firefox.app/Contents/MacOS/firefox"
# Load abbreviations
abbrs
# Turn off greeting
set -U fish_greeting ""
# Set colors (Base16 Eighties)
set -U fish_color_normal normal
set -U fish_color_command 99cc99
set -U fish_color_quote ffcc66
set -U fish_color_redirection d3d0c8
set -U fish_color_end cc99cc
set -U fish_color_error f2777a
set -U fish_color_selection white --bold --background=brblack
set -U fish_color_search_match bryellow --background=brblack
set -U fish_color_history_current --bold
set -U fish_color_operator 6699cc
set -U fish_color_escape 66cccc
set -U fish_color_cwd green
set -U fish_color_cwd_root red
set -U fish_color_valid_path --underline
set -U fish_color_autosuggestion 747369
set -U fish_color_user brgreen
set -U fish_color_host normal
set -U fish_color_cancel -r
set -U fish_pager_color_completion normal
set -U fish_pager_color_description B3A06D yellow
set -U fish_pager_color_prefix white --bold --underline
set -U fish_pager_color_progress brwhite --background=cyan
set -U fish_color_comment ffcc66
set -U fish_color_param d3d0c8
set -U fish_color_match 6699cc
echo "fish setup ✓"

29
legacy/scripts/setup_symlinks Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
DOTS=$(dirname "$0")/..
cd "$DOTS" || (echo "Directory not found: $DOTS"; exit 1)
DOTS="$PWD"
setup_symlinks() {
for source in $(find "$DOTS" -iname "*.symlink")
do
dest="$HOME/.`basename \"${source%.*}\"`"
ln -sfn "$source" "$dest"
done
echo "symlinks ✓"
}
setup_configlinks() {
for source in $(find "$DOTS" -iname "*.configlink")
do
dest="$HOME/.config/`basename \"${source%.*}\"`"
ln -sfn "$source" "$dest"
done
echo "configlinks ✓"
}
setup_symlinks
setup_configlinks

7
legacy/scripts/setup_ytfzf Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
echo "downloading ytfzf"
mkdir -p ~/.local/bin
curl -sL "https://raw.githubusercontent.com/pystardust/ytfzf/master/ytfzf" >~/.local/bin/ytfzf
chmod 755 ~/.local/bin/ytfzf
echo "ytfzf ✓"

View File

@ -0,0 +1,19 @@
#!/bin/sh
update_rust_analyzer() {
if ! (which rust-analyzer > /dev/null)
then
echo "not installed"
else
echo "removing"
rm /usr/local/bin/rust-analyzer
fi
echo "downloading rust analyzer"
rust_analyzer_bin=/usr/local/bin/rust-analyzer
curl -s -L https://github.com/rust-analyzer/rust-analyzer/releases/latest/download/rust-analyzer-mac -o $rust_analyzer_bin
chmod +x $rust_analyzer_bin
echo "rust-analyzer ✓"
}
update_rust_analyzer

View File

@ -0,0 +1,102 @@
# Colors for CoC
set-option -g default-terminal "screen-256color"
# Keep plenty of history for scrollback
set -g history-limit 100000
# Remove delay for entering copy mode
set-option -sg escape-time 0
# Horizontal and vertical splits
bind \\ split-window -h -c '#{pane_current_path}'
bind - split-window -v -c '#{pane_current_path}'
# Move between panes with vi keys
bind h select-pane -L
bind j select-pane -D
bind K select-pane -U
bind l select-pane -R
# Split out pane
bind b break-pane
# Synchronize panes
bind S set-window-option synchronize-panes
bind C-h resize-pane -L 10
bind C-l resize-pane -R 10
# Copy mode works as Vim
bind Escape copy-mode
bind k copy-mode
bind C-[ copy-mode
# Vi-style scrollback with prefix + C-[
set-window-option -g mode-keys vi
# Use v to trigger selection
bind-key -T copy-mode-vi v send-keys -X begin-selection
# Use y to yank current selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
# Enable mouse mode
set -g mouse on
# Status bar
set -g status-interval 60 # Seconds between refreshes
set -g renumber-windows on
set-option -g base-index 1 # Set 1 for first window (easier to type)
set-window-option -g pane-base-index 1 # Set 1 for first pane (easier to type)
set-option -g status-position bottom
################################
## COLORSCHEME: gruvbox dark
set-option -g status "on"
# Default statusbar color
set-option -g status-style bg=colour237,fg=colour223 # bg=bg1, fg=fg1
# Default window title colors
set-window-option -g window-status-style bg=colour214,fg=colour237 # bg=yellow, fg=bg1
# Default window with an activity alert
set-window-option -g window-status-activity-style bg=colour237,fg=colour248 # bg=bg1, fg=fg3
# Active window title colors
set-window-option -g window-status-current-style bg=red,fg=colour237 # fg=bg1
# Pane border
set-option -g pane-active-border-style fg=colour250 #fg2
set-option -g pane-border-style fg=colour237 #bg1
# Message infos
set-option -g message-style bg=colour239,fg=colour223 # bg=bg2, fg=fg1
# Writing commands inactive
set-option -g message-command-style bg=colour239,fg=colour223 # bg=fg3, fg=bg1
# Pane number display
set-option -g display-panes-active-colour colour250 #fg2
set-option -g display-panes-colour colour237 #bg1
# Clock
set-window-option -g clock-mode-colour colour109 #blue
# Bell
set-window-option -g window-status-bell-style bg=colour167,fg=colour235 # bg=red, fg=bg
# Theme settings mixed with colors (unfortunately, but there is no cleaner way)
set-option -g status-justify "left"
set-option -g status-left-style none
set-option -g status-left-length "80"
set-option -g status-right-style none
set-option -g status-right-length "80"
set-window-option -g window-status-separator ""
WEATHER='#(weather_cached)'
set-option -g status-left "#[fg=colour248, bg=colour241] #S #[fg=colour241, bg=colour237, nobold, noitalics, nounderscore]"
set-option -g status-right "#[fg=colour239, bg=colour237, nobold, nounderscore, noitalics]#[fg=colour246,bg=colour239] %Y-%m-%d  %H:%M #[fg=colour248, bg=colour239, nobold, noitalics, nounderscore]#[fg=colour237, nobold, bg=colour248] $WEATHER #[fg=colour237] "
set-window-option -g window-status-current-format "#[fg=colour237, bg=colour214, nobold, noitalics, nounderscore]#[fg=colour239, bg=colour214] #I #[fg=colour239, bg=colour214, bold] #W #[fg=colour214, bg=colour237, nobold, noitalics, nounderscore]"
set-window-option -g window-status-format "#[fg=colour237,bg=colour239,noitalics]#[fg=colour223,bg=colour239] #I #[fg=colour223, bg=colour239] #W #[fg=colour239, bg=colour237, noitalics]"