Some cleanup

This commit is contained in:
Daniel Flanagan 2023-07-17 11:23:37 -05:00
parent d2a85a7228
commit 3af512f530
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
39 changed files with 86 additions and 367 deletions

8
common/bin/? Executable file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env fish
echo "Keys you never remember:"
echo
echo "C-t fuzzy find a file or directory to insert into your command"
echo "C-g fuzzy find a directory to cd to"
# https://github.com/lotabout/skim/blob/master/shell/key-bindings.fish

View file

@ -1,7 +0,0 @@
#!/usr/bin/env fish
if test (count $argv) -lt 2
docker run -it --rm archlinux bash
else
docker run -it --rm $argv[1..-2] archlinux $argv[-1]
end

View file

@ -1,8 +1,12 @@
#!/usr/bin/env bash
usage() {
echo "at - waits until after the specified datetime"
echo "Usage:"
echo " at <DATE> && command..."
echo " at <DATETIME> && command..."
echo
echo "Examples:"
echo " at 15:00:00 && echo \"it is 3 o'clock\""
}
[[ -z "$1" ]] && { echo "Error: No DATE argument provided." >&2; usage; exit 1; }
@ -14,3 +18,4 @@ while [[ "$d" -ge "$(date +%s)" ]]; do
echo -ne "\rTime Remaining: ${days}d $(date -u --date @$((_dt)) +%H:%M:%S) ";
sleep 0.1
done
exit 0

View file

@ -1,14 +0,0 @@
#!/usr/bin/env bash
bbin="bible" # npm i -g bible
pbin="less"
# bible args
bargs=("")
# pager args
pargs="-R"
[[ $1 = s ]] && { bargs+=("--search"); shift; }
"${bbin}" "${bargs[@]}" "$*" | "${pbin}" $pargs

View file

@ -1,52 +0,0 @@
#!/usr/bin/env fish
# deps: fish, zstd, gpg, ssh
set -q HOST || set HOST (head -n 1 /etc/hostname | tr -d '\n')
# use the backup-host in the ~/.ssh/config as the default backup remote host
set -q BACKUP_REMOTE_HOST || set BACKUP_REMOTE_HOST backup-host
# use a user-specific dir by default to backup to
set -q BACKUP_REMOTE_DIR || set BACKUP_REMOTE_DIR "/storage/"(whoami)"/backups/$HOST"
set BACKUP_FILE_EXT .tar.zstd.gpg
if not set -q argv[1]
echo "No target file or directory provided"
exit 2
end
set target $argv[1]
if not test -d $target
echo "Target '$target' is not a directory"
exit 1
end
set remote_path
pushd (dirname $target) >/dev/null
# TODO: progress bar/status?
set friendly_target (pwd)
set path_friendly_target (pwd | cut -c2- | string replace -a / %)
set backup_file_name (date +%Y-%m-%d_%H-%M-%S)_"$path_friendly_target"
set remote_path "$BACKUP_REMOTE_DIR/$backup_file_name$BACKUP_FILE_EXT"
echo "Streaming PGP encrypted backup of $friendly_target to SSH host $BACKUP_REMOTE_HOST at $remote_path"
ssh $BACKUP_REMOTE_HOST "mkdir -p $BACKUP_REMOTE_DIR" || begin
echo "Failed to SSH to $BACKUP_REMOTE_HOST and create remote dir $BACKUP_REMOTE_DIR"
exit 3
end
# TODO: progress indicator?
tar cf - . |
zstd --ultra -T2 -22 |
gpg --encrypt --recipient daniel@lyte.dev |
ssh $BACKUP_REMOTE_HOST "cat - > $remote_path" || begin
echo "Failed to stream backup"
exit 4
end
popd >/dev/null
# TODO: checksum?
echo "Uploaded to host rift via ssh at $remote_path"
echo " Run 'unbackupify \"$backup_file_name$BACKUP_FILE_EXT\"' to restore!"

View file

@ -1,14 +0,0 @@
#!/usr/bin/env fish
set keyfile $HOME/.bupstash/backups.key
if not test -f $keyfile
echo Loading key from pass...
pass bupstash | tail -n+3 > $keyfile; or begin;
echo Failed to load key from pass
exit 1
end
end
set rift ssh://rift/storage/daniel-backups
bupstash init --repository $rift

View file

@ -1,3 +0,0 @@
#!/usr/bin/env bash
python -c "print(${*})"

View file

@ -1,4 +0,0 @@
#!/usr/bin/env bash
# TODO: needs fixing...?
cd "$(dirname "$(sk)")" || exit 1

View file

@ -20,7 +20,7 @@ COLOR_RESET="\x1b[0m" COLOR_GREEN="\x1b[32m"
COLOR_YELLOW="\x1b[33m"
COLOR_RED="\x1b[31m"
DOMAINS=( \
TLDS=( \
'.com' '.net' '.org' '.eu' '.in' '.it' '.sk' '.ac' '.ae' '.af' '.ag' '.al' \
'.am' '.as' '.at' '.ax' '.be' '.bi' '.bo' '.by' '.bz' '.cc' '.cd' '.cf' '.cg' \
'.ch' '.ci' '.cl' '.cm' '.cn' '.co' '.cr' '.cx' '.cz' '.dk' '.dm' '.do' '.ec' \
@ -80,10 +80,10 @@ check_domain() {
# iterate all provided domain names combined with all TLDs and check them
# concurrently
elements=${#DOMAINS[@]}
elements=${#TLDS[@]}
while (( "$#" )); do
for (( i=0;i<elements;i++ )); do
check_domain "$1${DOMAINS[${i}]}" &
check_domain "$1${TLDS[${i}]}" &
done
shift
done

View file

@ -1,11 +1,15 @@
#!/usr/bin/env bash
# TODO: detect MIME type?
# can a `clip-once` script exist building on this?
# wl-copy `-o`, xclip `-l 1`?
# TODO: figure out how/why these programs "wait" -- can a `clip-once` script exist building on this?
# wl-copy `-o`, xclip `-l 1`?
if is_wayland; then
if [ "$(uname)" == "Linux" ]; then
if is_wayland; then
wl-copy -n "$@"
else
else
xclip -i -sel c "$@"
fi
elif [ "$(uname)" == "Darwin" ]; then
pbcopy "$@"
fi

View file

@ -12,11 +12,12 @@ if [ "$?" -eq 0 ]; then
grim -g "$dim" - | wl-copy -t image/png
wl-paste -n > "$fn"
echo "$fn"
# grim -g "$dim" - | tee "$fn" | wl-copy -f
else
exit 1
fi
# TODO: implement for X and other OSs?
# pkill unclutter
# sleep 0.1
# import "$fn"

View file

@ -1,5 +0,0 @@
#!/usr/bin/env sh
echo "Primary : $(xclip -out -selection primary)"
echo "Secondary: $(xclip -out -selection primary)"
echo "Clipboard: $(xclip -out -selection clipboard)"

View file

@ -1,3 +0,0 @@
#!/usr/bin/env bash
zstd "$@"

View file

@ -1,8 +1,21 @@
#!/usr/bin/env sh
usage() {
echo "copy-git-forge-url <$FILE>[#L$LINE_NUMBERS]"
echo " Copies a link to the git forge's web interface for the current branch to the clipboard"
echo
echo " Examples:"
echo " \$ copy-git-forge-url readme.md#L12"
}
if [ "$#" -lt 1 ]; then
usage
exit 1
fi
url="$(gitforge-url.ts "$1")"
case "$(uname)" in
Linux*) echo "$url" | clip;;
Darwin*) echo "$url" | pbcopy;;
Darwin*) echo "$url" | clip;;
*) echo "OS not supported"; exit 1;
esac

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
[[ -z "${@}" ]] && { echo "No argument provided." >&2 ; exit 1; }
[[ $# -lt 1 ]] && { echo "No argument provided." >&2 ; exit 1; }
d=$(($(date +%s) + $1));
echo "Countdown started at $(date)"

View file

@ -1,3 +0,0 @@
#!/usr/bin/env bash
unzstd "$@"

View file

@ -1,11 +0,0 @@
#!/usr/bin/env moon
arg_spec = {
{"target", "REMOTE_MACHINE", "remote"}
{"fwd", "FORWARD_PORTS", "1313,3000,4800:8000,8080,1234,4400:4000,40080:80,40443:443"}
{"sargs", "SSH_ARGS", "-XY"}
}
args = {v[1], os.getenv(v[2]) or arg[i] or v[3] for i, v in ipairs(arg_spec)}
ports = {a, (if b == "" then a else b) for a, b in args.fwd\gmatch "(%d+):?(%d*),?"}
pargs = table.concat ["-L #{k}:localhost:#{v}" for k,v in pairs ports], " "
for k,v in pairs ports do print "Forwarding localhost:#{k} to #{args.target}:#{v}"
os.execute "ssh -N #{args.target} #{pargs} #{args.sargs}"

View file

@ -1,5 +0,0 @@
#!/usr/bin/env bash
KEYBOARD_SEARCH_STRING="AT Translated.*keyboard"
BUILTIN_KEYBOARD_ID=$(xinput list | grep "$KEYBOARD_SEARCH_STRING" | sed -ne 's/^.*id\=\([0-9]*\).*/\1/p')
sudo xinput float "$BUILTIN_KEYBOARD_ID"

View file

@ -1,5 +0,0 @@
#!/usr/bin/env bash
# TODO: implement
echo "Not implemented"

View file

@ -70,4 +70,3 @@ swaks --auth \
--to "$recipient" \
--h-Subject: "$subject" \
--body "$body"

View file

@ -1,8 +0,0 @@
#!/usr/bin/env bash
KEYBOARD_PARENT_SEARCH_STRING="Virtual core keyboard.*master keyboard"
PARENT_KEYBOARD_ID=$(xinput list | grep "$KEYBOARD_PARENT_SEARCH_STRING" | sed -ne 's/^.*id\=\([0-9]*\).*/\1/p')
KEYBOARD_SEARCH_STRING="AT Translated.*keyboard"
BUILTIN_KEYBOARD_ID=$(xinput list | grep "$KEYBOARD_SEARCH_STRING" | sed -ne 's/^.*id\=\([0-9]*\).*/\1/p')
sudo xinput reattach "$BUILTIN_KEYBOARD_ID" "$PARENT_KEYBOARD_ID"

View file

@ -1,50 +0,0 @@
#!/usr/bin/env bash
usage() {
# shellcheck disable=SC2016
echo 'encrypted-dir-archive <dir>
This script streams an gpg-encrypted byte-stream of a zstd-compressed \
tarball this can be redirected to a file for an encrypted backup.
Very roughly, this is a small wrapper around `tar cf . | zstd | gpg --encrypt` \
so you can go backwards to reverse the process `gpg --decrypt | zstd -d | tar xf`.
You can stream over ssh as a remote backup by piping to something like this: \
`ssh "$HOST" "cat - > '\$REMOTE_FILE'"`'.
}
if [ "$1" = '-h' ] || [ "$1" = "--help" ]; then
usage
exit 0
fi
dir="$1"
if [ -z "$dir" ]; then
echo "no directory argument provided" >&2
usage
exit 1
fi
if [ ! -d "$dir" ]; then
echo "'$dir' is not a directory" >&2
usage
exit 2
fi
# go to directory containing target directory
parent="$(dirname "$dir")"
pushd "$parent" >/dev/null || { echo "failed to cd to '$parent'" >&2; exit 3; }
# https://stackoverflow.com/a/30520299
if [ -t 1 ]; then
echo "not dumping encrypted data to terminal"
exit 4
fi
tar cf - "$(basename "$dir")" \
| zstd --ultra -T2 -22 \
| gpg --encrypt --recipient daniel@lyte.dev
popd || echo "failed to return to original directory" >&2

View file

@ -1,97 +0,0 @@
#!/usr/bin/env bash
_VERSION="0.2.0"
function help() {
I=" "
cat << USAGE
fsw - run a command when a file is modified - v$_VERSION
Usage:
${I}fsw <command> [filter] [dirs...]
${I}command - the specified bash command to eval
${I}filter - an optional filename filter
${I}dirs - the directories to watch (defaults to current directory)
Advanced:
${I}Command Variables:
${I}${I}Your commands have runtime access to some variables associated with the
${I}${I}${I}inotifywait event enabling further extensibility:
${I}${I}+ FSW_FILENAME - the name of the file
${I}${I}+ FSW_DIR - the directory containing the file
${I}${I}+ FSW_PATH - the full relative path of the file
${I}${I}+ FSW_FILE_EVENTS - a comma-separated list of the inotify events
${I}Environment:
${I}${I}Some customization options exist using environment variables
${I}${I}${I}due to their uncommon usage.
${I}${I}+ FSW_EVENTS - the list of events to have inotifywait observe
References:
${I}+ Filter works with grep -P
${I}+ See inotifywait(1) for FSW_EVENTS options.
Examples:
${I}fsw 'make' '\.c$'
${I}fsw 'bash \$filename' '\.bash$'
${I}fsw 'mix test --failed' '.exs?$' lib test
${I}FSW_EVENTS=open,access fsw 'espeak "Intruder Alert!"' \\
${I}${I}${I}'.*' /etc/secrets \$HOME/.secrets
USAGE
}
dbg() {
if [[ -n ${FSW_DEBUG+x} ]]; then
echo -e "[debug] fsw: $*"
fi
}
contains_element () {
local e match="$1"; shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
if [[ $1 = '-h' ]] || [[ $1 = '--help' ]] || [[ -z $1 ]]; then
help
exit 0
fi
FSW_EVENTS="${FSW_EVENTS:-close_write}"
dbg "Events: $FSW_EVENTS"
SHELL_COMMAND="${1}"; shift
dbg "Command: $SHELL_COMMAND"
FILTER="${1}"; shift
dbg "Filter: $FILTER"
dbg "Directory: ${1}"
DIRS=("${1:-.}"); shift
if [[ -e $FILTER ]]; then
# TODO: this is a sad hack/workaround
echo "It looks like your filter is an actual file. I'll just watch that for you."
DIRS=("${FILTER}")
fi
while [[ -n $1 ]] && realpath "$1" &> /dev/null; do
dbg "Directory: ${1}"
DIRS+=("$1"); shift
done
inotifywait -m -e "${FSW_EVENTS},delete,delete_self" -r "${DIRS[@]}" 2>&1 \
| grep --line-buffered -v ' Beware: since -r was given, this may take a while!' \
| while read -r dir events filename; do
if contains_element "$dir" "${DIRS[@]}" && [[ $events =~ "delete" ]]; then
echo "One of the watched directories (\"$dir\") was deleted. Exiting..."
exit 75
fi
if [[ "$dir $events" = "Watches established." ]]; then
echo "Ready."
dbg "Directory: ${DIRS[*]}"
else
export FSW_FILENAME="$filename"
export FSW_DIR="$dir"
export FSW_PATH="$dir$filename"
export FSW_FILE_EVENTS="$events"
export FSW_EVENT="$events $dir$filename"
dbg "Event:\n $(date)\n $FSW_PATH\n $FILTER\n $FSW_EVENT\n $dir $events $filename\n ${SHELL_COMMAND}"
dbg "Filtered Event: $(<<< "$FSW_PATH" grep -P "$FILTER")"
<<< "$FSW_PATH" grep -P "$FILTER" > /dev/null 2>&1 && eval "${SHELL_COMMAND}"
fi
done

View file

@ -1,4 +0,0 @@
#!/usr/bin/env bash
eval "${1}"
exec fsw "$@"

View file

@ -1,15 +0,0 @@
#!/usr/bin/env bash
rf="$1" # history count record file
cf="$1" # all choices file
touch "$LAUNCHER_HISTORY_FILE"
app="$(
< "$rf" awk 'NF{NF--};1' | cat - "$cf" | \
sort | uniq -c | sort -nr | \
sd '^\s+' '' | \
cut -d' ' -f2- | \
sk
)"
echo "$app $(date +%s)" >> "$LAUNCHER_HISTORY_FILE"
echo "$app"

View file

@ -1,16 +0,0 @@
#!/usr/bin/env sh
FZFP_PASS_CMD="pass"
FZFP_PASS_DIR="$HOME/.password-store"
FZFP_HEIGHT="${FZFP_HEIGHT:-40%}"
FZFP_PROMPT="${FZFP_PROMPT:-"$FZFP_PASS_CMD@$FZFP_PASS_DIR> "}"
FZFP_PASS_OPTS="${FZFP_PASS_OPTS:-}"
cd "$FZFP_PASS_DIR" || { echo "Could not cd to $FZFP_PASS_DIR" >&2; exit 1; }
# TODO: weighted history (see ./launch)
"${FZFP_PASS_CMD}" $FZFP_PASS_OPTS "$@" \
"$(fd gpg | sd ".gpg" "" | fzf --height "$FZFP_HEIGHT" --prompt "$FZFP_PROMPT")"
cd - >/dev/null || return 1

View file

@ -1,3 +0,0 @@
#!/usr/bin/env fish
fish -c (history | head -n 1 | grep -v history) | sk

View file

@ -1,6 +0,0 @@
#!/usr/bin/env sh
# TODO: must be sourced so as to not run in subshell?
addon=""; [ -n "$1" ] && addon="-${1}"
cd "$(cat "${DOTFILES_PATH}/.cwd${addon}.tmp")" || return

View file

@ -1,4 +1,8 @@
#!/usr/bin/env bash
git ls-tree -r -z --name-only HEAD -- "$1" | xargs -0 -n1 git blame \
--line-porcelain HEAD | grep "^author "| sort | uniq -c | sort -nr
git ls-tree -r -z --name-only HEAD -- "$1" \
| xargs -0 -n1 git blame --line-porcelain HEAD \
| grep "^author " \
| sort \
| uniq -c \
| sort -nr

View file

@ -1,5 +0,0 @@
#!/usr/bin/env sh
git branch --merged | \
grep -v "(^\*|master|main|dev)" | \
xargs git branch -dr

View file

@ -1,12 +0,0 @@
#!/usr/bin/env bash
MAIN_BRANCH="master"
CUR_BRANCH="$(git branch | grep '\*' | cut -d ' ' -f2-)"
if [[ -n ${2+x} ]]; then
MAIN_BRANCH="$2"
CUR_BRANCH="$1"
elif [[ -n ${1+x} ]]; then
MAIN_BRANCH="$1"
fi
git rebase -i "$(git merge-base "$CUR_BRANCH" "$MAIN_BRANCH")"

View file

@ -1,2 +0,0 @@
#!/usr/bin/env bash
feh -C /usr/share/fonts/ttf-iosevka-type -e "IosevkaLyte-type-regular/12" -d -., "$@"

View file

@ -1,3 +0,0 @@
#!/usr/bin/env sh
# open the target file in its git-forge in the browser

View file

@ -1,5 +1,18 @@
#!/usr/bin/env sh
usage() {
echo "open-in-git-forge <$FILE>[#L$LINE_NUMBERS]"
echo " Opens the URL in your browser to the git forge's web interface for the current branch for $FILE"
echo
echo " Examples:"
echo " \$ open-in-git-forge readme.md#L12"
}
if [ "$#" -lt 1 ]; then
usage
exit 1
fi
url="$(gitforge-url.ts "$1")"
case "$(uname)" in
Linux*) xdg-open "$url";;

View file

@ -1,6 +1,13 @@
function fish_user_key_bindings
set --export SKIM_TMUX_HEIGHT ""
command -q sk && functions | grep skim_key_bindings &>/dev/null && skim_key_bindings
set --export --universal SKIM_ALT_C_COMMAND "fd --hidden --type directory"
set --export --universal SKIM_CTRL_T_COMMAND "fd --hidden"
command -q sk && begin
functions | grep skim_key_bindings &>/dev/null && skim_key_bindings
bind -M insert \cg skim-cd-widget
end
fish_vi_key_bindings insert --no-erase
set --universal fish_cursor_default block

View file

@ -23,4 +23,5 @@ paru -Sy --needed --noconfirm \
cloc `# For counting lines of code` \
gitui `# Git TUI` \
tokei `# Counting Lines of Code (cloc alternative)` \
swaks `# Email CLI` \
pigz `# Multicore Compression Utility` \

View file

@ -0,0 +1,11 @@
[Added Associations]
image/jpeg=krita_jpeg.desktop
image/png=krita_png.desktop
[Default Applications]
image/jpeg=krita_jpeg.desktop
image/png=krita_png.desktop
[MIME Cache]
image/jpeg=krita_jpeg.desktop
image/png=krita_png.desktop